Where is an appropriate place to put helper methods for tags to support the DRY principle?
on 2007-01-28 23:23
on 2007-01-29 01:33
Tags are instance_eval'd on the page, so depending on how your page hierachy either put them as a method on a superclass or put them in a module which is included in each of the pages.
on 2007-01-29 02:29
Thanks for that explanation! I ended up creating a MyTags module that included tag definitions as well as helper methods. For those who may have the same question I did something like this: In extensions/my_tags/lib/my_tags.rb: module MyTags include Radiant::Taggable def helper_hello "hello" end tag 'hello' do |tag| helper_hello end end In extensions/my_tags/my_tags_extension.rb: class MyTagsExtension < Radiant::Extension version "1.0" description "Adds my tags to the global tag library" url "http://my_tags.com" def activate Page.send :include, MyTags end end As you can see my helper method 'helper_hello' is available from within my tags. The above technique used to include tags in the global scope was suggested a few months back in this mailing list and I found it works out quite nicely. Regards, Kaleb