Module: Munge::Helpers::Tag
- Defined in:
- lib/munge/helpers/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 |
# File 'lib/munge/helpers/tag.rb', line 14 def content_tag(name, content = nil, = {}, &block) if content.is_a?(Hash) = content content = nil end = .map { |k, v| %(#{k}="#{h(v)}") }.join(" ") content_str = if content content elsif block_given? capture(&block) else "" end "<#{name} #{}>#{content_str}</#{name}>" end |
#empty_tag(name, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/munge/helpers/tag.rb', line 4 def empty_tag(name, = {}) = .map { |k, v| %(#{k}="#{h(v)}") }.join(" ") if == "" "<#{name} />" else "<#{name} #{} />" end end |
#h(string) ⇒ Object
34 35 36 |
# File 'lib/munge/helpers/tag.rb', line 34 def h(string) CGI.escape_html(string) end |