Module: Munge::Helper::Tag
- Defined in:
- lib/munge/helper/tag.rb
Instance Method Summary collapse
- #content_tag(name, content = nil, options = {}, &block) ⇒ Object
- #empty_tag(name, options = {}) ⇒ Object
- #h(string) ⇒ Object
Instance Method Details
#content_tag(name, content = nil, options = {}, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/munge/helper/tag.rb', line 14 def content_tag(name, content = nil, = {}, &block) if content.is_a?(Hash) = content content = nil end html_attributes = if .any? " " + .map { |k, v| %(#{k}="#{h(v)}") }.join(" ") end inner_html = if content content elsif block_given? capture(&block) end "<#{name}#{html_attributes}>#{inner_html}</#{name}>" end |
#empty_tag(name, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/munge/helper/tag.rb', line 4 def empty_tag(name, = {}) = .map { |k, v| %(#{k}="#{h(v)}") }.join(" ") if == "" "<#{name} />" else "<#{name} #{options_str} />" end end |
#h(string) ⇒ Object
35 36 37 |
# File 'lib/munge/helper/tag.rb', line 35 def h(string) CGI.escape_html(string.to_s) end |