Class: Garterbelt::ClosedTag
- Defined in:
- lib/renderers/closed_tag.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Renderer
Instance Method Summary collapse
- #c(*args) ⇒ Object
-
#id(identifier) ⇒ Object
Convenience method chaining —————————.
-
#initialize(opts) ⇒ ClosedTag
constructor
A new instance of ClosedTag.
- #render ⇒ Object
-
#rendered_attributes ⇒ Object
Rendering ———————————————–.
- #template ⇒ Object
Methods inherited from Renderer
#indent, #level, #line_end, #output, #output=
Constructor Details
#initialize(opts) ⇒ ClosedTag
Returns a new instance of ClosedTag.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/renderers/closed_tag.rb', line 5 def initialize(opts) super self.type = opts[:type] || raise(ArgumentError, ":type required in initialization options") self.attributes = opts[:attributes] || {} css_class = attributes.delete(:class) self.css_class = if css_class css_class.is_a?(Array) ? css_class : [css_class] else [] end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/renderers/closed_tag.rb', line 3 def attributes @attributes end |
#css_class ⇒ Object
Returns the value of attribute css_class.
3 4 5 |
# File 'lib/renderers/closed_tag.rb', line 3 def css_class @css_class end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/renderers/closed_tag.rb', line 3 def type @type end |
Instance Method Details
#c(*args) ⇒ Object
26 27 28 29 |
# File 'lib/renderers/closed_tag.rb', line 26 def c(*args) self.css_class += args self end |
#id(identifier) ⇒ Object
Convenience method chaining —————————
20 21 22 23 24 |
# File 'lib/renderers/closed_tag.rb', line 20 def id(identifier) raise ArgumentError, "Id must be a String or Symbol" unless [String, Symbol].include?(identifier.class) self.attributes[:id] = identifier self end |
#render ⇒ Object
55 56 57 58 59 |
# File 'lib/renderers/closed_tag.rb', line 55 def render str = template self.output << str str end |
#rendered_attributes ⇒ Object
Rendering ———————————————–
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/renderers/closed_tag.rb', line 33 def rendered_attributes str = "" str << " class=\"#{css_class.join(' ')}\"" unless css_class.empty? keys = attributes.keys.sort{|a, b| a.to_s <=> b.to_s} keys.each do |key| value = attributes[key] if value value = value.to_s.gsub('"', '\'') str << " #{key}=\"#{value}\"" end end str end |
#template ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/renderers/closed_tag.rb', line 47 def template if style == :text type == :br ? "\n" : "" else "#{indent}<#{type}#{rendered_attributes}>#{line_end}" end end |