Class: ThemeCheck::HtmlNode

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
RegexHelpers
Defined in:
lib/theme_check/html_node.rb

Constant Summary

Constants included from RegexHelpers

RegexHelpers::LIQUID_TAG, RegexHelpers::LIQUID_TAG_OR_VARIABLE, RegexHelpers::LIQUID_VARIABLE, RegexHelpers::START_OR_END_QUOTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RegexHelpers

#href_to_file_size, #matches

Constructor Details

#initialize(value, template, placeholder_values = [], parent = nil) ⇒ HtmlNode

Returns a new instance of HtmlNode.



10
11
12
13
14
15
# File 'lib/theme_check/html_node.rb', line 10

def initialize(value, template, placeholder_values = [], parent = nil)
  @value = value
  @template = template
  @placeholder_values = placeholder_values
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/theme_check/html_node.rb', line 8

def parent
  @parent
end

#templateObject (readonly)

Returns the value of attribute template.



8
9
10
# File 'lib/theme_check/html_node.rb', line 8

def template
  @template
end

Instance Method Details

#attributesObject



31
32
33
34
35
# File 'lib/theme_check/html_node.rb', line 31

def attributes
  @attributes ||= @value.attributes
    .map { |k, v| [replace_placeholders(k), replace_placeholders(v.value)] }
    .to_h
end

#childrenObject



25
26
27
28
29
# File 'lib/theme_check/html_node.rb', line 25

def children
  @children ||= @value
    .children
    .map { |child| HtmlNode.new(child, template, @placeholder_values, self) }
end

#contentObject



37
38
39
# File 'lib/theme_check/html_node.rb', line 37

def content
  @content ||= replace_placeholders(@value.content)
end

#element?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/theme_check/html_node.rb', line 21

def element?
  @value.element?
end

#line_numberObject



63
64
65
# File 'lib/theme_check/html_node.rb', line 63

def line_number
  @value.line
end

#literal?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/theme_check/html_node.rb', line 17

def literal?
  @value.name == "text"
end

#markupObject



59
60
61
# File 'lib/theme_check/html_node.rb', line 59

def markup
  @markup ||= replace_placeholders(@value.to_html)
end

#nameObject



51
52
53
54
55
56
57
# File 'lib/theme_check/html_node.rb', line 51

def name
  if @value.name == "#document-fragment"
    "document"
  else
    @value.name
  end
end

#valueObject

placeholders for the HtmlNode to make sense.



43
44
45
46
47
48
49
# File 'lib/theme_check/html_node.rb', line 43

def value
  if literal?
    content
  else
    markup
  end
end