Class: HamlLint::NodeTransformer
- Inherits:
-
Object
- Object
- HamlLint::NodeTransformer
- 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
-
#initialize(document) ⇒ NodeTransformer
constructor
Creates a node transformer for the given Haml document.
-
#transform(haml_node) ⇒ HamlLint::Tree::Node
Converts the given HAML parse node into its corresponding HAML-Lint parse node.
Constructor Details
#initialize(document) ⇒ NodeTransformer
Creates a node transformer for the given Haml document.
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.
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 |