Sha256: 60329d26bfcd175ecc10d96400ba6bb2271537f853c0788251dadc6b2dfaa67d

Contents?: true

Size: 993 Bytes

Versions: 12

Compression:

Stored size: 993 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?
    end

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

Version data entries

12 entries across 12 versions & 1 rubygems

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