Class: ThemeCheck::HtmlNode
- Inherits:
-
Node
- Object
- Node
- ThemeCheck::HtmlNode
show all
- Extended by:
- Forwardable
- Includes:
- RegexHelpers
- Defined in:
- lib/theme_check/html_node.rb
Constant Summary
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
#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
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/theme_check/html_node.rb', line 8
def parent
@parent
end
|
#theme_file ⇒ Object
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
#attributes ⇒ Object
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
|
#children ⇒ Object
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
|
#content ⇒ Object
63
64
65
|
# File 'lib/theme_check/html_node.rb', line 63
def content
@content ||= replace_placeholders(@value.content)
end
|
#element? ⇒ Boolean
53
54
55
|
# File 'lib/theme_check/html_node.rb', line 53
def element?
@value.element?
end
|
#end_index ⇒ Object
45
46
47
|
# File 'lib/theme_check/html_node.rb', line 45
def end_index
raise NotImplementedError
end
|
#line_number ⇒ Object
37
38
39
|
# File 'lib/theme_check/html_node.rb', line 37
def line_number
@value.line
end
|
#literal? ⇒ Boolean
49
50
51
|
# File 'lib/theme_check/html_node.rb', line 49
def literal?
@value.name == "text"
end
|
#markup ⇒ Object
33
34
35
|
# File 'lib/theme_check/html_node.rb', line 33
def markup
@markup ||= replace_placeholders(@value.to_html)
end
|
#name ⇒ Object
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_index ⇒ Object
41
42
43
|
# File 'lib/theme_check/html_node.rb', line 41
def start_index
raise NotImplementedError
end
|
#value ⇒ Object
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
|