Module: CGI::TagMaker

Defined in:
lib/laser/standard_library/cgi/html.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#nn_element_def(element) ⇒ Object

Generate code for an element with required start and end tags.

- -


11
12
13
14
15
16
17
18
19
20
# File 'lib/laser/standard_library/cgi/html.rb', line 11

def nn_element_def(element)
  nOE_element_def(element, <<-END)
      if block_given?
        yield.to_s
      else
        ""
      end +
      "</#{element.upcase}>"
  END
end

#nO_element_def(element) ⇒ Object

Generate code for an element for which the end (and possibly the start) tag is optional.

O O or - O


46
47
48
49
50
51
52
53
54
# File 'lib/laser/standard_library/cgi/html.rb', line 46

def nO_element_def(element)
  nOE_element_def(element, <<-END)
      if block_given?
        yield.to_s + "</#{element.upcase}>"
      else
        ""
      end
  END
end

#nOE_element_def(element, append = nil) ⇒ Object

Generate code for an empty element.

- O EMPTY


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/laser/standard_library/cgi/html.rb', line 25

def nOE_element_def(element, append = nil)
  s = <<-END
      attributes={attributes=>nil} if attributes.kind_of?(String)
      "<#{element.upcase}" + attributes.collect{|name, value|
        next unless value
        " " + CGI::escapeHTML(name.to_s) +
        if true == value
          ""
        else
          '="' + CGI::escapeHTML(value.to_s) + '"'
        end
      }.join + ">"
  END
  s.sub!(/\Z/, " +") << append if append
  s
end