[dokuwiki] Re: Newbie needs help understanding Plugin creation
- From: Chris Smith <chris@xxxxxxxxxxxxx>
- To: dokuwiki@xxxxxxxxxxxxx
- Date: Wed, 30 May 2007 14:43:37 +0100
As per my previous message, $data is the return value from handle(). So ...
... return array($match);
... $renderer->doc .= $data;
$renderer->doc is a string. $data is an array. You might want to try
$data[0] ;)
You may also want to reread the syntax plugin tutorial, this particular
paragraph says it all ...
handle() method
This is the part of your plugin which should do all the work. Before
Dokuwiki renders the wiki page it creates a list of instructions for the
renderer. The plugin’s handle() method generates the render instructions
for the plugin’s own syntax mode. At some later time, these will be
interpreted by the plugin’s render() method. The instruction list is
cached and can be used many times, making it sensible to maximise the
work done once by this function and minimise the work done many times by
render().
Also see ... http://wiki.splitbrain.org/wiki:caching#two-stage-caching
- Chris
Tony Steward wrote:
Ok I fixed the 10 & {{ but I still don't understand how to get second part ("red") to show in the
final document. "Hellow world" will display but not "red".
This may seem silly but I plan on doing a lot more and this is a learning
process for me as the docs arnt very clear.
Please explain why you say handle() is only executed rarely. The instructions
say that this is where all the processing should be done or did I mis
understand.
Perhaps fix my little script so I can see what is wrong?
Thanks
Tony Steward
-----Original Message-----
From: chris@xxxxxxxxxxxxx
Sent: Wed, 30 May 2007 12:20:20 +0100
To: dokuwiki@xxxxxxxxxxxxx
Subject: [dokuwiki] Re: Newbie needs help understanding Plugin creation
The return value of handle() is $data in the render() parameters.
handle() is only executed rarely, pretty much only when the page is
edited. render() is executed much more often and most often will use
the saved results from handle().
I noticed your substr() call in handle uses 10 for '{{' when the pattern
uses '<' and so should be 9.
Cheers,
Chris
Tony Steward wrote:
Hello,
I am trying to understand how plugin works & have adjusted the sample in
the tutorial.
How do I get data from the handle into render?
I want to put the likes of <KEYCONV|red> into a wiki page and have it
return "Hello
Worldred"
Below is what i tried and failed. Please show me how to do this.
Thanks
Tony
<?php
/**
* Plugin Skeleton: Displays "Hello World!"
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Christopher Smith <chris@xxxxxxxxxxxxx>
*/
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_keyconv extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Tony Steward',
'email' => 'tony_steward@xxxxxxxxx',
'date' => '2007-05-29',
'name' => 'Key Converter',
'desc' => 'Show keys from differant manufacturers',
'url' => 'http://www.locks.stewardclan.net/lockswiki/',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What kind of syntax do we allow (optional)
*/
// function getAllowedTypes() {
// return array();
// }
/**
* What about paragraphs? (optional)
*/
// function getPType(){
// return 'normal';
// }
/**
* Where to sort in?
*/
function getSort(){
return 999;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<KEYCONV|.+?>',$mode,'plugin_keyconv');
//
$this->Lexer->addEntryPattern('<keyconv>',$mode,'plugin_keyconv');
}
// function postConnect() {
// $this->Lexer->addExitPattern('</keyconv>','plugin_keyconv');
// }
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
$match = substr($match, 10, -2); // strip {{keyconv> from start
and }} from end
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
//return array($state, $match);
break;
case DOKU_LEXER_UNMATCHED :
break;
case DOKU_LEXER_EXIT :
break;
case DOKU_LEXER_SPECIAL :
break;
}
return array($match);
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
$renderer->doc .= "Hello World!"; // ptype =
'normal'
$renderer->doc .= $data;
// $renderer->doc .= "<p>Hello World!</p>"; // ptype =
'block'
return true;
}
return false;
}
}
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist
____________________________________________________________
PREVENT ACCESSING DANGEROUS WEBSITES - Protect your computer with Free Web Security Guard!
More information at http://www.inbox.com/wsg
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist
- Follow-Ups:
- [dokuwiki] Re: Newbie needs help understanding Plugin creation
- From: Tony Steward
- References:
- [dokuwiki] Re: Newbie needs help understanding Plugin creation
- From: Tony Steward
Other related posts:
- » [dokuwiki] Newbie needs help understanding Plugin creation
- » [dokuwiki] Re: Newbie needs help understanding Plugin creation
- » [dokuwiki] Re: Newbie needs help understanding Plugin creation
- » [dokuwiki] Re: Newbie needs help understanding Plugin creation
- » [dokuwiki] Re: Newbie needs help understanding Plugin creation
- » [dokuwiki] Re: Newbie needs help understanding Plugin creation
Ok I fixed the 10 & {{ but I still don't understand how to get second part ("red") to show in the
final document. "Hellow world" will display but not "red".
This may seem silly but I plan on doing a lot more and this is a learning
process for me as the docs arnt very clear.
Please explain why you say handle() is only executed rarely. The instructions
say that this is where all the processing should be done or did I mis
understand.
Perhaps fix my little script so I can see what is wrong?
Thanks
Tony Steward
-----Original Message----- From: chris@xxxxxxxxxxxxx Sent: Wed, 30 May 2007 12:20:20 +0100 To: dokuwiki@xxxxxxxxxxxxx Subject: [dokuwiki] Re: Newbie needs help understanding Plugin creation The return value of handle() is $data in the render() parameters. handle() is only executed rarely, pretty much only when the page is edited. render() is executed much more often and most often will use the saved results from handle(). I noticed your substr() call in handle uses 10 for '{{' when the pattern uses '<' and so should be 9. Cheers, Chris Tony Steward wrote:Hello, I am trying to understand how plugin works & have adjusted the sample in the tutorial. How do I get data from the handle into render? I want to put the likes of <KEYCONV|red> into a wiki page and have it return "Hello Worldred" Below is what i tried and failed. Please show me how to do this. Thanks Tony <?php /** * Plugin Skeleton: Displays "Hello World!" * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@xxxxxxxxxxxxx> */ 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_keyconv extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Tony Steward', 'email' => 'tony_steward@xxxxxxxxx', 'date' => '2007-05-29', 'name' => 'Key Converter', 'desc' => 'Show keys from differant manufacturers', 'url' => 'http://www.locks.stewardclan.net/lockswiki/', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What kind of syntax do we allow (optional) */ // function getAllowedTypes() { // return array(); // } /** * What about paragraphs? (optional) */ // function getPType(){ // return 'normal'; // } /** * Where to sort in? */ function getSort(){ return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('<KEYCONV|.+?>',$mode,'plugin_keyconv'); // $this->Lexer->addEntryPattern('<keyconv>',$mode,'plugin_keyconv'); } // function postConnect() { // $this->Lexer->addExitPattern('</keyconv>','plugin_keyconv'); // } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match, 10, -2); // strip {{keyconv> from start and }} from end switch ($state) { case DOKU_LEXER_ENTER : break; case DOKU_LEXER_MATCHED : //return array($state, $match); break; case DOKU_LEXER_UNMATCHED : break; case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : break; } return array($match); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= "Hello World!"; // ptype = 'normal' $renderer->doc .= $data; // $renderer->doc .= "<p>Hello World!</p>"; // ptype = 'block' return true; } return false; } }-- DokuWiki mailing list - more info at http://wiki.splitbrain.org/wiki:mailinglist
____________________________________________________________PREVENT ACCESSING DANGEROUS WEBSITES - Protect your computer with Free Web Security Guard! More information at http://www.inbox.com/wsg
- [dokuwiki] Re: Newbie needs help understanding Plugin creation
- From: Tony Steward
- [dokuwiki] Re: Newbie needs help understanding Plugin creation
- From: Tony Steward