ENHANCEMENT: if a folder is missing an index.md file load the first file as a failback

This commit is contained in:
Will Rossiter 2011-01-14 01:48:36 +00:00
parent fc8ab96c51
commit 2a7b7ee83d
3 changed files with 24 additions and 12 deletions

View File

@ -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;
}
/**

View File

@ -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
@ -441,7 +445,12 @@ 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();

View File

@ -58,8 +58,9 @@ 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
$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'));