Class: ThemeCheck::HtmlNode

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

Constant Summary

Constants included from RegexHelpers

RegexHelpers::HTML_LIQUID_PLACEHOLDER, 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

#matches

Constructor Details

#initialize(value, theme_file, 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, theme_file, placeholder_values = [], parent = nil)
  @value = value
  @theme_file = theme_file
  @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

#theme_fileObject (readonly)

Returns the value of attribute theme_file.



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

def theme_file
  @theme_file
end

Instance Method Details

#attributesObject



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

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

#childrenObject



27
28
29
30
31
# File 'lib/theme_check/html_node.rb', line 27

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

#contentObject



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

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

#element?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/theme_check/html_node.rb', line 53

def element?
  @value.element?
end

#end_indexObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/theme_check/html_node.rb', line 45

def end_index
  raise NotImplementedError
end

#line_numberObject



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

def line_number
  @value.line
end

#literal?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/theme_check/html_node.rb', line 49

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

#markupObject



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

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

#nameObject



67
68
69
70
71
72
73
# File 'lib/theme_check/html_node.rb', line 67

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

#start_indexObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/theme_check/html_node.rb', line 41

def start_index
  raise NotImplementedError
end

#valueObject

placeholders for the HtmlNode to make sense.



19
20
21
22
23
24
25
# File 'lib/theme_check/html_node.rb', line 19

def value
  if literal?
    content
  else
    markup
  end
end