Home > How to make a Mephisto Plugin

How to make a Mephisto Plugin

February 26th, 2007

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.


, , , , ,

  1. February 26th, 2007 at 00:29 | #1

    thanks.
    keep up the good work!

  2. February 26th, 2007 at 00:29 | #2

    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 26th, 2007 at 00:29 | #3

    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 26th, 2007 at 00:29 | #4

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

  1. No trackbacks yet.
Comments are closed.