Class: HamlLint::NodeTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_lint/node_transformer.rb

Overview

Responsible for transforming Haml::Parser::ParseNode objects into corresponding Tree::Node objects.

The parse tree generated by HAML has a number of strange cases where certain types of nodes are created that don't necessarily correspond to what one would expect. This class is intended to isolate and handle these cases so that linters don't have to deal with them.

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ NodeTransformer

Creates a node transformer for the given parser context.


13
14
15
# File 'lib/haml_lint/node_transformer.rb', line 13

def initialize(parser)
  @parser = parser
end

Instance Method Details

#transform(haml_node) ⇒ Object

Transforms the given Haml::Parser::ParseNode into its corresponding Tree::Node.


19
20
21
22
23
24
25
26
# File 'lib/haml_lint/node_transformer.rb', line 19

def transform(haml_node)
  node_class = "#{HamlLint::Utils.camel_case(haml_node.type.to_s)}Node"

  HamlLint::Tree.const_get(node_class).new(@parser, haml_node)
rescue NameError
  # TODO: Wrap in parser error?
  raise
end