Module: CGI::TagMaker

Included in:
Html3, Html4, Html4Fr, Html4Tr, Html5
Defined in:
lib/cgi/html.rb

Overview

Base module for HTML-generation mixins.

Provides methods for code generation for tags following the various DTD element types.

Instance Method Summary collapse

Instance Method Details

#nn_element(element, attributes = {}) ⇒ Object

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

- -


11
12
13
14
15
16
17
# File 'lib/cgi/html.rb', line 11

def nn_element(element, attributes = {})
  s = nOE_element(element, attributes)
  if block_given?
    s << yield.to_s
  end
  s << "</#{element.upcase}>"
end

#nn_element_def(attributes = {}, &block) ⇒ Object



19
20
21
# File 'lib/cgi/html.rb', line 19

def nn_element_def(attributes = {}, &block)
  nn_element(__callee__, attributes, &block)
end

#nO_element(element, attributes = {}) ⇒ Object

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

O O or - O


51
52
53
54
55
56
57
58
# File 'lib/cgi/html.rb', line 51

def nO_element(element, attributes = {})
  s = nOE_element(element, attributes)
  if block_given?
    s << yield.to_s
    s << "</#{element.upcase}>"
  end
  s
end

#nO_element_def(attributes = {}, &block) ⇒ Object



60
61
62
# File 'lib/cgi/html.rb', line 60

def nO_element_def(attributes = {}, &block)
  nO_element(__callee__, attributes, &block)
end

#nOE_element(element, attributes = {}) ⇒ Object

Generate code for an empty element.

- O EMPTY


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

def nOE_element(element, attributes = {})
  attributes={attributes=>nil} if attributes.kind_of?(String)
  s = "<#{element.upcase}"
  attributes.each do|name, value|
    next unless value
    s << " "
    s << CGI::escapeHTML(name.to_s)
    if value != true
      s << '="'
      s << CGI::escapeHTML(value.to_s)
      s << '"'
    end
  end
  s << ">"
end

#nOE_element_def(attributes = {}, &block) ⇒ Object



42
43
44
# File 'lib/cgi/html.rb', line 42

def nOE_element_def(attributes = {}, &block)
  nOE_element(__callee__, attributes, &block)
end