Class: ThemeCheck::Template
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ThemeFile
#==, #initialize, #json?, #name, #path, #relative_path, #source
Class Method Details
.parse(source) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/theme_check/template.rb', line 65
def self.parse(source)
Tags.register_tags!
Liquid::Template.parse(
source,
line_numbers: true,
error_mode: :warn,
disable_liquid_c_nodes: true,
)
end
|
Instance Method Details
#excerpt(line) ⇒ Object
40
41
42
|
# File 'lib/theme_check/template.rb', line 40
def excerpt(line)
lines[line - 1].strip
end
|
#full_line(line) ⇒ Object
49
50
51
|
# File 'lib/theme_check/template.rb', line 49
def full_line(line)
lines[line - 1]
end
|
#lines ⇒ Object
29
30
31
32
|
# File 'lib/theme_check/template.rb', line 29
def lines
@lines ||= source.split("\n", -1)
end
|
#liquid? ⇒ Boolean
13
14
15
|
# File 'lib/theme_check/template.rb', line 13
def liquid?
true
end
|
#parse ⇒ Object
53
54
55
|
# File 'lib/theme_check/template.rb', line 53
def parse
@ast ||= self.class.parse(source)
end
|
#root ⇒ Object
61
62
63
|
# File 'lib/theme_check/template.rb', line 61
def root
parse.root
end
|
#section? ⇒ Boolean
21
22
23
|
# File 'lib/theme_check/template.rb', line 21
def section?
name.start_with?('sections')
end
|
#snippet? ⇒ Boolean
25
26
27
|
# File 'lib/theme_check/template.rb', line 25
def snippet?
name.start_with?('snippets')
end
|
#source_excerpt(line) ⇒ Object
44
45
46
47
|
# File 'lib/theme_check/template.rb', line 44
def source_excerpt(line)
original_lines = source.split("\n")
original_lines[line - 1].strip
end
|
#template? ⇒ Boolean
17
18
19
|
# File 'lib/theme_check/template.rb', line 17
def template?
name.start_with?('templates')
end
|
#updated_content ⇒ Object
Not entirely obvious but lines is mutable, corrections are to be applied on @lines.
36
37
38
|
# File 'lib/theme_check/template.rb', line 36
def updated_content
lines.join("\n")
end
|
#warnings ⇒ Object
57
58
59
|
# File 'lib/theme_check/template.rb', line 57
def warnings
@ast.warnings
end
|
#write ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/theme_check/template.rb', line 5
def write
content = updated_content
if source != content
@storage.write(@relative_path, content)
@source = content
end
end
|