[typo] New style Sidebar API

Kyle Heon kheon at comcast.net
Wed Apr 19 20:40:48 EDT 2006


This is cool. Seeing as how I'm struggling through creating my first
sidebar, any chance someone more in the know can update
components\sidebars\README with updated details on how to create a sidebar?

Kyle Heon
kheon at comcast.net
www.kyleheon.com


-----Original Message-----
From: typo-list-bounces at rubyforge.org
[mailto:typo-list-bounces at rubyforge.org] On Behalf Of Piers Cawley
Sent: Sunday, April 16, 2006 2:38 PM
To: typo-list at rubyforge.org
Subject: [typo] New style Sidebar API

Right, I've just made my last big batch of changes in the sidebar subsystem
for a while (modulo any bug fixes that crop up as a result of this) and
thought I'd better give you the heads up on them.

First of all, and I can't stress this enough, if your sidebar's
configure.rhtml looks anything like this:

<%= form_tag ... %>
 <!-- Buncha inputs and labels -->
<%= end_form_tag %>

<%= observe_form ... %>

then you MUST at least get rid of the form_tag and observe_form parts of it.
Nested forms break browsers.

Ahem.

You might prefer to get rid of your configure.rhtml altogether though.

Here's archives_controller.rb before the API changes

  class Plugins::Sidebars::ArchivesController < Sidebars::ComponentPlugin
    def self.display_name
      "Archives"
    end

    def self.description
      'Displays links to monthly archives'
    end

    def self.default_config
      {'count' => 10, 'show_count' => true}
    end

    def content
      ...
    end

    def configure
    end
  end

And here it is after:

  class Plugins::Sidebars::ArchivesController < Sidebars::ComponentPlugin
    display_name 'Archives'
    description 'Displays links to monthly archives'
    
    setting :show_count => true, :label => 'Show article counts', 
            :input_type => :checkbox
    setting :count, 10, :label => 'Number of Months'

    def content
      ...
    end
  end

Actually, I lied, it doesn't have a 'display_name' declaration because
Sidebars::ComponentPlugin does a much better job of working out the default
display name.

And here's its configure.rhtml after the changes:

   <!-- this space intentionally left blank -->

That's right, it doesn't actually have one because the setting declarations
give enough information for us to build the configuration div automatically.
There's a few wrinkles if you need a text area, group of radio buttons or a
'select' menu, but there are good examples of all of those to be found in
'xml_controller.rb', 'flickr_controller.rb' and 'static_controller.rb'.

Sidebars still aren't being tested, but I think it might be *possible* to
test them now. I'm also planning on writing a sidebar generator to make the
sidebar author's life even easier, but that's probably way over on the
'sometime' milestone.

--
Piers Cawley <pdcawley at bofh.org.uk>
http://www.bofh.org.uk/
_______________________________________________
Typo-list mailing list
Typo-list at rubyforge.org
http://rubyforge.org/mailman/listinfo/typo-list



More information about the Typo-list mailing list