Dev JumpStarts

This section is just to provide some intro for new plugin developers of DokuWiki. It will provide short explanation to introduce into simple syntax development.

We tried to provide balanced articles reduced to the most important facts instead explaining the whole world. We spiced the practical things, which can be easily followed up, with very few and short notes where we thought it is indispensable to understand some dependencies. Those will deliver at least a basic idea and some key-words for further self-made search attempts within the DokuWiki.org or Forum for further explanations.

Please do not hesitate to Contact us in the event of questions, suggestions and comments.

get a glimpseEnjoy coding
Taggic

Dev Jump Start - A very simple plugin

The following section delivers a simple plugin what just output the given parameter. To see that it is really done by the plugin it adds the 'MOO' text around. It is just to provide you an introducing overview without stepping into much details, therefore please read the comments within the php-code section of this chapter.

The php-Code

syntax.php
*/ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /****************************************************************************** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_xsstuff extends DokuWiki_Syntax_Plugin { /******************************************************************************/ /* return some info - for compatibility (DW Release Lemmings and before) * plugin.info.txt needed in any case ! */ function getInfo(){ return confToHash(dirname(__FILE__).'/plugin.info.txt'); } function getType(){ return 'substition';} // Returns the type of syntax this plugin defines function getPType(){ return 'block';} // Defines how this syntax is handled regarding paragraphs function getSort(){ return 999;} // Returns a number used to determine in which order modes are added /******************************************************************************/ /* Connect pattern to lexer */ function connectTo($mode){ $this->Lexer->addSpecialPattern('\{\[^}]*\>\}',$mode,'plugin_xsstuff'); } /******************************************************************************/ /* Handle the match */ function handle($match, $state, $pos, &$handler) { global $ID; // lets assume your syntax line looking as follows: // {alpha,bravo,charly>} $match = substr($match,strlen('{'),-2); //strip markup from start and end = 'alpha,bravo,charly' //handle params: load params into an array // the following will split the parameter string into an array of parameter $params = explode(',',$match); return $params; } /******************************************************************************/ /* Create output */ function render($mode, &$renderer, $data) { // chain params comma separated = alpha,bravo,charly $params = implode(',',$data); $ret ='MOO->| ' .$params. ' |<-MOO'; // Render: output of syntax parameter as text $renderer->doc .= $ret; } }
  1. <?php
  2. /**
  3. *  xsstuff Plugin: Plugin Dev Jumpstart - skeleton + simple plugin function
  4. *
  5. * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author     Taggic <taggic@t-online.de>
  7. */
  8.  
  9. if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
  10. if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  11. require_once(DOKU_PLUGIN.'syntax.php');  
  12.    
  13. /******************************************************************************
  14. * All DokuWiki plugins to extend the parser/rendering mechanism
  15. * need to inherit from this class
  16. */
  17. class syntax_plugin_xsstuff extends DokuWiki_Syntax_Plugin
  18. {
  19.  
  20. /******************************************************************************/
  21. /* return some info - for compatibility (DW Release Lemmings and before)
  22.  * plugin.info.txt needed in any case !
  23. */
  24.     function getInfo(){
  25.         return confToHash(dirname(__FILE__).'/plugin.info.txt');
  26.     }
  27.  
  28.     function getType(){ return 'substition';} // Returns the type of syntax this plugin defines
  29.     function getPType(){ return 'block';}     // Defines how this syntax is handled regarding paragraphs
  30.     function getSort(){ return 999;}          // Returns a number used to determine in which order modes are added
  31.    
  32. /******************************************************************************/
  33. /* Connect pattern to lexer
  34. */
  35.     function connectTo($mode){
  36.         $this->Lexer->addSpecialPattern('\{\<xsstuff>[^}]*\>\}',$mode,'plugin_xsstuff');
  37.     }
  38.  
  39. /******************************************************************************/
  40. /* Handle the match
  41. */
  42.     function handle($match, $state, $pos, &$handler) {
  43.         global $ID;
  44.         // lets assume your syntax line looking as follows:
  45.         // {<xsstuff>alpha,bravo,charly>}
  46.         $match = substr($match,strlen('{<xsstuff>'),-2); //strip markup from start and end = 'alpha,bravo,charly'
  47.         //handle params: load params into an array
  48.         // the following will split the parameter string into an array of parameter
  49.         $params = explode(',',$match);  
  50.         return $params;        
  51.      }
  52.  
  53. /******************************************************************************/
  54. /* Create output
  55. */
  56.     function render($mode, &$renderer, $data) {
  57.          // chain params comma separated = alpha,bravo,charly
  58.          $params = implode(',',$data);
  59.          $ret ='MOO->|  ' .$params. '  |<-MOO';
  60.          // Render: output of syntax parameter as text            
  61.          $renderer->doc .=  $ret;
  62.      }
  63. }
  64.  

Syntax

{<xsstuff>alpha,bravo,charly>}

Output

MOO->| alpha,bravo,charly |<-MOO

The Plugin

To get the complete plugin please download: xsstuff.zip



Dev Jump Start - Extended simple plugin (html)

See the following example regarding direct html and styling output, it is simple add. The example shows that you can also output self-made html-code. Just modify the render function of your xsStuff plugin accordingly (or download the zip below). The page syntax keeps unchanged. You may store the style into a “style.css” file within your plugin folder. Do not forget to add a related class to the html code of syntax file if you use style.css.

The php-Code

syntax.php
/******************************************************************************/ /* Create output */ function render($mode, &$renderer, $data) { // let's loop through the parameter and put color and text style to each of them $color = array('red','green','blue'); $txt_style = array('bold','normal','bolder'); $s=0; foreach($data as $bit) { $output .= ''.$bit.'
'; $s++; if($s>2) $s=0; } // Render: output of syntax parameter as colored, styled text, one below the other $renderer->doc .= $output; }
  1. /******************************************************************************/
  2. /* Create output
  3. */
  4. function render($mode, &$renderer, $data) {
  5.      // let's loop through the parameter and put color and text style to each of them
  6.      $color = array('red','green','blue');
  7.      $txt_style = array('bold','normal','bolder');
  8.      $s=0;
  9.      foreach($data as $bit) {
  10.         $output .=  '<span style="color:'.$color[$s].'; font-weight:'.$txt_style[$s].';">'.$bit.'</span><br />';
  11.         $s++;
  12.         if($s>2) $s=0;
  13.      }
  14.      
  15.      // Render: output of syntax parameter as colored, styled text, one below the other            
  16.      $renderer->doc .=  $output;
  17. }
  18.  

The output

alpha
bravo
charly

The Plugin

To get the complete plugin please download: xmstuff.zip


see also

tips/tips_devjumps.txt · Last modified: 2014/04/30 09:36 (external edit)

This Wiki is hosted and ruled by Policies of Frister Consultancy Services.
By using this wiki you accept these rules. -> Impressum