diff --git a/code/DocumentationService.php b/code/DocumentationService.php index 49892d5..b9d742f 100644 --- a/code/DocumentationService.php +++ b/code/DocumentationService.php @@ -439,10 +439,6 @@ class DocumentationService { } } } - - // if goal has not been found and the index.md file does not exist then the next - // option is to pick the first file in the folder - return $base . ltrim($firstFile, '/'); } closedir($handle); diff --git a/code/DocumentationViewer.php b/code/DocumentationViewer.php index 6566223..ee1908d 100755 --- a/code/DocumentationViewer.php +++ b/code/DocumentationViewer.php @@ -386,7 +386,7 @@ class DocumentationViewer extends Controller { return $page; } - + return false; } @@ -486,11 +486,23 @@ class DocumentationViewer extends Controller { */ function getContent() { if($page = $this->getPage()) { - + // Remove last portion of path (filename), we want a link to the folder base $html = DocumentationParser::parse($page, $this->Link(array_slice($this->Remaining, 0))); return DBField::create("HTMLText", $html); } + else { + // if no page found then we may want to get the listing of + // the folder + if($url = $this->Remaining) { + $pages = DocumentationService::get_pages_from_folder($this->getModule(), implode('/', $url), false); + + return $this->customise(array( + 'Title' => DocumentationService::clean_page_name(array_pop($url)), + 'Pages' => $pages + ))->renderWith('DocFolderListing'); + } + } return false; } diff --git a/templates/DocFolderListing.ss b/templates/DocFolderListing.ss new file mode 100644 index 0000000..3490cb5 --- /dev/null +++ b/templates/DocFolderListing.ss @@ -0,0 +1,13 @@ +<% if Pages %> +
+

$Title

+ + +
+<% else %> +

Nothing to see here

+<% end_if %> \ No newline at end of file diff --git a/tests/DocumentationServiceTest.php b/tests/DocumentationServiceTest.php index d746333..9726b6e 100644 --- a/tests/DocumentationServiceTest.php +++ b/tests/DocumentationServiceTest.php @@ -58,9 +58,10 @@ class DocumentationServiceTest extends SapphireTest { $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path); - // subsubfolder has no index file. It should fail through to the first file + // subsubfolder has no index file. It should fail instead the viewer should pick up on this + // and display the listing of the folder $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder')); - $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); + $this->assertFalse($path); // third level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));