summaryrefslogtreecommitdiff
path: root/platform/www/bin/render.php
blob: 6076951910ce56d624541f92f31f421367336f0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env php
<?php

use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;

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.
 *
 * 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>
 */
class RenderCLI extends CLI {

    /**
     * Register options and arguments on the given $options object
     *
     * @param Options $options
     * @return void
     */
    protected function setup(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 Options $options
     * @throws DokuCLI_Exception
     * @return void
     */
    protected function main(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)) throw new DokuCLI_Exception("No such renderer $renderer");
        echo $result;
    }
}

// Main
$cli = new RenderCLI();
$cli->run();