Minor Shortcodes Update

Last winter I released a CFML port of the WordPress Shortcodes functionality.  It's proven both very useful and very flexible in the real world, exactly as I'd hoped it would.  I tried to make a very direct port of the PHP, but after using it on a number of projects, I found myself reimplementing the same wrapper functionality, so I decided to move that into the core.

The mods are very simple, just the addition of an 'addAll' method.  Consider this code:

sc = new shortcodes.shortcodes();
sc.add("time", new shortcodes.time());
sc.add("latex", new shortcodes.latex());

It can now be expressed like this:

sc = new shortcodes.shortcodes();
  'time': new shortcodes.time(),
  'latex': new shortcodes.latex()

The really handy part, however, is that there is also a 'setShortcodes' alias for the 'addAll' method, so you can use it within setter-injection frameworks (e.g., ColdSpring).  So you can configure your shortcode engine with your DI framework of choice without needing an intermediary as you've had to use to this point:

<bean id="shortcodes" class="shortcodes.shortcodes">
  <property name="shortcodes">
      <entry key="time">
        <bean class="shortcodes.time" />
      <entry key="latex">
        <bean class="shortcodes.latex" />

As you might imagine, this allows you to use your normal DI infrastructure to configure your shortcode implementations, which is a huge boon.  The ColdSpring (and Spring) syntax for maps is a little verbose, but it's not too bad, and it lets you keep all your wiring in one place without resorting to wrapper beans or weird factory setups.

So no functional changes to the actual implementation, just easier to use.  I've also bundled 'time' and 'date' shortcode implementations to go along with the original \LaTeX implementation.  They're much more simplistic, which will hopefully do a better job of helping people get started implementing their own shortcodes (as well as providing some more utility out of the box for integrators).

As always, for full details and up-to-date info you should visit the project page, check out the online demo, or grab source from Subversion.

Comments are closed.