public
Description: a lightweight, feature-rich blogging platform
Home | Edit | New

DevelopingPlugins

Plugins

Imagine being able to write a blog plugin with proper object-orientation! :-) Plugins have an extremely simple syntax that you can pick up just from reading a sample.

  require 'canticore/plugin'
 
  Canticore::Plugin::Create 'theme-changer' do
    enhances :index
    variable :before_text, 
      { :summary => "Dropdown Prefix Text", :desc => "Text to display before the drop-down.", :default => "Change Theme: " }
 
    def output
      haml :output
    end
 
    hook :body, :output
 
  end

The #enhances block tells the blog what pages the plugin should be enabled on: :index just means it will be enabled on the landing page, and not archive pages, individual post pages, static pages, et cetera. You can also use enhances :all for a blanket enabling.

Each variable you want the user to change and be able to save to the database begins with a #variable function. Give it a name and a list of options.

Hooks are where you attach your functionality to Canticore. Right now there’s only a few, :body being one of them. The line hook :body, :output tells Canticore to attach the output of the function called :output to the body hook. You can use HAML for your plugins. In this case the function output looks for a file called views/output.haml in your plugin gem to render.

Filters are coming, as are multiple choice variables (drop-down).

Last edited by ardekantur, Sun Dec 21 13:51:51 -0800 2008
Home | Edit | New
Versions: