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

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

#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
9
10
# File 'lib/navigator/tag.rb', line 8

def self.names_without_suffix
  %w[img input]
end

Instance Method Details

#computed_contentObject



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

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

#prefixObject



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

def prefix
  ["<#{name}", format_attributes, ">"].compact * ""
end

#renderObject



31
32
33
# File 'lib/navigator/tag.rb', line 31

def render
  [prefix, computed_content, suffix].compact * ""
end

#suffixObject



27
28
29
# File 'lib/navigator/tag.rb', line 27

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