From b49053cfab01c2f9c66fcc6204ce38d7b1f4f19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Garn=C3=A6s?= Date: Tue, 9 Aug 2011 16:44:26 +0200 Subject: [PATCH] Implemented support for XML --- bin/phrocco | 2 +- lib/adapters/XmlAdapter.php | 71 +++++++++++++++++++++++++++++++++++++ phrocco.php | 3 +- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 lib/adapters/XmlAdapter.php diff --git a/bin/phrocco b/bin/phrocco index 127b217..afb902f 100755 --- a/bin/phrocco +++ b/bin/phrocco @@ -19,7 +19,7 @@ if(count($argv)>1){ Command line options: -i Where to look for source code files - Searches recursively -o Root directory to output to - -l Language to parse. Currently PHP only, more to come. + -l Language to parse. Currently PHP and XML only, more to come. Examples: phrocco -i ./ -o ./docs diff --git a/lib/adapters/XmlAdapter.php b/lib/adapters/XmlAdapter.php new file mode 100644 index 0000000..2172e10 --- /dev/null +++ b/lib/adapters/XmlAdapter.php @@ -0,0 +1,71 @@ +`array of code lines`, "docs"=>`array of doc blocks`) + **/ + public function parse($file) { + // Load the file + $file = trim(file_get_contents($file)); + // Determine if we start with a documentation or code block + $is_start_doc = '', $f); + } + // Every entry should now be an array containing documentation first and + // code second. If we started with a code only block then we add an empty + // documentation block to keep this structure. + if (!$is_start_doc) { + array_unshift($file[0], ''); + } + + // Separate entries into code and documentation + $docs = array(); + $code = array(); + for ($i = 0; $i < sizeof($file); $i++) { + $docs[] = trim($file[$i][0]); + $code[] = $file[$i][1]; + } + + // Passes code onto pygmentize to add syntax highlighting + // Assemble the code into a single string we can pass on to pygmentize. + // Each block is separated by a delimiter. + $code = implode("\n\n", $code); + $pyg = new Pygment; + $code = $pyg->pygmentize("xml", $code); + // Separate by syntax highlighted delimiter again + $code = explode('<!--CODEBLOCK-->', $code); + + foreach($code as &$val) { + $val = rtrim($val); + $val = str_replace("\t", " ", $val); + $val='
'.trim($val, "\n\r").'
'; + } + + // Pass documentation through Markdown + foreach($docs as &$doc) { + $doc = Markdown($doc); + } + + // Our final array of code mapped to comments + return array("code"=>$code,"docs"=>$docs); + } + +} diff --git a/phrocco.php b/phrocco.php index 2e1571c..9290920 100755 --- a/phrocco.php +++ b/phrocco.php @@ -57,7 +57,8 @@ public function getExtension() { class PhroccoGroup { public $extensions = array( - "php" => array("php","phps","phpt") + "php" => array("php","phps","phpt"), + "xml" => array("xml") ); public $language = "php"; public $defaults = array(