Add an alphabetical index (Fixes #5)

This commit is contained in:
Will Rossiter 2014-09-07 20:35:08 +12:00
parent 0b91b91e33
commit 31a3b8a744
9 changed files with 166 additions and 48 deletions

View File

@ -26,6 +26,7 @@ class DocumentationViewer extends Controller {
*/ */
private static $allowed_actions = array( private static $allowed_actions = array(
'home', 'home',
'all',
'LanguageForm', 'LanguageForm',
'doLanguageForm', 'doLanguageForm',
'handleRequest', 'handleRequest',
@ -144,6 +145,8 @@ class DocumentationViewer extends Controller {
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function handleAction($request, $action) { public function handleAction($request, $action) {
$action = $request->param('Action');
try { try {
if(preg_match('/DocumentationSearchForm/', $request->getURL())) { if(preg_match('/DocumentationSearchForm/', $request->getURL())) {
$action = 'results'; $action = 'results';
@ -175,6 +178,7 @@ class DocumentationViewer extends Controller {
return $response; return $response;
} }
if($response->getStatusCode() !== 200) {
// look up the manifest to see find the nearest match against the // look up the manifest to see find the nearest match against the
// list of the URL. If the URL exists then set that as the current // list of the URL. If the URL exists then set that as the current
// page to match against. // page to match against.
@ -199,6 +203,9 @@ class DocumentationViewer extends Controller {
} }
} }
return $response;
}
/** /**
* Returns the current version. If no version is set then it is the current * Returns the current version. If no version is set then it is the current
* set version so need to pull that from the {@link Entity}. * set version so need to pull that from the {@link Entity}.
@ -245,6 +252,13 @@ class DocumentationViewer extends Controller {
return ($this->record) ? $this->record->getEntity()->getVersions() : null; return ($this->record) ? $this->record->getEntity()->getVersions() : null;
} }
/**
* @return DocumentationEntityVersion
*/
public function getStableVersion() {
return ($this->record) ? $this->record->getEntity()->getStableVersion() : null;
}
/** /**
* Generate a list of entities which have been registered and which can * Generate a list of entities which have been registered and which can
* be documented. * be documented.
@ -322,15 +336,31 @@ class DocumentationViewer extends Controller {
* *
* @return string * @return string
*/ */
public function Link() { public function Link($action = '') {
$link = Controller::join_links( $link = Controller::join_links(
Director::absoluteBaseURL(), Director::absoluteBaseURL(),
Config::inst()->get('DocumentationViewer', 'link_base') Config::inst()->get('DocumentationViewer', 'link_base'),
$action
); );
return $link; return $link;
} }
public function AllPages() {
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
foreach($pages as $url => $page) {
$output->push(new ArrayData(array(
'Link' => $url,
'Title' => $page['title'],
'FirstLetter' => strtoupper(substr($page['title'], 0, 1))
)));
}
return GroupedList::create($output->sort('Title', 'ASC'));
}
/** /**
* Build the language dropdown. * Build the language dropdown.
* *

View File

@ -14,8 +14,9 @@ class DocumentationViewerVersionWarning extends Extension {
$version = $this->owner->getVersion(); $version = $this->owner->getVersion();
$versions = $this->owner->getVersions(); $versions = $this->owner->getVersions();
if($page && $verions->count() > 0) { if($version && $page && $versions->count() > 0) {
$stable = $this->owner->getStableVersion(); $stable = $this->owner->getStableVersion();
$compare = $version->compare($stable); $compare = $version->compare($stable);
// same // same

View File

@ -81,7 +81,7 @@ class DocumentationEntity extends ViewableData {
return false; return false;
} }
$sortedVersions = $this->getVersions(); $sortedVersions = $this->getVersions()->toArray();
usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);')); usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);'));

View File

@ -35,10 +35,24 @@ class DocumentationEntityLanguage extends ViewableData {
/** /**
* @return string * @return DocumentationEntityVersion
*/ */
public function getVersion() { public function getVersion() {
return $this->entity->getVersion(); return $this->entity;
}
/**
* @return array
*/
public function getVersions() {
return $this->entity->getEntity()->getVersions();
}
/**
* @return
*/
public function getStableVersion() {
return $this->entity->getEntity()->getStableVersion();
} }
/** /**

View File

@ -128,6 +128,12 @@ class DocumentationEntityVersion extends ViewableData {
return $this->entity->getTitle(); return $this->entity->getTitle();
} }
/**
* @return DocumentationEntity
*/
public function getEntity() {
return $this->entity;
}
/** /**
* Returns an integer value based on if a given version is the latest * Returns an integer value based on if a given version is the latest

View File

@ -28,6 +28,10 @@ html {
border-radius: 3px; border-radius: 3px;
} }
.no-box {
padding: 15px;
}
/*! main content column */ /*! main content column */
#content { #content {
float: right; float: right;
@ -41,7 +45,8 @@ html {
width: 25%; width: 25%;
float: left; float: left;
} }
#sidebar .nav { #sidebar .nav,
#sidebar .minor-nav {
margin: 0; margin: 0;
padding: 0; padding: 0;
list-style: none; list-style: none;
@ -62,6 +67,11 @@ html {
font-weight: bold; font-weight: bold;
} }
#sidebar .minor-nav a {
color: #181C17;
opacity: 0.4;
}
#layout { #layout {
padding-bottom: 20px; padding-bottom: 20px;
} }
@ -165,8 +175,9 @@ html {
#page-numbers a { #page-numbers a {
padding: 3px 5px; padding: 3px 5px;
} }
#page-numbers span { #page-numbers span {
background-color: #ACD5CA;
} }
#page-numbers a:hover { #page-numbers a:hover {
color: #FFFFFF; color: #FFFFFF;

View File

@ -62,6 +62,10 @@ p {
margin: 0 0 10px; margin: 0 0 10px;
} }
.text-wrap {
word-break: break-all;
}
/*! lists */ /*! lists */
ul { ul {
margin: 15px 0 20px 20px; margin: 15px 0 20px 20px;
@ -95,11 +99,32 @@ dd {
margin: 5px 0 10px 20px; margin: 5px 0 10px 20px;
} }
.semantic {
list-style: none;
margin: 0;
padding: 0;
}
ul.third {
overflow: hidden;
}
ul.third li {
float: left;
width: 33.3%;
padding-right: 30px;
padding-bottom: 20px;
}
ul.third li:nth-child(3n+1) {
clear: both;
}
/*! headers */ /*! headers */
h1 { h1 {
font-size: 30px; font-size: 30px;
line-height: 30px; line-height: 30px;
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 0;
letter-spacing: -1px; letter-spacing: -1px;
} }

View File

@ -1,4 +1,5 @@
<div id="sidebar" class="box"> <div id="sidebar">
<div class="box">
<ul class="nav"> <ul class="nav">
<% loop Entities %> <% loop Entities %>
<% if DefaultEntity %> <% if DefaultEntity %>
@ -18,3 +19,10 @@
<% end_loop %> <% end_loop %>
</ul> </ul>
</div> </div>
<div class="no-box">
<ul class="minor-nav">
<li><a href="{$Link(all)}">Documentation Index</a></li>
</ul>
</div>
</div>

View File

@ -0,0 +1,23 @@
<div class="box">
<h1>Documentation Index</h1>
<div id="page-numbers">
<span>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<a href="#$FirstLetter">$FirstLetter</a>
<% end_loop %>
</span>
</div>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<h2 id="$FirstLetter">$FirstLetter</h2>
<ul class="third semantic">
<% loop $Children %>
<li>
<a href="$Link">$Title</a>
</li>
<% end_loop %>
</ul>
<% end_loop %>
</div>