My First Typo Sidebar

2006-11-12, , Comments

I recently developed my very own plugin for this blog. To cut a short story even shorter, I wrote a Ruby class and an HTML template, and I was done.

The Plugin

Whilst wandering around the Google gadgets pages, I’d spotted Adam Bowman’s animated Treefrog. It appealed. I wanted one on my blog.

What did I have to do? The content required nothing complicated, nothing dynamic: just a static chunk of HTML. How difficult could it be?

Read the code, Not the manual

I’ve fiddled round with Typo before and found reading the code to be the best way to figure out what to do. In this case, I needed to look at an existing sidebar plugin. I guessed the best model for my new plugin would be the “Static” sidebar component which I use to list a collection of links to favourite web sites.

I soon found the controller for this plugin in the components/plugins/sidebars/ subdirectory of my Typo installation. It’s a simple Ruby class derived from Sidebars::ComponentPlugin:

components/plugins/sidebars/static_controller.rb
class Plugins::Sidebars::StaticController < Sidebars::ComponentPlugin
  description "Static content, like links to other sites, advertisements, or blog meta-infomation"

  DEFAULT_TEXT = %q{
<ul>
  <li><a href="http://www.typosphere.org" title="Typo">Typo</a></li>
  ....
</ul>
}

  setting :title, 'Links'
  setting :body, DEFAULT_TEXT, :input_type => :text_area

end

I also spotted a components/plugins/sidebars/static subdirectory, and in this subdirectory was a two-line HTML template.

components/plugins/sidebars/static/content.html
<h3><%= @sb_config['title'] %></h3>
<%= @sb_config['body'] %>

My Plugin

My plugin was even more simple than the static one. I created a class:

components/plugins/sidebars/treefrog_controller.rb
class Plugins::Sidebars::TreefrogController < Sidebars::ComponentPlugin
  description 'Treefrog'
  setting :title, 'Treefrog'
end

and an HTML template:

components/plugins/sidebars/treefrog/content.rhtml
<h3><%= @sb_config['title'] %></h3>
<object
type="application/x-shockwave-flash"
data="files/treefrog.swf"
width="150" height="200">
<param name="movie" value="files/treefrog.swf" />
</object>

and I was done. As before, I ran a local Typo session to check my plugin worked, then I copied the files over to my live site. Job done.

So What?

So what’s so amazing about this? Absolutely nothing. This is hardly rocket science.

Notice, though, that:

  1. I didn’t have to restart my blog server

  2. I didn’t have to change any existing part of my blog application — the changes were purely additive.

  3. I didn’t reconfigure anything. I didn’t have to register my plugin. I didn’t have to tell my class where to find the HTML template. I didn’t have to write or generate loads of XML.

No, this isn’t amazing. So why do so many other application development frameworks get it so very wrong?

Feedback