mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
ENHANCEMENT: contrary to r115556, display a listing of files within an empty folder index rather than defaulting to the first file. Fixes #6347
This commit is contained in:
parent
2a7b7ee83d
commit
768345a8b9
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
13
templates/DocFolderListing.ss
Normal file
13
templates/DocFolderListing.ss
Normal file
@ -0,0 +1,13 @@
|
||||
<% if Pages %>
|
||||
<div id="folder-listing">
|
||||
<h2>$Title</h2>
|
||||
|
||||
<ul>
|
||||
<% control Pages %>
|
||||
<li><a href="$Link">$Title</a></li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>Nothing to see here</p>
|
||||
<% end_if %>
|
@ -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'));
|
||||
|
Loading…
Reference in New Issue
Block a user