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(document) ⇒ NodeTransformer

Creates a node transformer for the given Haml document.

Parameters:



15
16
17
# File 'lib/haml_lint/node_transformer.rb', line 15

def initialize(document)
  @document = document
end

Instance Method Details

#transform(haml_node) ⇒ HamlLint::Tree::Node

Converts the given HAML parse node into its corresponding HAML-Lint parse node.

Parameters:

  • haml_node (Haml::Parser::ParseNode)

Returns:



24
25
26
27
28
# File 'lib/haml_lint/node_transformer.rb', line 24

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

  HamlLint::Tree.const_get(node_class).new(@document, haml_node)
end