How to make a Mephisto Plugin

Posted by hank, Mon Feb 26 00:29:00 UTC 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.

Tags:

Comments

  • no avatar available for Nicole Nicole
    February 27, 2007 @ 10:17 PM

    thanks. keep up the good work!

  • photo of Pablo Pablo
    May 29, 2007 @ 08:32 PM

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

  • photo of Hank Hank
    May 29, 2007 @ 08:39 PM

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

    
    {% for tag in site.tags %}
      {{ tag | size_tag }}
    {% endfor %}
    

    That’s all that’s needed.

  • photo of Rutger Rutger
    February 28, 2008 @ 09:18 PM

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

Have your say

A name is required. You may use Markdown in your comments.