How to create your own typo macro filters

rubyredrick edited this page Sep 13, 2010 · 2 revisions

In this tutorial, you’ll learn how to create a nice “hello world” Typo textfilter plugin. It will just make a Javascript pop up appear at load time saying “Hello world”.

First, create a plugin using Rails default plugin generator

$ ./script/generate plugin typo_textfilter_helloworld

Load your plugin in your favourite text editor, and start with init.rb. You’ll need to load the Typo Textfilter Plugin API and your Helloworld class

require 'text_filter_plugin'
require 'typo_textfilter_helloworld'

Now, edit your lib/typo_textfilter_helloworld.rb, this is where the big thing start

First, declare your Helloworld class :

class Typo
  class Textfilter
    class Helloworld < TextFilterPlugin::MacroPost
      plugin_display_name "Hello world"
      plugin_description "Adds a hello world pop up"

Now, add the method with the help text for your macro

def self.help_text
You can use `<typo:helloworld>` to have a stupid javascript pop up saying "hello world" }

Now, create your macro filter which does all the work:

def self.macrofilter(blog,content,attrib,params,text="")
  %{<script type="text/javascript">alert('hello world');</script>}

Close the unclosed classes and methods


In your code, you can call your hello world macro filter :

<typo:helloworld />