FEATURE: added parser for metadata inside documentation. MINOR: removed outdated code

This commit is contained in:
Will Rossiter 2011-01-14 03:29:14 +00:00
parent 768345a8b9
commit e571b5973f
5 changed files with 65 additions and 23 deletions

View File

@ -141,10 +141,6 @@ class DocumentationPage extends ViewableData {
return $link; return $link;
} }
function setFullPath($path) {
$this->fullPath = $path;
}
function getLang() { function getLang() {
return $this->lang; return $this->lang;
} }
@ -169,6 +165,16 @@ class DocumentationPage extends ViewableData {
return $this->title; return $this->title;
} }
/**
* Set a variable from the metadata field on this class
*
* @param String key
* @param mixed value
*/
public function setMetaData($key, $value) {
$this->$key = $value;
}
/** /**
* @return string * @return string
*/ */
@ -205,6 +211,6 @@ class DocumentationPage extends ViewableData {
*/ */
function getHTML($baselink = null) { function getHTML($baselink = null) {
// if this is not a directory then we can to parse the file // if this is not a directory then we can to parse the file
return DocumentationParser::parse($this->getPath(true), $baselink); return DocumentationParser::parse($this, $baselink);
} }
} }

View File

@ -303,4 +303,27 @@ class DocumentationParser {
return $md; return $md;
} }
/**
* Strips out the metadata for a page
*
* @param DocumentationPage
*/
public static function retrieve_meta_data(DocumentationPage &$page) {
if($md = $page->getMarkdown()) {
$matches = preg_match_all('/
(?<key>[A-Za-z0-9_-]+):
\s*
(?<value>.*)
/x', $md, $meta);
if($matches) {
foreach($meta['key'] as $index => $key) {
if(isset($meta['value'][$index])) {
$page->setMetaData($key, $meta['value'][$index]);
}
}
}
}
}
} }

View File

@ -387,7 +387,6 @@ class DocumentationService {
if($handle) { if($handle) {
$extensions = DocumentationService::get_valid_extensions(); $extensions = DocumentationService::get_valid_extensions();
$firstFile = false;
// ensure we end with a slash // ensure we end with a slash
$base = rtrim($base, '/') .'/'; $base = rtrim($base, '/') .'/';
@ -406,9 +405,6 @@ 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. // the folder is the one that we are looking for.
if(strtolower($name) == strtolower($formatted)) { if(strtolower($name) == strtolower($formatted)) {

View File

@ -205,4 +205,16 @@ HTML;
$result $result
); );
} }
function testRetrieveMetaData() {
$page = new DocumentationPage();
$page->setRelativePath('MetaDataTest.md');
$page->setEntity(new DocumentationEntity('parser', '2.4', BASE_PATH . '/sapphiredocs/tests/docs-parser/'));
DocumentationParser::retrieve_meta_data($page);
$this->assertEquals('Dr. Foo Bar.', $page->Author);
$this->assertEquals("Foo Bar's Test page.", $page->getTitle());
$this->assertEquals("Foo Bar's Test page.", $page->Title);
}
} }

View File

@ -0,0 +1,5 @@
Title: Foo Bar's Test page.
Author: Dr. Foo Bar.
Another: Test.
# Content