Sha256: 258e2b1de0fe324f7bc1d9a936fcd0ffbb36cb2e1ff84b4eaa15e2055a1f2fe3

Contents?: true

Size: 918 Bytes

Versions: 5

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class Visitor
    def initialize(checks)
      @checks = checks
    end

    def visit_template(template)
      visit(Node.new(template.root, nil, template))
    rescue Liquid::Error => exception
      exception.template_name = template.name
      call_checks(:on_error, exception)
    end

    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
    end

    private

    def visit_children(node)
      node.children.each { |child| visit(child) }
    end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
theme-check-0.2.2 lib/theme_check/visitor.rb
theme-check-0.2.0 lib/theme_check/visitor.rb
theme-check-0.1.2 lib/theme_check/visitor.rb
theme-check-0.1.1 lib/theme_check/visitor.rb
theme-check-0.1.0 lib/theme_check/visitor.rb