Method: AnyView::Helpers::TagHelpers#tag

Defined in:
lib/any_view/tag_helpers.rb

#tag(name, options = {}) ⇒ Object

Creates an html tag with the given name and options

Examples:

tag(:br, :style => 'clear:both')
tag(:p, :content => "hello", :class => 'large')

Returns:

  • a string



31
32
33
34
35
36
37
# File 'lib/any_view/tag_helpers.rb', line 31

def tag(name, options={})
  content, open_tag = options.delete(:content), options.delete(:open)
  identity_tag_attributes.each { |attr| options[attr] = attr.to_s if options[attr]  }
  html_attrs = options.collect { |a, v| v.blank? ? nil : "#{a}=\"#{v}\"" }.compact.join(" ")
  base_tag = (!html_attrs.blank? ? "<#{name} #{html_attrs}" : "<#{name}")
  base_tag << (open_tag ? ">" : (content ? ">#{content}</#{name}>" : " />"))
end