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



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

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



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

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



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

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

#tag(name, &block) ⇒ Object



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

def tag(name, &block)
  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



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

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

#tagsObject



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

def tags
  Util.tags_in_array(instance_methods)
end