How to make a Mephisto Plugin

So, I figured I might as well provide a quick tutorial on how to make Mephisto Plugins currently. Many of the old plugins are broken, so there needs to be a resurgence of plugin development. Here’s the basic structure of the Tag Cloud plugin:


mephisto_tag_cloud
 - init.rb README
 - lib
   - mephisto_plugins
     - tag_cloud.rb

As you can see, the structure is very simple. Here’s my code for init.rb


Liquid::Template.register_filter(MephistoPlugins::TagCloud)

That’s it! No require or anything! Next, I edited lib/mephisto_plugins/tag_cloud.rb:


module MephistoPlugins
  module TagCloud
    def size_tag(tag, largest = 2)
      size = (Tag.find_by_name(tag).taggings(true).length + 18).to_f / 18
      size = largest if size > largest
      "<span style='font-size: #{size}em'><a href='/tags/#{tag}'>#{tag}</a></span>"
    end
  end
end

Holy crap that barely any code at all! So, the moral of the story is that it’s very easy to make the plugins once you figure out what to do.



Comments

  1. Nicole

    February 26, 2007 at 12:29 AM

    thanks.
    keep up the good work!


  2. Pablo

    February 26, 2007 at 12:29 AM

    Hi! Excelent Post!
    Just a question, how do you embed the plugin in a page? Can it be embeded in an article?
    Thanks.


  3. Hank

    February 26, 2007 at 12:29 AM

    For this one, I just put this in my layout:

    <filter:code>
    {% for tag in site.tags %}
    {{ tag | size_tag }}
    {% endfor %}
    </filter:code>

    That’s all that’s needed.


  4. Rutger

    February 26, 2007 at 12:29 AM

    Isn’t this a filter instead of a plugin? Or am i wrong?