Class: ThemeCheck::LiquidFile

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

Instance Attribute Summary

Attributes inherited from ThemeFile

#storage, #version

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



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

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

#liquid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/theme_check/liquid_file.rb', line 14

def liquid?
  true
end

#parseObject



39
40
41
# File 'lib/theme_check/liquid_file.rb', line 39

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

#rewriterObject



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

def rewriter
  @rewriter ||= ThemeFileRewriter.new(@relative_path, source)
end

#rootObject



47
48
49
# File 'lib/theme_check/liquid_file.rb', line 47

def root
  parse.root
end

#section?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/theme_check/liquid_file.rb', line 22

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

#snippet?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/theme_check/liquid_file.rb', line 26

def snippet?
  name.start_with?('snippets')
end

#source_excerpt(line) ⇒ Object



34
35
36
37
# File 'lib/theme_check/liquid_file.rb', line 34

def source_excerpt(line)
  original_lines = source.split("\n")
  original_lines[line - 1].strip
end

#template?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/theme_check/liquid_file.rb', line 18

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

#warningsObject



43
44
45
# File 'lib/theme_check/liquid_file.rb', line 43

def warnings
  @ast.warnings
end

#writeObject



5
6
7
8
9
10
11
12
# File 'lib/theme_check/liquid_file.rb', line 5

def write
  content = rewriter.to_s
  if source != content
    @storage.write(@relative_path, content.gsub("\n", @eol))
    @source = content
    @rewriter = nil
  end
end