Skip to content

Commit

Permalink
Added parameter for setting the desired output format for transformat…
Browse files Browse the repository at this point in the history
…ion, separated target param for transformation into a source and target param, added a license file
  • Loading branch information
mvriel committed Oct 6, 2010
1 parent fd3ecdd commit 4020b11
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 41 deletions.
12 changes: 12 additions & 0 deletions DocBlox/Writer/Abstract.php
Expand Up @@ -16,6 +16,7 @@ class DocBlox_Writer_Abstract extends DocBlox_Abstract
protected $theme = 'default';
protected $theme_path = '';
protected $target = '';
protected $source = '';
protected $resource_path = '';

public function __construct()
Expand All @@ -24,6 +25,17 @@ public function __construct()
$this->resource_path = $root_path.'/resources';
$this->theme_path = $this->resource_path.'/themes';
$this->target = $root_path.'/output';
$this->source = $root_path.'/output/structure.xml';
}

public function getSource()
{
return $this->source;
}

public function setSource($source)
{
$this->source = $source;
}

public function getTarget()
Expand Down
6 changes: 4 additions & 2 deletions DocBlox/Writer/Xslt.php
Expand Up @@ -160,7 +160,8 @@ function generateFullPath($path)

public function execute()
{
$target_path = realpath($this->target);
$target_path = realpath($this->getTarget());
$source_file = realpath($this->getSource());

// copy all generic files to the target folder
$this->copyRecursive($this->resource_path.'/js', $target_path.'/js');
Expand All @@ -175,7 +176,7 @@ public function execute()

// Load the XML source
$xml = new DOMDocument();
$xml->load($target_path.'/structure.xml');
$xml->load($source_file);

// get a list of contained files
$files = array();
Expand All @@ -194,6 +195,7 @@ public function execute()

$this->log('Generating the class diagram');
$class_graph = new DocBlox_Writer_Xslt_ClassGraph();
$class_graph->setTarget($this->getTarget());
$class_graph->execute($xml);
}
}
24 changes: 22 additions & 2 deletions DocBlox/Writer/Xslt/ClassGraph.php
Expand Up @@ -20,6 +20,26 @@ class DocBlox_Writer_Xslt_ClassGraph extends DocBlox_Abstract
{
protected $target = './output';

/**
* Returns the target location for the SVG.
*
* @return string
*/
public function getTarget()
{
return $this->target;
}

/**
* Sets the target location for the SVG.
*
* @return string
*/
public function setTarget($target)
{
$this->target = $target;
}

public function execute(DomDocument $xml)
{
// NOTE: the -V flag sends output using STDERR and STDOUT
Expand Down Expand Up @@ -102,7 +122,7 @@ public function execute(DomDocument $xml)
$graph->renderDotFile($dot_file, $path.'/classes.svg');
}

function buildTreenode($node_list, $parent = 'stdClass')
protected function buildTreenode($node_list, $parent = 'stdClass')
{
if (!isset($node_list[$parent]))
{
Expand All @@ -118,7 +138,7 @@ function buildTreenode($node_list, $parent = 'stdClass')
return $result;
}

function buildGraphNode(Image_GraphViz $graph, $nodes, $parent = null)
protected function buildGraphNode(Image_GraphViz $graph, $nodes, $parent = null)
{
foreach($nodes as $node => $children)
{
Expand Down
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2010 Mike van Riel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
9 changes: 5 additions & 4 deletions TODO
@@ -1,20 +1,21 @@
0.6: Add configuration files, clean up and fixes
+ Add Zend_Config support for projects and default configuration (command-line options override settings)
* Clean up code
+ Capture STDERR message when graphviz is not installed (ClassGraph.php:26)
+ Get Transformation Writer from Config
+ separate source and target parameter for transform.php
+ Add license (information)
+ add output format parameter to transform.php
* Check theming support and improve
* separate source and target parameter for transform.php
* description tab of class goes out of bounds if the tags are too big
* safari does not show the svg nicely, it places it into a very small scrollbox
* add line numbers to markers
* Add license (information)

0.7: Enhance docblock support, statistics support and add support for multiple writers
* add inline parsing of annotations in docblock descriptions (see /lib/Zend/Log/Formatter/Firebug.php:40 for an example)
* add parsing of docblock annotations and adding specific functionality per annotation
* Keep track of number of docblock successes and fails and show at the end of the process
* Add statistics (nr of files, classes, methods, with or without docblock. Percentage, lines per method, lines per file, configurable thresholds, etc)
* add output format parameter to transform.php and support for multiple writers
* Add PDF output writer
* syntax highlight @example annotation content

0.8: Add custom documents
Expand Down
90 changes: 57 additions & 33 deletions bin/transform.php
Expand Up @@ -16,8 +16,10 @@
// initialize the argument parser
$opts = new Zend_Console_Getopt(array(
'help|h' => 'show this help message',
'target|t-s' => 'path where the structure.xml is located and where to save the generated files (optional, defaults to "output")',
'theme-s' => 'name of the theme to use (optional, defaults to "default")',
'source|s-s' => 'path where the structure.xml is located (optional, defaults to "output/structure.xml")',
'target|t-s' => 'path where to save the generated files (optional, defaults to "output")',
'output|o-s' => 'output format to use (optional, defaults to "xslt")',
'theme-s' => 'name of the theme to use (optional, defaults to "default")',
'verbose|v' => 'Outputs any information collected by this application, may slow down the process slightly',
));

Expand All @@ -29,52 +31,74 @@
{
throw new Zend_Console_Getopt_Exception('');
}
} catch (Zend_Console_Getopt_Exception $e)
{
// if the message actually contains anything, show it.
if ($e->getMessage())

// initialize timer
$timer = new sfTimer();

if ($opts->getOption('output'))
{
echo $e->getMessage() . PHP_EOL . PHP_EOL;
$writer = $opts->getOption('output');
} else
{
if (!isset(DocBlox_Abstract::config()->transformation->writer))
{
throw new Exception('Unable to find configuration entry for the transformation writer, please check your configuration file.');
}
$writer = DocBlox_Abstract::config()->transformation->writer;
}
$writer = 'DocBlox_Writer_'.ucfirst($writer);
$writer = new $writer();

// show help message and exit the application
echo $opts->getUsageMessage();
exit;
}
// set target option if it was provided by the user
if ($opts->getOption('target'))
{
$path = realpath($opts->getOption('target'));
if (!file_exists($path) && !is_dir($path) && !is_writable($path))
{
throw new Exception('Given target directory does not exist or is not writable');
}

// initialize timer
$timer = new sfTimer();
$writer->setTarget($path);
}

echo 'Starting transformation of files (this could take a while depending upon the size of your project)'.PHP_EOL;
// set source option if it was provided by the user
if ($opts->getOption('source'))
{
$path = realpath($opts->getOption('source'));
if (!file_exists($path) || !is_readable($path))
{
throw new Exception('Given source does not exist or is not readable');
}

// TODO: for now we have hardcoded the Xslt writer, this must become a config entry or argument
$writer = new DocBlox_Writer_Xslt();
$writer->setSource($path);
}

// set target option if it was provided by the user
if ($opts->getOption('t'))
{
$path = realpath($opts->getOption('t'));
if (!file_exists($path) || !is_readable($path.'/structure.xml'))
// set theme / chrome path if provided
if ($opts->getOption('theme'))
{
throw new Exception('Given target or structure.xml does not exist or is not readable');
$writer->setTheme($opts->getOption('theme'));
}

$writer->setTarget($path);
}

// set theme / chrome path if provided
if ($opts->getOption('theme'))
// enable verbose mode if the flag was set
if ($opts->getOption('verbose'))
{
$writer->setLogLevel(Zend_Log::DEBUG);
}
} catch (Exception $e)
{
$writer->setTheme($opts->getOption('theme'));
}
// if the message actually contains anything, show it.
if ($e->getMessage())
{
echo $e->getMessage() . PHP_EOL . PHP_EOL;
}

// enable verbose mode if the flag was set
if ($opts->getOption('verbose'))
{
$writer->setLogLevel(Zend_Log::DEBUG);
// show help message and exit the application
echo $opts->getUsageMessage();
exit;
}

// start the transformation process
echo 'Starting transformation of files (this could take a while depending upon the size of your project)'.PHP_EOL;
$writer->execute();

echo 'Finished transformation in '.round($timer->getElapsedTime(), 2).' seconds'.PHP_EOL;
3 changes: 3 additions & 0 deletions config.xml
Expand Up @@ -17,4 +17,7 @@
<item>TODO</item>
<item>FIXME</item>
</markers>
<transformation>
<writer>xslt</writer>
</transformation>
</docblox>

0 comments on commit 4020b11

Please sign in to comment.