diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-09-29 20:17:39 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-09-29 20:17:39 +0200 |
commit | 6c1ae996157551dcf5bb4e7e8922677bb3d3d358 (patch) | |
tree | b3a4162367176a4e2ebadbd6ab31753c1b042be0 /bin/render.php | |
parent | 35f3340eb3b989194a496861abfb5b3d3c9a630d (diff) | |
parent | 57271d078b9c433bec79d75cb44dadcafeae07df (diff) | |
download | rpg-6c1ae996157551dcf5bb4e7e8922677bb3d3d358.tar.gz rpg-6c1ae996157551dcf5bb4e7e8922677bb3d3d358.tar.bz2 |
Merge branch 'master' into stable
* master: (214 commits)
release preparations
postgresql auth plugin: correct function name
parse AT parameter: first strtotime then timestamp remove config option
move more strings to lang.php
move strings to lang.php
add placeholders for create page text
phpdocs parserutils
improve some scrutinizer issues
visibility plugin methods
use config cascade for loading of localizations
reformatting config cascade
add lang files to cascading
work around missing gzopen on certain systems #865
translation update
fix scrutinizer issues
fixed typos in docblock comments
do not allow empty passwords
clean user credentials from control chars
added filter method to INPUT class
translation update
...
Diffstat (limited to 'bin/render.php')
-rwxr-xr-x | bin/render.php | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/bin/render.php b/bin/render.php index d30ef2958..672993223 100755 --- a/bin/render.php +++ b/bin/render.php @@ -1,5 +1,10 @@ #!/usr/bin/php <?php +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +define('NOSESSION', 1); +require_once(DOKU_INC.'inc/init.php'); + + /** * A simple commandline tool to render some DokuWiki syntax with a given * renderer. @@ -9,59 +14,48 @@ * DokuWiki markup * * @license GPL2 - * @author Andreas Gohr <andi@splitbrain.org> + * @author Andreas Gohr <andi@splitbrain.org> */ -if ('cli' != php_sapi_name()) die(); +class RenderCLI extends DokuCLI { -ini_set('memory_limit','128M'); -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -define('NOSESSION',1); -require_once(DOKU_INC.'inc/init.php'); -require_once(DOKU_INC.'inc/common.php'); -require_once(DOKU_INC.'inc/parserutils.php'); -require_once(DOKU_INC.'inc/cliopts.php'); - -// handle options -$short_opts = 'hr:'; -$long_opts = array('help','renderer:'); -$OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts); -if ( $OPTS->isError() ) { - fwrite( STDERR, $OPTS->getMessage() . "\n"); - _usage(); - exit(1); -} -$RENDERER = 'xhtml'; -foreach ($OPTS->options as $key => $val) { - switch ($key) { - case 'h': - case 'help': - _usage(); - exit; - case 'r': - case 'renderer': - $RENDERER = $val; + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + $options->setHelp( + 'A simple commandline tool to render some DokuWiki syntax with a given renderer.'. + "\n\n". + 'This may not work for plugins that expect a certain environment to be '. + 'set up before rendering, but should work for most or even all standard '. + 'DokuWiki markup' + ); + $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode'); } -} + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @throws DokuCLI_Exception + * @return void + */ + protected function main(DokuCLI_Options $options) { + $renderer = $options->getOpt('renderer', 'xhtml'); -// do the action -$source = stream_get_contents(STDIN); -$info = array(); -$result = p_render($RENDERER,p_get_instructions($source),$info); -if(is_null($result)) die("No such renderer $RENDERER\n"); -echo $result; - -/** - * Print usage info - */ -function _usage(){ - print "Usage: render.php <options> - - Reads DokuWiki syntax from STDIN and renders it with the given renderer - to STDOUT - - OPTIONS - -h, --help show this help and exit - -r, --renderer <renderer> the render mode (default: xhtml) -"; + // do the action + $source = stream_get_contents(STDIN); + $info = array(); + $result = p_render($renderer, p_get_instructions($source), $info); + if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer"); + echo $result; + } } + +// Main +$cli = new RenderCLI(); +$cli->run();
\ No newline at end of file |