Module: Munge::Helpers::Tag

Defined in:
lib/munge/helpers/tag.rb

Instance Method Summary collapse

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 (name, content = nil, options = {}, &block)
  if content.is_a?(Hash)
    options = content
    content = nil
  end

  options_str = options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")

  content_str =
    if content
      content
    elsif block_given?
      capture(&block)
    else
      ""
    end

  "<#{name} #{options_str}>#{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, options = {})
  options_str = options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")

  if options_str == ""
    "<#{name} />"
  else
    "<#{name} #{options_str} />"
  end
end

#h(string) ⇒ Object



34
35
36
# File 'lib/munge/helpers/tag.rb', line 34

def h(string)
  CGI.escape_html(string)
end