module AutoHtml::TagHelper
XHTML tags builder
Public Instance Methods
tag(tag_name, attrs = {}) { || ... }
click to toggle source
# File lib/auto_html/tag_helper.rb, line 6 def tag(tag_name, attrs = {}) if block_given? content_tag(tag_name, yield, attrs) else unary_tag(tag_name, attrs) end end
Private Instance Methods
content_tag(tag_name, value, attrs = {})
click to toggle source
# File lib/auto_html/tag_helper.rb, line 20 def content_tag(tag_name, value, attrs = {}) start_tag = "<#{tag_and_attributes(tag_name, tag_attributes(attrs))}>" end_tag = "</#{tag_name}>" [start_tag, value, end_tag].join end
tag_and_attributes(tag_name, attributes)
click to toggle source
# File lib/auto_html/tag_helper.rb, line 26 def tag_and_attributes(tag_name, attributes) attributes.empty? ? tag_name : "#{tag_name} #{attributes}" end
tag_attributes(hash)
click to toggle source
# File lib/auto_html/tag_helper.rb, line 30 def tag_attributes(hash) hash.compact .to_a .map { |k, v| %(#{k}="#{v}") }.join(' ') end
unary_tag(tag_name, attrs = {})
click to toggle source
# File lib/auto_html/tag_helper.rb, line 16 def unary_tag(tag_name, attrs = {}) "<#{tag_and_attributes(tag_name, tag_attributes(attrs))} />" end