Tags:
create new tag
, view all tags

MacroPluginDev

UPDATED This plugin has been merged with the new and improved AliasPlugin And I suggest using that rather than this hack smile -- TravisBarker - 27 Apr 2005

Explanation

who, what, why, where, when, and why again?
Nobody seemed interested in implementing the idea I came up with on AliasPluginDev so I finally just did it myself.

the MacroPlugin is a simple hack of the AliasPlugin that changes the way the "alias" is rendered. Instead of rendering the same term that is typed into the page, but as a link to the "aliased topic" as the AliasPlugin does, the MacroPlugin actually replaces the term itself with the alias. ( which may or may not be a link to another topic) by this method the plugin becomes somewhat more flexible because the alias can be any arbitrary string.

Example:

a picture is worth a thousand words
the term the macro
foo bar

The macro table above causes "foo" (as typed) to expand and become "bar" in normal topic view. "bar" can be a string.

Current Limitations

sofar it only replaces a single word with a single word, I would like suggestions on how to make it replace a single word with a string. UPDATED the problem was solved changing line 59 of MacroPlugin.pm to the following:

WikiWord && $line =~ /\|\s*(?:\<nop\>)?(\w+)\s*\|\s*(?:\<nop\>)?(\S*[^|]*)\s*\|/) ||
so MacroPlugin now allows strings to replace words

Thinkinking a bit further on this line it would be just as easy to allow MacroPlugin to replace arbitrary strings with strings. this way you could match a phrase and change it to a different word or phrase of arbitrary length.

Name Change Suggestions

keeping wiki words clean
Since this plugin is so similar to AliasPlugin, I think we might consider merging the two. By giving the user the option of "what kind of alias/macro do you want?" the plugin becomes more powerful and functional.

I would also like to hear new names suggested for this plugin because we already have a MacrosPlugin and i think it might be confusing to have both a MacroPlugin & a MacrosPlugin, I dunno, what do you think about it?

Further Development

a word of caution
I have put off creating the MacroPlugin topic until we can discuss its future a bit further (and tested the code I hacked out of AliasPlugin 8) ).

Advantages

Because there is an up side to everything...
  • censorship and moderation in forum applications
  • nicknames or abv. turn into Full names (or the other way around)
  • it is simpler than MacrosPlugin (and easier to use) and more flexible than AliasPlugin.

Disadvantages

Because there is a down side to everything too...
  • unexpected expansion of macros in normal topic view if used carelessly
  • can break html and other code if macro occurs within html tags.


-- TravisBarker - 20 Mar 2005

working example MacroPlugin.pm and MacroPlugin.txt are attached below but have only been briefly tested at this point. You can visit ThetaBase:TWiki.MacroPlugin for a working demo.

Topic attachments
I Attachment Action Size Date Who Comment
Perl source code filepm MacroPlugin.pm manage 3.8 K 2005-03-20 - 22:43 TravisBarker Replacement value can be a string
Texttxt MacroPlugin.txt manage 3.0 K 2005-03-20 - 22:47 TravisBarker Includes test for String
Topic revision: r5 - 2005-04-27 - TravisBarker
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by PerlIdeas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.