summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2010-01-05 23:42:55 +0100
committerAndreas Gohr <andi@splitbrain.org>2010-01-05 23:42:55 +0100
commitd421dc123691a8d6409c4d224ba28e5bbdd5eeed (patch)
treed0eef5e19b90417c9ee7f9d63a742b09db17cbbb /bin
parentbe98b27c033249b156719149299e9bf7a2e16701 (diff)
downloadrpg-d421dc123691a8d6409c4d224ba28e5bbdd5eeed.tar.gz
rpg-d421dc123691a8d6409c4d224ba28e5bbdd5eeed.tar.bz2
Added a rendering commandline tool
This simple tool renders some syntax given on STDIN with the given renderer (defaults to xhtml) and outputs to STDOUT.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/render.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/bin/render.php b/bin/render.php
new file mode 100755
index 000000000..45e463c01
--- /dev/null
+++ b/bin/render.php
@@ -0,0 +1,67 @@
+#!/usr/bin/php
+<?php
+/**
+ * A simple commandline tool to render some DokuWiki syntax with a given
+ * renderer.
+ *
+ * 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
+ *
+ * @license GPL2
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+if ('cli' != php_sapi_name()) die();
+
+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;
+ }
+}
+
+
+// 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");
+
+
+/**
+ * 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)
+";
+}