BUGFIX: Deprecation errors and strict warnings breaks the docsviewer

This commit is contained in:
Stig Lindqvist 2012-05-18 09:48:57 +12:00
parent ae092ebf19
commit fa646cdbf6
6 changed files with 36 additions and 8 deletions

View File

@ -43,7 +43,7 @@ class DocumentationParser {
$md = self::rewrite_api_links($md, $page);
$md = self::rewrite_heading_anchors($md, $page);
$md = self::rewrite_code_blocks($md, $page);
$md = self::rewrite_code_blocks($md);
require_once(DOCSVIEWER_PATH .'/thirdparty/markdown/markdown.php');
@ -53,11 +53,11 @@ class DocumentationParser {
return $parser->transform($md);
}
function rewrite_code_blocks($md) {
public static function rewrite_code_blocks($md) {
$started = false;
$inner = false;
$lines = split("\n", $md);
$lines = explode("\n", $md);
foreach($lines as $i => $line) {
if(!$started && preg_match('/^\t*:::\s*(.*)/', $line, $matches)) {
// first line with custom formatting
@ -203,14 +203,14 @@ class DocumentationParser {
/**
*
*/
static function rewrite_heading_anchors($md, $page) {
public static function rewrite_heading_anchors($md, $page) {
$re = '/^\#+(.*)/m';
$md = preg_replace_callback($re, array('DocumentationParser', '_rewrite_heading_anchors_callback'), $md);
return $md;
}
static function _rewrite_heading_anchors_callback($matches) {
public static function _rewrite_heading_anchors_callback($matches) {
$heading = $matches[0];
$headingText = $matches[1];
@ -236,8 +236,8 @@ class DocumentationParser {
$t = $title;
$t = str_replace('&','-and-',$t);
$t = str_replace('&','-and-',$t);
$t = ereg_replace('[^A-Za-z0-9]+','-',$t);
$t = ereg_replace('-+','-',$t);
$t = preg_replace('/[^A-Za-z0-9]+/','-',$t);
$t = preg_replace('/-+/','-',$t);
$t = trim($t, '-');
$t = strtolower($t);

View File

@ -110,7 +110,7 @@ class DocumentationService {
*
* @return array
*/
public function get_ignored_files() {
public static function get_ignored_files() {
return self::$ignored_files;
}

View File

@ -4,6 +4,15 @@
*/
class DocumentationParserTest extends SapphireTest {
function testGenerateHtmlId() {
$this->assertEquals('title-one', DocumentationParser::generate_html_id('title one'));
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title one'));
$this->assertEquals('title-and-one', DocumentationParser::generate_html_id('Title & One'));
$this->assertEquals('title-and-one', DocumentationParser::generate_html_id('Title & One'));
$this->assertEquals('title-one', DocumentationParser::generate_html_id(' Title one '));
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title--one'));
}
function testRewriteCodeBlocks() {
$page = new DocumentationPage();
$page->setRelativePath('test.md');

View File

@ -268,4 +268,17 @@ class DocumentationViewerTest extends FunctionalTest {
$this->assertNull($warn->OutdatedRelease);
$this->assertTrue($warn->FutureRelease);
}
/**
* Test that the pages comes back sorted by filename
*/
function testGetEntityPagesSortedByFilename() {
$v = new DocumentationViewer();
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0/'), DataModel::inst());
$pages = $v->getEntityPages();
$links = $pages->column('Link');
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/ChangeLog', $links[0]);
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/Tutorials', $links[1]);
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/empty', $links[2]);
}
}

View File

@ -0,0 +1,3 @@
# Changelog
This is a changelog

View File

@ -0,0 +1,3 @@
# Tutorials
This a bunch of tutorials