PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/render.php

http://github.com/splitbrain/dokuwiki
PHP | 64 lines | 28 code | 7 blank | 29 comment | 2 complexity | c7586c30f0c560abec547b72f2d1f99e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. #!/usr/bin/php
  2. <?php
  3. use splitbrain\phpcli\CLI;
  4. use splitbrain\phpcli\Options;
  5. if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
  6. define('NOSESSION', 1);
  7. require_once(DOKU_INC . 'inc/init.php');
  8. /**
  9. * A simple commandline tool to render some DokuWiki syntax with a given
  10. * renderer.
  11. *
  12. * This may not work for plugins that expect a certain environment to be
  13. * set up before rendering, but should work for most or even all standard
  14. * DokuWiki markup
  15. *
  16. * @license GPL2
  17. * @author Andreas Gohr <andi@splitbrain.org>
  18. */
  19. class RenderCLI extends CLI {
  20. /**
  21. * Register options and arguments on the given $options object
  22. *
  23. * @param Options $options
  24. * @return void
  25. */
  26. protected function setup(Options $options) {
  27. $options->setHelp(
  28. 'A simple commandline tool to render some DokuWiki syntax with a given renderer.' .
  29. "\n\n" .
  30. 'This may not work for plugins that expect a certain environment to be ' .
  31. 'set up before rendering, but should work for most or even all standard ' .
  32. 'DokuWiki markup'
  33. );
  34. $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode');
  35. }
  36. /**
  37. * Your main program
  38. *
  39. * Arguments and options have been parsed when this is run
  40. *
  41. * @param Options $options
  42. * @throws DokuCLI_Exception
  43. * @return void
  44. */
  45. protected function main(Options $options) {
  46. $renderer = $options->getOpt('renderer', 'xhtml');
  47. // do the action
  48. $source = stream_get_contents(STDIN);
  49. $info = array();
  50. $result = p_render($renderer, p_get_instructions($source), $info);
  51. if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer");
  52. echo $result;
  53. }
  54. }
  55. // Main
  56. $cli = new RenderCLI();
  57. $cli->run();