Class: Navigator::Tag

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

Overview

Renders a HTML tag.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/navigator/tag.rb', line 6

def content
  @content
end

#nameObject (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_suffixObject



8
# File 'lib/navigator/tag.rb', line 8

def self.names_without_suffix = %w[img input]

Instance Method Details

#computed_contentObject



21
# File 'lib/navigator/tag.rb', line 21

def computed_content = self.class.names_without_suffix.include?(name) ? nil : content

#prefixObject

rubocop:enable Metrics/ParameterLists



19
# File 'lib/navigator/tag.rb', line 19

def prefix = ["<#{name}", format_attributes, ">"].compact.join

#renderObject



25
# File 'lib/navigator/tag.rb', line 25

def render = [prefix, computed_content, suffix].compact.join

#suffixObject



23
# File 'lib/navigator/tag.rb', line 23

def suffix = self.class.names_without_suffix.include?(name) ? nil : "</#{name}>"