Class: Navigator::Tag
- Inherits:
-
Object
- Object
- Navigator::Tag
- Defined in:
- lib/navigator/tag.rb
Overview
Renders a HTML tag.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #computed_content ⇒ Object
-
#initialize(name, content = nil, attributes: {}, activator: Navigator::TagActivator.new) ⇒ Tag
constructor
A new instance of Tag.
- #prefix ⇒ Object
- #render ⇒ Object
- #suffix ⇒ Object
Constructor Details
#initialize(name, content = nil, attributes: {}, activator: Navigator::TagActivator.new) ⇒ Tag
Returns a new instance of Tag.
12 13 14 15 16 17 |
# File 'lib/navigator/tag.rb', line 12 def initialize name, content = nil, attributes: {}, activator: Navigator::TagActivator.new @name = String(name) @content = content @attributes = attributes.with_indifferent_access @activator = activator end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/navigator/tag.rb', line 6 def content @content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/navigator/tag.rb', line 6 def name @name end |
Class Method Details
.names_without_suffix ⇒ Object
8 9 10 |
# File 'lib/navigator/tag.rb', line 8 def self.names_without_suffix %w[img input] end |
Instance Method Details
#computed_content ⇒ Object
23 24 25 |
# File 'lib/navigator/tag.rb', line 23 def computed_content self.class.names_without_suffix.include?(name) ? nil : content end |
#prefix ⇒ Object
19 20 21 |
# File 'lib/navigator/tag.rb', line 19 def prefix ["<#{name}", format_attributes, ">"].compact * "" end |
#render ⇒ Object
31 32 33 |
# File 'lib/navigator/tag.rb', line 31 def render [prefix, computed_content, suffix].compact * "" end |
#suffix ⇒ Object
27 28 29 |
# File 'lib/navigator/tag.rb', line 27 def suffix self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" end |