Module: CGI::TagMaker
Overview
Base module for HTML-generation mixins.
Provides methods for code generation for tags following the various DTD element types.
Instance Method Summary collapse
-
#nn_element(element, attributes = {}) ⇒ Object
Generate code for an element with required start and end tags.
- #nn_element_def(attributes = {}, &block) ⇒ Object
-
#nO_element(element, attributes = {}) ⇒ Object
Generate code for an element for which the end (and possibly the start) tag is optional.
- #nO_element_def(attributes = {}, &block) ⇒ Object
-
#nOE_element(element, attributes = {}) ⇒ Object
Generate code for an empty element.
- #nOE_element_def(attributes = {}, &block) ⇒ Object
Instance Method Details
#nn_element(element, attributes = {}) ⇒ Object
Generate code for an element with required start and end tags.
- -
12 13 14 15 16 17 18 |
# File 'lib/cgi/html.rb', line 12 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
20 21 22 |
# File 'lib/cgi/html.rb', line 20 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
52 53 54 55 56 57 58 59 |
# File 'lib/cgi/html.rb', line 52 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
61 62 63 |
# File 'lib/cgi/html.rb', line 61 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cgi/html.rb', line 27 def nOE_element(element, attributes = {}) attributes={attributes=>nil} if attributes.kind_of?(String) s = "<#{element.upcase}".dup 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
43 44 45 |
# File 'lib/cgi/html.rb', line 43 def nOE_element_def(attributes = {}, &block) nOE_element(__callee__, attributes, &block) end |