Dit is een oude revisie van het document!
Inhoud
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 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 thus far, 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).
Versions
- 2010-09-03
- Fixed javascript that was broken in DokuWiki version 2009-12-25, “Lemming”.
- 2009-11-05
- Initial version
Installation
Plugin manager
Point your plug-in manager at http://home.vdmeulen.net/bridge/trumpsuits.tgz or http://home.vdmeulen.net/bridge/trumpsuits.zip.
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.
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.
<?php /** * Plugin Trumpsuits: controls display of trump suit card symbols with CSS style attributes * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Pieter van der Meulen <pieter@vdmeulen.net> */ if(!defined('DOKU_INC')) die(); 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 { public static $SPADES='♠'; public static $HEARTS='♥'; public static $DIAMONDS='♦'; public static $CLUBS='♣'; /** * return some info */ function getInfo() { return array( 'author' => 'Pieter van der Meulen', 'email' => 'pieter@vdmeulen.net', 'date' => '2010-09-03', 'name' => 'trumpsuits', 'desc' => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black (configurable).', '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; } /** * Set "normal" inline substitution */ function getPType() { return 'normal'; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern($this->nt_symbol_regex(), $mode, 'plugin_trumpsuits'); $this->Lexer->addSpecialPattern(self::$CLUBS, $mode,'plugin_trumpsuits'); $this->Lexer->addSpecialPattern(self::$DIAMONDS,$mode,'plugin_trumpsuits'); $this->Lexer->addSpecialPattern(self::$HEARTS,$mode,'plugin_trumpsuits'); $this->Lexer->addSpecialPattern(self::$SPADES,$mode,'plugin_trumpsuits'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler) { $repl = $match; switch ($match) { case self::$CLUBS: $repl = $this->render_style($match, $this->getConf('clubs_css')); break; case self::$DIAMONDS: $repl = $this->render_style($match, $this->getConf('diamonds_css')); break; case self::$HEARTS: $repl = $this->render_style($match, $this->getConf('hearts_css')); break; case self::$SPADES: $repl = $this->render_style($match, $this->getConf('spades_css')); break; default: $regex = '/'.$this->nt_symbol_regex().'/'; if (preg_match($regex, $match)==1) { $repl = substr($match, 0, 1); $repl .= $this->render_style($this->getConf('notrump_symbol'), $this->getConf('notrump_css')); $repl .= substr($match, -1, 1); } else { $repl = $match; } } return array($match, $repl); } /** * Create output. On non-xhtml formasts leave symbols unaffected * * @param <type> $format * @param <type> $renderer * @param <type> $data * @return <type> */ function render($format, &$renderer, $data) { if($format == 'xhtml') { $renderer->doc .= $data[1]; } else { $renderer->doc .= $data[0]; } return true; } function render_style($s, $style) { return '<span style="'.$style.'">'.$s.'</span>'; } function nt_symbol_regex() { return '[^A-Za-z]'.$this->getConf('notrump_symbol').'[^\w]'; } } ?>
script.js
if(window.toolbar!=undefined){ var icobase = DOKU_BASE + "lib/plugins/trumpsuits/images/"; toolbar[toolbar.length] = { "type": "insert", "title": "Spades", "icon": "spades.png", "insert": "♠", "icobase": icobase}; toolbar[toolbar.length] = { "type": "insert", "title": "Hearts", "icon": "hearts.png", "insert": "♥", "icobase": icobase}; toolbar[toolbar.length] = { "type": "insert", "title": "Diamonds", "icon": "diamonds.png", "insert": "♦", "icobase": icobase}; toolbar[toolbar.length] = { "type": "insert", "title": "Clubs", "icon": "clubs.png", "insert": "♣", "icobase": icobase}; }
Wishlist
- Configuration options for trump suit symbol replacement
- Language options. Can one use language conf in javascript?




