1 module Radiant::Taggable
2 mattr_accessor :last_description, :tag_descriptions
3 @@tag_descriptions = {}
5 def self.included(base)
6 base.extend(ClassMethods)
8 def self.included(new_base)
10 new_base.tag_descriptions.merge! self.tag_descriptions
15 def render_tag(name, tag_binding)
16 send "tag:#{name}", tag_binding
20 Util.tags_in_array(methods)
23 def tag_descriptions(hash=nil)
24 self.class.tag_descriptions hash
28 def inherited(subclass)
29 subclass.tag_descriptions.reverse_merge! self.tag_descriptions
33 def tag_descriptions(hash = nil)
34 Radiant::Taggable.tag_descriptions[self.name] ||= (hash ||{})
38 Radiant::Taggable.last_description = RedCloth.new(Util.strip_leading_whitespace(text)).to_html
42 self.tag_descriptions[name] = Radiant::Taggable.last_description if Radiant::Taggable.last_description
43 Radiant::Taggable.last_description = nil
44 define_method("tag:#{name}", &block)
48 Util.tags_in_array(self.instance_methods)
54 def self.tags_in_array(array)
55 array.grep(/^tag:/).map { |name| name[4..-1] }.sort
58 def self.strip_leading_whitespace(text)
61 lines = text.split("\n")
62 leading = lines.map do |line|
63 unless line =~ /^\s*$/
64 line.match(/^(\s*)/)[0].length
69 lines.inject([]) {|ary, line| ary << line.sub(/^[ ]{#{leading}}/, "")}.join("\n")