diff --git a/_config/routes.yml b/_config/routes.yml index d4fbbd5..041a12f 100644 --- a/_config/routes.yml +++ b/_config/routes.yml @@ -4,5 +4,5 @@ After: framework/routes#coreroutes --- Director: rules: - 'dev/docs': 'DocumentationViewer' + 'dev/docs//$Lang/$Action': 'DocumentationViewer' 'DocumentationOpenSearchController//$Action': 'DocumentationOpenSearchController' diff --git a/code/DocumentationManifest.php b/code/DocumentationManifest.php index 8003b9a..a118dfd 100644 --- a/code/DocumentationManifest.php +++ b/code/DocumentationManifest.php @@ -355,10 +355,6 @@ class DocumentationManifest { $parts = explode('/', trim($record->getRelativeLink(), '/')); - // the first part of the URL should be the language, so shift that off - // so we just have the core pages. - array_shift($parts); - // Add the base link. $output->push(new ArrayData(array( 'Link' => $base->Link(), @@ -446,7 +442,14 @@ class DocumentationManifest { * @return string */ public function normalizeUrl($url) { - return trim($url, '/') .'/'; + $url = trim($url, '/') .'/'; + + // if the page is the index page then hide it from the menu + if(strpos(strtolower($url), '/index.md/')) { + $url = substr($url, 0, strpos($url, "index.md/")); + } + + return $url; } /** @@ -458,33 +461,33 @@ class DocumentationManifest { * * @return ArrayList */ - public function getChildrenFor($path, $recursive = true) { + public function getChildrenFor($entityPath, $recordPath = null) { + if(!$recordPath) { + $recordPath = $entityPath; + } + $output = new ArrayList(); $base = Config::inst()->get('DocumentationViewer', 'link_base'); - $path = $this->normalizeUrl($path); - $depth = substr_count($path, '/'); + $entityPath = $this->normalizeUrl($entityPath); + $recordPath = $this->normalizeUrl($recordPath); + + $depth = substr_count($entityPath, '/'); foreach($this->getPages() as $url => $page) { $pagePath = $this->normalizeUrl($page['filepath']); // check to see if this page is under the given path - if(strpos($pagePath, $path) === false) { + if(strpos($pagePath, $entityPath) === false) { continue; } - // if the page is the index page then hide it from the menu - if(strpos(strtolower($pagePath), '/index.md/')) { - $pagePath = substr($pagePath, 0, strpos($pagePath, "index.md/")); - } - // only pull it up if it's one more level depth if(substr_count($pagePath, DIRECTORY_SEPARATOR) == ($depth + 1)) { - // found a child - $mode = ($pagePath == $path) ? 'current' : 'link'; + $mode = (strpos($recordPath, $pagePath) !== false) ? 'current' : 'link'; $children = new ArrayList(); - if($mode == 'current' && $recursive) { - // $children = $this->getChildrenFor($url, false); + if($mode == 'current') { + $children = $this->getChildrenFor($pagePath, $recordPath); } $output->push(new ArrayData(array( diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index 98877fc..6ce681f 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -32,13 +32,6 @@ class DocumentationViewer extends Controller { */ private static $documentation_title = 'SilverStripe Documentation'; - /** - * @var array - */ - private static $url_handlers = array( - '$Lang/$Action' => 'handleAction' - ); - /** * @var array */ @@ -323,12 +316,13 @@ class DocumentationViewer extends Controller { $mode = 'link'; $children = new ArrayList(); + if($entity->hasRecord($record) || $entity->getIsDefaultEntity()) { $mode = 'current'; // add children $children = $this->getManifest()->getChildrenFor( - $entity->getPath() + $entity->getPath(), ($record) ? $record->getPath() : $entity->getPath() ); } else { if($current && $current->getKey() == $entity->getKey()) { @@ -372,6 +366,9 @@ class DocumentationViewer extends Controller { return $codes->parse($html); } + /** + * Short code parser + */ public function includeChildren($args) { if(isset($args['Folder'])) { $children = $this->getManifest()->getChildrenFor( @@ -387,6 +384,21 @@ class DocumentationViewer extends Controller { 'Children' => $children )))->renderWith('Includes/DocumentationPages'); } + + /** + * @return ArrayList + */ + public function getChildren() { + if($this->record instanceof DocumentationFolder) { + return $this->getManifest()->getChildrenFor( + $this->record->getPath() + ); + } else { + return $this->getManifest()->getChildrenFor( + dirname($this->record->getPath()) + ); + } + } /** * Generate a list of breadcrumbs for the user. @@ -416,6 +428,9 @@ class DocumentationViewer extends Controller { return ($this->record) ? $this->record->getEntity() : null; } + /** + * @return ArrayList + */ public function getVersions() { return $this->manifest->getVersions($this->getEntity); } diff --git a/css/layout.css b/css/layout.css index 41cc0bd..1d79a6c 100644 --- a/css/layout.css +++ b/css/layout.css @@ -185,16 +185,6 @@ html { display: inline-block; } -/* Breadcrumbs */ -#breadcrumbs { - float: left; -} - #breadcrumbs p { - font-size: 11px; - margin: 0 0 5px 0; - color: #798D85; - } - /* Search Results */ #search-results { @@ -446,7 +436,7 @@ html { } .doc-breadcrumbs p { font-size: 11px; - margin: 0; + margin: 0 0 5px 0; color: #999; } .doc-breadcrumbs p a { @@ -503,4 +493,26 @@ html { .documentation_children p { font-size: 13px; opacity: 0.9; + } + +.next-prev { + border-top: 1px solid #eee; + margin-top: 20px; + padding-top: 19px; + overflow: hidden; +} + .next-prev a { + color: #798D85; + } + + .next-prev p { + margin: 0; + } + + .next-prev .prev-link { + float: left; + } + + .next-prev .next-link { + float: right; } \ No newline at end of file