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
rubocop:disable Metrics/ParameterLists.
-
#prefix ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #render ⇒ Object
- #suffix ⇒ Object
Constructor Details
#initialize(name, content = nil, attributes: {}, activator: Navigator::TagActivator.new) ⇒ Tag
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 |
# File 'lib/navigator/tag.rb', line 11 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 |
# File 'lib/navigator/tag.rb', line 8 def self.names_without_suffix = %w[img input] |
Instance Method Details
#computed_content ⇒ Object
21 |
# File 'lib/navigator/tag.rb', line 21 def computed_content = self.class.names_without_suffix.include?(name) ? nil : content |
#prefix ⇒ Object
rubocop:enable Metrics/ParameterLists
19 |
# File 'lib/navigator/tag.rb', line 19 def prefix = ["<#{name}", format_attributes, ">"].compact.join |
#render ⇒ Object
25 |
# File 'lib/navigator/tag.rb', line 25 def render = [prefix, computed_content, suffix].compact.join |
#suffix ⇒ Object
23 |
# File 'lib/navigator/tag.rb', line 23 def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>" |