====== Trump suits plugin for DokuWiki ======
This may not be the most spectacular DokuWiki plugin available, but it suits my own needs just fine. The plugin renders (FIXME will render in the near future) the diamond and heart card suit symbols in red, and the clubs and spade card suit symbols in black. It also adds four buttons to the editor toolbar for quick access to the trump suit symbols.
Due to my very limited knowledge of PHP and javascript I can't guarantee this won't set fire to your DokuWiki server. Mine seems to have survived this far though, so there is hope yet. Suggestions for improvement are very welcome.
===== Syntax =====
No special syntax. Just use standard UTF card suit symbols (optionally inserted by using the toolbar buttons).
===== Installation =====
==== Plugin manager ====
Point your plug-in manager at [[/downloads/trumpsuits-dokuwiki-plugin.tar.gz]] or [[/downloads/trumpsuits-dokuwiki-plugin.zip]]. FIXME
==== Manual ====
Create the folder ''lib/plugins/trumpsuits'' in your DokuWiki folder. Create ''syntax.php'' and ''scrips.js'' as given below. Create the folder lib/plugins/trumpsuits/images and place the images in this table in there.
^ Suit ^ Filename ^ Image ^
| Clubs | clubs.png | {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/clubs.png}} |
| Diamonds | diamonds.png | {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/diamonds.png}} |
| Hearts | hearts.png | {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/hearts.png}} |
| Spades | spades.png | {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/spades.png}} |
=== syntax.php ===
Take care not to include whitespace in front of the first php tag or after the last php tag. This leads to strange behaviour by DokuWiki.
*/
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_trumpsuits extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Pieter van der Meulen',
'email' => 'pieter@vdmeulen.net',
'date' => '2007-08-09',
'name' => 'trumpsuits',
'desc' => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black.',
'url' => 'http://www.vdmeulen.net/wiki/bridge/trumpsuits-dokuwiki-plugin',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
//This must be implemented
function getSort(){ return 123; }
}
?>
Hieruit eventueel nog stukje gebruiken:
tags into the document when trumpsigns are encountered
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Pieter van der Meulen
*/
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_tab extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Pieter van der Meulen',
'email' => 'dev@vdmeulen.net',
'date' => '2006-11-20',
'name' => 'Trumpsigns Plugin',
'desc' => 'Inserts tags into the html around trump signs',
'url' => 'http://www.vdmeulen.net/wiki/bridge/troeftekens_in_dokuwiki#vergroot_in_rood_en_wart_weergeven',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* Where to sort in?
*/
function getSort(){
return 789;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('♣',$mode,'plugin_trumpsigns');
$this->Lexer->addSpecialPattern('♦',$mode,'plugin_trumpsigns');
$this->Lexer->addSpecialPattern('♥',$mode,'plugin_trumpsigns');
$this->Lexer->addSpecialPattern('♠',$mode,'plugin_trumpsigns');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
break;
case DOKU_LEXER_UNMATCHED :
break;
case DOKU_LEXER_EXIT :
break;
case DOKU_LEXER_SPECIAL :
break;
}
return array();
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
$renderer->doc .= "XXX+";
$renderer->doc .= $data;
$renderer->doc .= "-XXX";
return true;
}
return false;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
=== script.js ===
//create a single toolbutton with desired properties
function plugin_trumpsuits_createToolbutton (id, tooltipText, imgFile, insText, accKey) {
var ico = document.createElement("img");
ico.src = DOKU_BASE + "lib/plugins/trumpsuits/images/" + imgFile;
var btn = document.createElement("button");
btn.id = "syntax__plugin_trumpsuits_" + id;
btn.className = "toolbutton";
btn.appendChild(ico);
btn.title = tooltipText;
btn.accessKey = accKey;
eval('btn.onclick = function(){insertAtCarret("wiki__text", "' + insText + '"); return false;}');
return(btn);
}
//if this is an "edit" page, add toolbuttons
function plugin_trumpsuits_toolbar_additions() {
var toolbar = $("tool__bar");
if(!toolbar) {return;}
if(!$("edbtn__save")) {return;} //We must be able to save the page
var tbtn = plugin_trumpsuits_createToolbutton("spades", "Spades", "spades.png", "â™ ", 'S');
if (tbtn) {toolbar.appendChild(tbtn);}
tbtn = plugin_trumpsigns_createToolbutton("hearts", "Hearts", "hearts.png", "♥", 'H');
if (tbtn) {toolbar.appendChild(tbtn);}
tbtn = plugin_trumpsigns_createToolbutton("diamonds", "Diamonds", "diamonds.png", "♦", 'D');
if (tbtn) {toolbar.appendChild(tbtn);}
tbtn = plugin_trumpsigns_createToolbutton("clubs", "Clubs", "clubs.png", "♣", 'C');
if (tbtn) {toolbar.appendChild(tbtn);}
}
addInitEvent(plugin_trumpsuits_toolbar_additions);
===== Notes =====
Notes on javasript in plugins: http://wiki.splitbrain.org/wiki:devel:javascript. For debugging, first turn CSS en javascript compression off in your DokuWiki config. Then debug path/to/wiki/lib/exe/js.php. I use the Firefox javascript debugger plugin. User manual: http://devedge-temp.mozilla.org/viewsource/2002/venkman/01/index_en.html.
Browser an OS dependent CSS selectors: https://rafael.adm.br/css_browser_selector/