From 314e504903a745e135f9d94071e274c6634b6ed2 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 7 Sep 2014 21:28:21 +1200 Subject: [PATCH] Show nested sidebar menu --- code/DocumentationManifest.php | 36 +++++++++++++++++++++ code/controllers/DocumentationViewer.php | 16 ++++++--- code/models/DocumentationEntity.php | 7 ++-- code/models/DocumentationEntityLanguage.php | 9 ++++-- code/models/DocumentationPage.php | 14 +++++++- css/layout.css | 17 +++++++++- css/typography.css | 6 ++-- templates/Includes/DocumentationSidebar.ss | 2 +- 8 files changed, 90 insertions(+), 17 deletions(-) diff --git a/code/DocumentationManifest.php b/code/DocumentationManifest.php index 19c85a1..0971a14 100644 --- a/code/DocumentationManifest.php +++ b/code/DocumentationManifest.php @@ -370,4 +370,40 @@ class DocumentationManifest { return null; } + + /** + * Return the children of the provided record path. + * + * Looks for any pages in the manifest which have one more slash attached. + * + * @param string $path + * + * @return ArrayList + */ + public function getChildrenFor($base, $record) { + $output = new ArrayList(); + $depth = substr_count($base, '/'); + + foreach($this->getPages() as $url => $page) { + if(strstr($url, $base) !== false) { + // children + if(substr_count($url, '/') == ($depth + 1)) { + if($base !== $record) { + $mode = (strstr($url, $record) !== false) ? 'current' : 'link'; + } else { + $mode = 'link'; + } + + $output->push(new ArrayData(array( + 'Link' => $url, + 'Title' => $page['title'], + 'LinkingMode' => $mode + ))); + } + } + } + + return $output; + } + } diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index 35d7287..04de103 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -219,14 +219,14 @@ class DocumentationViewer extends Controller { /** * Returns the current language. * - * @return string + * @return DocumentationEntityLanguage */ public function getLanguage() { - return ($this->record) ? $this->record->getEntity()->getLanguage() : null; + return ($this->record) ? $this->record->getEntity() : null; } /** - * + * @return DocumentationManifest */ public function getManifest() { return new DocumentationManifest((isset($_GET['flush']))); @@ -272,10 +272,17 @@ class DocumentationViewer extends Controller { if($entities) { foreach($entities as $entity) { $mode = 'link'; + $children = new ArrayList(); if($this->record) { if($entity->hasRecord($this->record)) { $mode = 'current'; + + // add children + $children = $this->getManifest()->getChildrenFor( + $this->getLanguage()->Link(), + $this->record->Link() + ); } } @@ -284,7 +291,8 @@ class DocumentationViewer extends Controller { $output->push(new ArrayData(array( 'Title' => $entity->getTitle(), 'Link' => $link, - 'LinkingMode' => $mode + 'LinkingMode' => $mode, + 'Children' => $children ))); } } diff --git a/code/models/DocumentationEntity.php b/code/models/DocumentationEntity.php index 49ca491..bd3eef9 100755 --- a/code/models/DocumentationEntity.php +++ b/code/models/DocumentationEntity.php @@ -173,12 +173,9 @@ class DocumentationEntity extends ViewableData { */ public function hasRecord(DocumentationPage $page) { foreach($this->getVersions() as $version) { - foreach($version->getSupportedLanguages() as $lang) { - if($lang === $page->getEntity()) { - return true; - } + if(strstr($page->getPath(), $version->getPath()) !== false) { + return true; } } } - } \ No newline at end of file diff --git a/code/models/DocumentationEntityLanguage.php b/code/models/DocumentationEntityLanguage.php index 8438f4d..cb79920 100644 --- a/code/models/DocumentationEntityLanguage.php +++ b/code/models/DocumentationEntityLanguage.php @@ -29,7 +29,9 @@ class DocumentationEntityLanguage extends ViewableData { */ public function Link() { return Controller::join_links( - $this->entity->Link(), $this->language + $this->entity->Link(), + $this->language, + '/' ); } @@ -66,7 +68,10 @@ class DocumentationEntityLanguage extends ViewableData { * @return string */ public function getPath() { - return Controller::join_links($this->entity->getPath(), $this->language); + return Controller::join_links( + $this->entity->getPath(), + $this->language + ); } /** diff --git a/code/models/DocumentationPage.php b/code/models/DocumentationPage.php index 77806a5..e21cd02 100755 --- a/code/models/DocumentationPage.php +++ b/code/models/DocumentationPage.php @@ -83,7 +83,19 @@ class DocumentationPage extends ViewableData { return $this->title; } - return DocumentationHelper::clean_page_name($this->filename); + $page = DocumentationHelper::clean_page_name($this->filename); + + if($page == "Index") { + // look at the folder name + $parts = explode("/", $this->getPath()); + array_pop($parts); // name + + $page = DocumentationHelper::clean_page_name( + array_pop($parts) + ); + } + + return $page; } /** diff --git a/css/layout.css b/css/layout.css index 50e33dc..e5308de 100644 --- a/css/layout.css +++ b/css/layout.css @@ -62,16 +62,31 @@ html { padding: 15px 15px 14px; } - #sidebar .nav .current { + #sidebar .nav .current .top { background: #f6f7f8; + border: none; font-weight: bold; } + + #sidebar .nav .current li { + font-weight: normal; + padding: 5px 0; + list-style: none; + font-size: 13px; + } + #sidebar .nav .current a { + color: rgb(51, 67, 72); + } #sidebar .minor-nav a { color: #181C17; opacity: 0.4; } + #sidebar .nav a.current { + font-weight: bold; + } + #layout { padding-bottom: 20px; } diff --git a/css/typography.css b/css/typography.css index d7e24a8..6e41ad7 100644 --- a/css/typography.css +++ b/css/typography.css @@ -68,13 +68,13 @@ p { /*! lists */ ul { - margin: 15px 0 20px 20px; + margin: 10px 0 20px 20px; padding: 0; } li, dd { - font-size: 12px; - margin: 0; + font-size: 13px; + margin: 0 0 5px 0; line-height: 20px; } diff --git a/templates/Includes/DocumentationSidebar.ss b/templates/Includes/DocumentationSidebar.ss index 162ff18..949d5e4 100644 --- a/templates/Includes/DocumentationSidebar.ss +++ b/templates/Includes/DocumentationSidebar.ss @@ -5,7 +5,7 @@ <% if DefaultEntity %> <% else %> -
  • $Title <% if IsFolder %><% end_if %> +
  • $Title <% if IsFolder %><% end_if %> <% if LinkingMode == current %> <% if Children %>