diff --git a/code/DocumentationService.php b/code/DocumentationService.php index 39483fa..49892d5 100644 --- a/code/DocumentationService.php +++ b/code/DocumentationService.php @@ -393,11 +393,8 @@ class DocumentationService { $base = rtrim($base, '/') .'/'; while (false !== ($file = readdir($handle))) { - if(in_array($file, DocumentationService::get_valid_extensions())) continue; - if(!$firstFile && !is_dir($base . $file)) $firstFile = $file; - $formatted = strtolower($file); // if the name has a . then take the substr @@ -409,6 +406,9 @@ class DocumentationService { } } + // save this file as a backup if we don't have one to fail back to + if(!$firstFile && !is_dir($base . $file)) $firstFile = $file; + // the folder is the one that we are looking for. if(strtolower($name) == strtolower($formatted)) { @@ -439,13 +439,15 @@ 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); - // 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($file, '/'); + return false; } /** diff --git a/code/DocumentationViewer.php b/code/DocumentationViewer.php index 949a053..6566223 100755 --- a/code/DocumentationViewer.php +++ b/code/DocumentationViewer.php @@ -379,6 +379,7 @@ class DocumentationViewer extends Controller { $page = new DocumentationPage(); $page->setRelativePath($relativeFilePath); + $page->setEntity($module); $page->setLang($this->Lang); $page->setVersion($this->Version); @@ -409,7 +410,6 @@ class DocumentationViewer extends Controller { } $page->LinkingMode = 'link'; - $page->Children = $this->_getModulePagesNested($page, $module); } } @@ -423,6 +423,10 @@ class DocumentationViewer extends Controller { /** * Get the module pages under a given page. Recursive call for {@link getModulePages()} * + * @todo Need to rethink how to support pages which are pulling content from their children + * i.e if a folder doesn't have index.md then it will load the first file in the folder + * however it doesn't yet pass the highlighting to it. + * * @param ArrayData CurrentPage * @param DocumentationEntity * @param int Depth of page in the tree @@ -440,8 +444,13 @@ class DocumentationViewer extends Controller { // its either in this section or is the actual link $page->LinkingMode = (isset($this->Remaining[$level + 1])) ? 'section' : 'current'; - - if(is_dir($page->getPath())) { + + $relativePath = Controller::join_links( + $module->getPath($page->getVersion(), $page->getLang()), + $page->getRelativePath() + ); + + if(is_dir($relativePath)) { $children = DocumentationService::get_pages_from_folder($module, $page->getRelativePath(), false); $segments = array(); @@ -455,7 +464,7 @@ class DocumentationViewer extends Controller { continue; } - + $child->LinkingMode = 'link'; $child->Children = $this->_getModulePagesNested($child, $module, $level + 1); } diff --git a/tests/DocumentationServiceTest.php b/tests/DocumentationServiceTest.php index 1accfe1..d746333 100644 --- a/tests/DocumentationServiceTest.php +++ b/tests/DocumentationServiceTest.php @@ -57,9 +57,10 @@ class DocumentationServiceTest extends SapphireTest { // second level $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 $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder')); - $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/", $path); + $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); // third level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));