Sha256: fe1d6b22522a71cc2ea14ad4874bc6aefe4a86cd2f9dd73a851cbb41639a764a

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  class LiquidFile < ThemeFile
    def write
      content = rewriter.to_s
      if source != content
        @storage.write(@relative_path, content.gsub("\n", @eol))
        @source = content
        @rewriter = nil
      end
    end

    def liquid?
      true
    end

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

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

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

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

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

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

    def warnings
      @ast.warnings
    end

    def root
      parse.root
    end

    def self.parse(source)
      Tags.register_tags!
      Liquid::Template.parse(
        source,
        line_numbers: true,
        error_mode: :warn,
        disable_liquid_c_nodes: true,
      )
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
theme-check-1.10.3 lib/theme_check/liquid_file.rb
theme-check-1.10.2 lib/theme_check/liquid_file.rb
theme-check-1.10.1 lib/theme_check/liquid_file.rb
theme-check-1.10.0 lib/theme_check/liquid_file.rb
theme-check-1.9.2 lib/theme_check/liquid_file.rb
theme-check-1.9.1 lib/theme_check/liquid_file.rb
theme-check-1.9.0 lib/theme_check/liquid_file.rb
theme-check-1.8.0 lib/theme_check/liquid_file.rb
theme-check-1.7.2 lib/theme_check/liquid_file.rb
theme-check-1.7.1 lib/theme_check/liquid_file.rb
theme-check-1.7.0 lib/theme_check/liquid_file.rb
theme-check-1.6.2 lib/theme_check/liquid_file.rb