Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #128 from robbieaverill/bugfix/127-use-stable-vers…
Browse files Browse the repository at this point in the history
…ion-in-all-page

Use the current version to filter pages in the "documentation index"
  • Loading branch information
Damian Mooyman committed Dec 12, 2016
2 parents 40d70a0 + 1a4475a commit ded5432
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
11 changes: 6 additions & 5 deletions code/DocumentationManifest.php
Expand Up @@ -432,12 +432,13 @@ protected function addPage($page, $basename, $path)
$link = $this->stripLinkBase($page->Link());

$this->pages[$link] = array(
'title' => $page->getTitle(),
'basename' => $basename,
'filepath' => DocumentationHelper::normalizePath($path),
'type' => get_class($page),
'title' => $page->getTitle(),
'version' => $page->getVersion(),
'basename' => $basename,
'filepath' => DocumentationHelper::normalizePath($path),
'type' => get_class($page),
'entitypath' => $this->entity->getPath(),
'summary' => $page->getSummary()
'summary' => $page->getSummary()
);
}

Expand Down
48 changes: 42 additions & 6 deletions code/controllers/DocumentationViewer.php
Expand Up @@ -251,7 +251,7 @@ public function handleAction($request, $action)
if (in_array($action, $allowed)) {
//
// if it's one of the allowed actions such as search or all then the
// URL must be prefixed with one of the allowed languages.
// URL must be prefixed with one of the allowed languages and versions
//
return parent::handleAction($request, $action);
} else {
Expand All @@ -275,8 +275,8 @@ public function handleAction($request, $action)
$type = get_class($this->record);
$body = $this->renderWith(
array(
"DocumentationViewer_{$type}",
"DocumentationViewer"
"DocumentationViewer_{$type}",
'DocumentationViewer'
)
);

Expand All @@ -288,8 +288,8 @@ public function handleAction($request, $action)
} elseif (!$url || $url == $lang) {
$body = $this->renderWith(
array(
"DocumentationViewer_DocumentationFolder",
"DocumentationViewer"
'DocumentationViewer_DocumentationFolder',
'DocumentationViewer'
)
);

Expand Down Expand Up @@ -572,15 +572,21 @@ public function Link($action = '')
* Generate a list of all the pages in the documentation grouped by the
* first letter of the page.
*
* @param string|int|null $version
* @return GroupedList
*/
public function AllPages()
public function AllPages($version = null)
{
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
$baseLink = $this->getDocumentationBaseHref();

foreach ($pages as $url => $page) {
// Option to skip Pages that do not belong to the current version
if (!is_null($version) && (string) $page['version'] !== (string) $version) {
continue;
}

$first = strtoupper(trim(substr($page['title'], 0, 1)));

if ($first) {
Expand All @@ -599,6 +605,16 @@ public function AllPages()
return GroupedList::create($output->sort('Title', 'ASC'));
}

/**
* Return all Pages that apply to the current version (from the route)
*
* @return GroupedList
*/
public function getAllVersionPages()
{
return $this->AllPages($this->getRequestedVersion());
}

/**
* Documentation Search Form. Allows filtering of the results by many entities
* and multiple versions.
Expand Down Expand Up @@ -761,4 +777,24 @@ public function getHasDefaultEntity()
{
return $this->getManifest()->getHasDefaultEntity();
}

/**
* Gets the requested version from the URL
*
* @return string
*/
public function getRequestedVersion()
{
return (string) $this->request->param('Version');
}

/**
* Gets the link to the "documentation index" containing the currently requested version
*
* @return string
*/
public function getDocumentationIndexLink()
{
return $this->Link($this->getRequestedVersion() . '/all');
}
}
4 changes: 3 additions & 1 deletion code/models/DocumentationPage.php
Expand Up @@ -15,7 +15,9 @@ class DocumentationPage extends ViewableData
/**
* @var string
*/
protected $title, $summary, $introduction;
protected $title;
protected $summary;
protected $introduction;

/**
* @var DocumentationEntity
Expand Down
2 changes: 1 addition & 1 deletion templates/Includes/DocumentationSidebar.ss
Expand Up @@ -63,7 +63,7 @@

<div class="no-box">
<ul class="minor-nav">
<li><a href="{$Link(all)}">Documentation Index</a></li>
<li><a href="$DocumentationIndexLink">Documentation Index</a></li>
</ul>
</div>
</div>
6 changes: 3 additions & 3 deletions templates/Layout/DocumentationViewer_all.ss
@@ -1,13 +1,13 @@
<div id="documentation_index" class="box">
<div id="page-numbers">
<span>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<% loop $AllVersionPages.GroupedBy(FirstLetter) %>
<a href="#$FirstLetter">$FirstLetter</a>
<% end_loop %>
</span>
</div>

<% loop $AllPages.GroupedBy(FirstLetter) %>
<% loop $AllVersionPages.GroupedBy(FirstLetter) %>
<h2 id="$FirstLetter">$FirstLetter</h2>

<ul class="third semantic">
Expand All @@ -18,4 +18,4 @@
<% end_loop %>
</ul>
<% end_loop %>
</div>
</div>

0 comments on commit ded5432

Please sign in to comment.