Okay, it's remarkably lame, but here's my first TiddlyWiki plugin. It defines a new shout macro - you include <<shout some-message>> in a tiddler and it includes A SHOUTING VERSION OF THE MESSAGE.
I adapted it from the sparklines plugin. The important code is at the end - you create a macro by defining a value config.macros.helloWorld, then you simply implement config.macros.helloWorld.handler. This function receives a place variable, defining where the macro will go, and the parameters that were passed into the macro (params).
- /***
- |''Name''|ShoutPlugin|
- |''Description''|Make yourself heard - capitalises all text|
- |''Version''|1.0.0|
- |''Status''|stable|
- |''Source''|http://www.example.com/plugins.html#Shout|
- |''License''|[[BSD open source license]]|
- |''~CoreVersion''|2.4.0|
- |''Feedback''|[[TiddlyWiki community|http://groups.google.com/group/TiddlyWiki]] |
- |''Keywords''|exclamation|
- !Usage
- {{{
- <<shout message-to-be-shouted-about>>
- }}}
- Pretty simple really
- !!Examples
- {{{<<shout these tiddlers are making me thirsty!!!>>}}}
- !Code
- ***/
- //{{{
- if(!version.extensions.ShoutPlugin) {
- version.extensions.ShoutPlugin = {installed:true};
- //--
- //-- Shout
- //--
- config.macros.shout = {};
- config.macros.shout.handler = function(place,macroName,params)
- {
- var greeting = createTiddlyElement(place,"span",null,"greeting",params.join(" ").toUpperCase());
- place.appendChild(greeting);
- };
- }
- //}}}

Nice!
Just one suggestion: Instead of manually creating an element, you could use
wikify():wikify(params.join(" ").toUpperCase(), place);Also, while joining the
paramsto form a single string is not unclever, I wonder whether it wouldn’t be better to only useparams[0](thus requiring the user to enclose the text in either quotes or double brackets).FWIW, there’s a slightly updated plugin template available on the community wiki.
OpenSocial-Tiddlywiki Integration // Sep 3, 2008 at 11:19 am
[...] began with the Shout plugin whose code I’ve already documented. It was only a matter of creating an iframe and pointing it – by setting its src property – to [...]
Tiddlywiki Plugin Authoring: Detecting onload // Sep 17, 2008 at 2:17 pm
[...] Tiddlywiki plugins load on startup, early on in the whole boot sequence. I was wondering how to detect when elements are on the page and got some good advice in #tiddlywiki. [...]
Reflections from a TiddlyWiki Tiddler and Thoughts on a Guide for Web App Development with TiddlyWiki // Sep 21, 2008 at 11:41 pm
[...] – Your plugin defines a macro. Users include the macro as <<macroname>> inside a tiddler, and your macro is invoked, [...]