Class: ThemeCheck::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/visitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(checks) ⇒ Visitor

Returns a new instance of Visitor.



4
5
6
# File 'lib/theme_check/visitor.rb', line 4

def initialize(checks)
  @checks = checks
end

Instance Method Details

#visit(node) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/theme_check/visitor.rb', line 15

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

#visit_template(template) ⇒ Object



8
9
10
11
12
13
# File 'lib/theme_check/visitor.rb', line 8

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