class ContentTagHelper::Tag
Attributes
css[R]
id[RW]
name[R]
Public Class Methods
new(name, *args)
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 23 def initialize(name, *args) @name = name @attributes = tag_options(*args) @attributes[:class] = Tag::CSS.new(@attributes.fetch(:class, {})) end
Public Instance Methods
[](k)
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 44 def [](k) @attributes[k] end
[]=(k,v)
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 48 def []=(k,v) @attributes[k] = v end
render(content)
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 52 def render(content) "<#{name}#{render_attributes}>#{content.to_s.strip}</#{name}>".html_safe end
render_attributes()
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 56 def render_attributes attrs = @attributes.dup if css.empty? attrs.delete :class else attrs[:class] = css.to_s end attrs.keys.map do |k| "#{k}='#{attrs[k]}'" end.join(' ').prepend(' ').html_safe end
tag_options(*args)
click to toggle source
# File lib/ecrire/app/helpers/content_tag_helper.rb, line 29 def tag_options(*args) options = nil args.each do |a| if a.is_a?(Hash) options = a break end end (options || {}).with_indifferent_access end