mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX: Resolve navigation sorting using natural sort
This commit is contained in:
parent
a069dbd9d9
commit
6ba14bed75
@ -384,7 +384,8 @@ class DocumentationParser {
|
||||
|
||||
|
||||
/**
|
||||
* Return the children from a given module. Used for building the tree of the page
|
||||
* Return the children from a given module sorted by Title using natural ordering.
|
||||
* It is used for building the tree of the page.
|
||||
*
|
||||
* @param String module name
|
||||
*
|
||||
@ -393,6 +394,7 @@ class DocumentationParser {
|
||||
public static function get_pages_from_folder($folder) {
|
||||
$handle = opendir($folder);
|
||||
$output = new DataObjectSet();
|
||||
$files = array();
|
||||
|
||||
if($handle) {
|
||||
$extensions = DocumentationService::get_valid_extensions();
|
||||
@ -400,17 +402,23 @@ class DocumentationParser {
|
||||
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if(!in_array($file, $ignore)) {
|
||||
$file = strtolower($file);
|
||||
|
||||
$clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => self::clean_page_name($file),
|
||||
'Filename' => $clean,
|
||||
'Path' => $folder . $file .'/'
|
||||
)));
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
natsort($files);
|
||||
|
||||
foreach($files as $file) {
|
||||
$file = strtolower($file);
|
||||
|
||||
$clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => self::clean_page_name($file),
|
||||
'Filename' => $clean,
|
||||
'Path' => $folder . $file .'/'
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
@ -211,6 +211,14 @@ class DocumentationParserTest extends SapphireTest {
|
||||
$this->assertContains('subfolder', $pages->column('Filename'), 'Foldername');
|
||||
$this->assertContains('test', $pages->column('Filename'), 'Filename');
|
||||
$this->assertNotContains('_images', $pages->column('Filename'), 'Ignored files');
|
||||
|
||||
// test the order of pages
|
||||
$pages = DocumentationParser::get_pages_from_folder(BASE_PATH . '/sapphiredocs/tests/docs/en/sort');
|
||||
$this->assertEquals(
|
||||
array('1 basic', '2 intermediate', '3 advanced', '10 some page', '21 another page'),
|
||||
$pages->column('Title')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
0
tests/docs/en/sort/1-basic.md
Normal file
0
tests/docs/en/sort/1-basic.md
Normal file
0
tests/docs/en/sort/10-some-page.md
Normal file
0
tests/docs/en/sort/10-some-page.md
Normal file
0
tests/docs/en/sort/2-intermediate.md
Normal file
0
tests/docs/en/sort/2-intermediate.md
Normal file
0
tests/docs/en/sort/21-another-page.md
Normal file
0
tests/docs/en/sort/21-another-page.md
Normal file
0
tests/docs/en/sort/3-advanced.md
Normal file
0
tests/docs/en/sort/3-advanced.md
Normal file
Loading…
x
Reference in New Issue
Block a user