Sha256: 6930624daecf85977b141f9e552807d311a557a7bcbbc22cf576ec98756a246b

Contents?: true

Size: 1017 Bytes

Versions: 6

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class LiquidVisitor
    attr_reader :checks

    def initialize(checks, disabled_checks)
      @checks = checks
      @disabled_checks = disabled_checks
    end

    def visit_liquid_file(liquid_file)
      visit(LiquidNode.new(liquid_file.root, nil, liquid_file))
    rescue Liquid::Error => exception
      exception.template_name = liquid_file.name
      call_checks(:on_error, exception)
    end

    private

    def visit(node)
      call_checks(:on_node, node)
      call_checks(:on_tag, node) if node.tag?
      call_checks(:"on_#{node.type_name}", node)
      node.children.each { |child| visit(child) }
      unless node.literal?
        call_checks(:"after_#{node.type_name}", node)
        call_checks(:after_tag, node) if node.tag?
        call_checks(:after_node, node)
      end

      @disabled_checks.update(node) if node.comment? || node.inline_comment?
    end

    def call_checks(method, *args)
      checks.call(method, *args)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/liquid_visitor.rb
theme-check-1.14.0 lib/theme_check/liquid_visitor.rb
theme-check-1.13.0 lib/theme_check/liquid_visitor.rb
theme-check-1.12.1 lib/theme_check/liquid_visitor.rb
theme-check-1.12.0 lib/theme_check/liquid_visitor.rb
theme-check-1.11.0 lib/theme_check/liquid_visitor.rb