Class: Input::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/input.rb

Direct Known Subclasses

Input

Constant Summary collapse

SELF_CLOSING =

Which tags are self closing (such tags ignore children).

[:img, :input]
ESCAPE_HTML =

Borrowed from Rack::Utils, map of single character strings to html escaped versions.

{"&" => "&amp;", "<" => "&lt;", ">" => "&gt;", "'" => "&#39;", '"' => "&quot;"}
ESCAPE_HTML_PATTERN =

A regexp that matches all html characters requiring escaping.

Regexp.union(*ESCAPE_HTML.keys)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, type, attributes = {}) ⇒ Tag

Create a new tag.



98
99
100
101
102
# File 'lib/input.rb', line 98

def initialize(form, type, attributes={})
  @form = form
  @type = type
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



83
84
85
# File 'lib/input.rb', line 83

def attributes
  @attributes
end

#formObject

Returns the value of attribute form.



81
82
83
# File 'lib/input.rb', line 81

def form
  @form
end

#typeObject

Returns the value of attribute type.



82
83
84
# File 'lib/input.rb', line 82

def type
  @type
end

Instance Method Details

#closeObject

Return opening half of tag, or nothing tag if self closing



120
121
122
123
124
125
126
# File 'lib/input.rb', line 120

def close
  if SELF_CLOSING.include?(type)
    ""
  else
    "</#{type}>"
  end
end

#openObject

Return opening half of tag, or entire tag if self closing



108
109
110
111
112
113
114
# File 'lib/input.rb', line 108

def open
  if SELF_CLOSING.include?(@type)
    "<#{@type}#{attr_html(attributes)}/>"
  else
    "<#{@type}#{attr_html(attributes)}>"
  end
end