ENHANCEMENT: hide index pages from menus. BUGFIX: fixed incorrect name strings coming through on nested pages

This commit is contained in:
Will Rossiter 2010-10-29 02:12:20 +00:00
parent 8a02cee714
commit 9335c789af
3 changed files with 27 additions and 14 deletions

View File

@ -320,7 +320,7 @@ class DocumentationParser {
$name = strtolower(array_shift($goal));
if(!$name) $name = 'index';
if($handle) {
$extensions = DocumentationService::get_valid_extensions();
@ -331,11 +331,10 @@ class DocumentationParser {
// if the name has a . then take the substr
$formatted = ($pos = strrpos($formatted, '.')) ? substr($formatted, 0, $pos) : $formatted;
$name = ($dot = strrpos($formatted, '.')) ? substr($name, 0, $dot) : $name;
// the folder is the one that we are looking for.
if($name == $formatted) {
$name = ($dot = strrpos($name, '.')) ? substr($name, 0, $dot) : $name;
// the folder is the one that we are looking for.
if(strtolower($name) == strtolower($formatted)) {
if(is_dir($base . $file)) {
// if this is a directory check that there is any more states to get
// to in the goal. If none then what we want is the 'index.md' file
@ -350,13 +349,13 @@ class DocumentationParser {
else {
// goal state. End of recursion
$result = $base .'/'. $file;
return $result;
}
}
}
}
closedir($handle);
}

View File

@ -354,6 +354,7 @@ class DocumentationViewer extends Controller {
if(!$module) return false;
$absFilepath = DocumentationParser::find_page($module->getPath(), $this->Remaining);
if($absFilepath) {
$relativeFilePath = str_replace($module->getPath(), '', $absFilepath);
@ -382,6 +383,12 @@ class DocumentationViewer extends Controller {
if($pages) {
foreach($pages as $page) {
if(strtolower($page->Title) == "index") {
$pages->remove($page);
continue;
}
$linkParts = array();
// don't include the 'index in the url
@ -426,6 +433,12 @@ class DocumentationViewer extends Controller {
}
foreach($children as $child) {
if(strtolower($child->Title) == "index") {
$children->remove($child);
continue;
}
$child->Link = $this->Link(array_merge($segments, array($child->Filename)));
$child->LinkingMode = 'link';
$child->Children = $this->_getModulePagesNested($child, $level + 1);

View File

@ -127,22 +127,23 @@ class DocumentationViewerTests extends FunctionalTest {
$response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/'));
$pages = $v->getModulePages();
$this->assertEquals(
array('index', 'sort', 'subfolder', 'test'),
array('sort', 'subfolder', 'test'),
$pages->column('Filename')
);
$this->assertEquals(
array('link', 'link','current', 'link'),
array('link','current', 'link'),
$pages->column('LinkingMode')
);
$links = $pages->column('Link');
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/', $links[0]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/sort/', $links[1]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[2]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[3]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/sort/', $links[0]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[1]);
$this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[2]);
// Children
$pagesArr = $pages->toArray();
$child1 = $pagesArr[0];
$child1 = $pagesArr[1];
$this->assertFalse($child1->Children);