Software As She’s Developed

Mahemoff’s Podcast/Blog - Web, Programming, Usabilty from the Author of ‘Ajax Design Patterns’ (AjaxPatterns.org)

Software As She’s Developed header image 2

Shout - First TiddlyWiki Plugin

August 5th, 2008 · 4 Comments

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. //}}}


Categories: SoftwareDev

Tags:

4 responses so far ↓

  • 1 FND // Aug 8, 2008 at 1:42 pm

    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 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 […]

  • 3 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. […]

  • 4 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, […]

Leave a Comment