Module: TrustyCms::Taggable::ClassMethods

Defined in:
lib/trusty_cms/taggable.rb

Instance Method Summary collapse

Instance Method Details

#deprecated_tag(name, options = {}, &dblock) ⇒ Object

Define a tag while also deprecating it. Normal usage:

deprecated_tag 'old:way', :substitute => 'new:way', :deadline => '1.1.1'

If no substitute is given then a warning will be issued but nothing rendered. If a deadline version is provided then it will be mentioned in the deprecation warnings.

In less standard situations you can use deprecated_tag in exactly the same way as tags are normally defined:

desc %

Please note that the old r:busted namespace is no longer supported.
Refer to the documentation for more about the new r:hotness tags.

deprecated_tag ‘busted’ do |tag|

raise TagError "..."

end



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/trusty_cms/taggable.rb', line 101

def deprecated_tag(name, options={}, &dblock)
  TrustyCms::Taggable.tag_deprecations[name] = options.dup
  if dblock
    tag(name) do |tag|
      warn_of_tag_deprecation(name, options)
      dblock.call(tag)
    end
  else
    tag(name) do |tag|
      warn_of_tag_deprecation(name, options)
      tag.render(options[:substitute], tag.attr.dup, &tag.block) if options[:substitute]
    end
  end
end

#desc(text) ⇒ Object



68
69
70
71
# File 'lib/trusty_cms/taggable.rb', line 68

def desc(text)
  TrustyCms::Taggable.last_description = text
  # TrustyCms::Taggable.last_description = RedCloth.new(Util.strip_leading_whitespace(text)).to_html
end

#inherited(subclass) ⇒ Object



59
60
61
62
# File 'lib/trusty_cms/taggable.rb', line 59

def inherited(subclass)
  subclass.tag_descriptions.reverse_merge! self.tag_descriptions
  super
end

#tag(name, &block) ⇒ Object



73
74
75
76
77
# File 'lib/trusty_cms/taggable.rb', line 73

def tag(name, &block)
  self.tag_descriptions[name] = TrustyCms::Taggable.last_description if TrustyCms::Taggable.last_description
  TrustyCms::Taggable.last_description = nil
  define_method("tag:#{name}", &block)
end

#tag_descriptions(hash = nil) ⇒ Object



64
65
66
# File 'lib/trusty_cms/taggable.rb', line 64

def tag_descriptions(hash = nil)
  TrustyCms::Taggable.tag_descriptions[self.name] ||= (hash ||{})
end

#tagsObject



79
80
81
# File 'lib/trusty_cms/taggable.rb', line 79

def tags
  Util.tags_in_array(self.instance_methods)
end