Sha256: c42ba9455216666cd49131d90b5ed1e9adc0ca68640939dd3292625e6633a557

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  class Template < 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 ||= TemplateRewriter.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

2 entries across 2 versions & 1 rubygems

Version Path
theme-check-1.6.1 lib/theme_check/template.rb
theme-check-1.6.0 lib/theme_check/template.rb