Shout – First TiddlyWiki Plugin

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).

javascript

  1. /***
  2. |''Name''|ShoutPlugin|
  3. |''Description''|Make yourself heard - capitalises all text|
  4. |''Version''|1.0.0|
  5. |''Status''|stable|
  6. |''Source''|http://www.example.com/plugins.html#Shout|
  7. |''License''|[[BSD open source license]]|
  8. |''~CoreVersion''|2.4.0|
  9. |''Feedback''|[[TiddlyWiki community|http://groups.google.com/group/TiddlyWiki]] |
  10. |''Keywords''|exclamation|
  11. !Usage
  12. {{{
  13. <<shout message-to-be-shouted-about>>
  14. }}}
  15. Pretty simple really
  16. !!Examples
  17. {{{<<shout these tiddlers are making me thirsty!!!>>}}}
  18. !Code
  19. ***/
  20. //{{{
  21. if(!version.extensions.ShoutPlugin) {
  22. version.extensions.ShoutPlugin = {installed:true};
  23.  
  24. //--
  25. //-- Shout
  26. //--
  27.  
  28. config.macros.shout = {};
  29. config.macros.shout.handler = function(place,macroName,params)
  30. {
  31.  var greeting = createTiddlyElement(place,"span",null,"greeting",params.join(" ").toUpperCase());
  32.   place.appendChild(greeting);
  33. };
  34.  
  35.  
  36. }
  37. //}}}

4 thoughts on Shout – First TiddlyWiki Plugin

  1. Nice!

    Just one suggestion: Instead of manually creating an element, you could use wikify():

    wikify(params.join(" ").toUpperCase(), place);
    

    Also, while joining the params to form a single string is not unclever, I wonder whether it wouldn’t be better to only use params[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.

  2. Pingback: OpenSocial-Tiddlywiki Integration

  3. Pingback: Tiddlywiki Plugin Authoring: Detecting onload

  4. Pingback: Reflections from a TiddlyWiki Tiddler and Thoughts on a Guide for Web App Development with TiddlyWiki

Leave a Reply