Module: Cyberweb::CGI::TagMaker

Defined in:
lib/cyberweb/cgi/tag_maker.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

#

nn_element

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

#


24
25
26
27
28
29
30
# File 'lib/cyberweb/cgi/tag_maker.rb', line 24

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

#

nn_element_def

#


35
36
37
# File 'lib/cyberweb/cgi/tag_maker.rb', line 35

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

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

#

nO_element

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

O O or - O
#


76
77
78
79
80
81
82
83
84
85
# File 'lib/cyberweb/cgi/tag_maker.rb', line 76

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

#

nO_element_def

#


90
91
92
# File 'lib/cyberweb/cgi/tag_maker.rb', line 90

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
#


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cyberweb/cgi/tag_maker.rb', line 44

def nOE_element(element, attributes = {})
  attributes = { attributes => nil } if attributes.is_a? 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

#

nOE_element_def

#


63
64
65
# File 'lib/cyberweb/cgi/tag_maker.rb', line 63

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