Class: ThemeCheck::Template

Inherits:
ThemeFile show all
Defined in:
lib/theme_check/template.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThemeFile

#==, #initialize, #json?, #name, #path, #relative_path, #source

Constructor Details

This class inherits a constructor from ThemeCheck::ThemeFile

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

#linesObject



29
30
31
32
# File 'lib/theme_check/template.rb', line 29

def lines
  # Retain trailing newline character
  @lines ||= source.split("\n", -1)
end

#liquid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/theme_check/template.rb', line 13

def liquid?
  true
end

#parseObject



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

def parse
  @ast ||= self.class.parse(source)
end

#rootObject



61
62
63
# File 'lib/theme_check/template.rb', line 61

def root
  parse.root
end

#section?Boolean

Returns:

  • (Boolean)


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

def section?
  name.start_with?('sections')
end

#snippet?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

def template?
  name.start_with?('templates')
end

#updated_contentObject

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

#warningsObject



57
58
59
# File 'lib/theme_check/template.rb', line 57

def warnings
  @ast.warnings
end

#writeObject



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