Class: Haml::Parser::ParseNode

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/haml.rb

Instance Method Summary collapse

Instance Method Details

#accept(visitor) ⇒ Object

Here we’re going to hook into the parse node and define a method that will accept a visitor in order to walk through the tree.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/syntax_tree/haml.rb', line 60

def accept(visitor)
  case type
  when :comment
    visitor.visit_comment(self)
  when :doctype
    visitor.visit_doctype(self)
  when :filter
    visitor.visit_filter(self)
  when :haml_comment
    visitor.visit_haml_comment(self)
  when :plain
    visitor.visit_plain(self)
  when :root
    visitor.visit_root(self)
  when :script
    visitor.visit_script(self)
  when :silent_script
    visitor.visit_silent_script(self)
  when :tag
    visitor.visit_tag(self)
  else
    raise "Unknown node type: #{type}"
  end
end

#format(q) ⇒ Object



85
86
87
# File 'lib/syntax_tree/haml.rb', line 85

def format(q)
  accept(SyntaxTree::Haml::Format.new(q))
end

#pretty_print(q) ⇒ Object



89
90
91
# File 'lib/syntax_tree/haml.rb', line 89

def pretty_print(q)
  accept(SyntaxTree::Haml::PrettyPrint.new(q))
end