Forum: Radiant CMS Where to put helper methods for tags?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e3098fc25a84135db32e68f4176b19f?d=identicon&s=25 Kaleb Walton (Guest)
on 2007-01-28 22:23
(Received via mailing list)
Where is an appropriate place to put helper methods for tags to
support the DRY principle?
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2007-01-29 00:33
(Received via mailing list)
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.
9e3098fc25a84135db32e68f4176b19f?d=identicon&s=25 Kaleb Walton (Guest)
on 2007-01-29 01:29
(Received via mailing list)
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
This topic is locked and can not be replied to.