Class: HamlLint::Adapter::Haml4

Inherits:
HamlLint::Adapter show all
Extended by:
Forwardable
Defined in:
lib/haml_lint/adapter/haml_4.rb

Overview

Adapts the Haml::Parser from Haml 4 for use in HamlLint :reek:UncommunicativeModuleName

Instance Method Summary collapse

Methods inherited from HamlLint::Adapter

detect_class

Constructor Details

#initialize(source, options = Haml::Options.new) ⇒ Haml4

Parses the specified Haml code into an abstract syntax tree

Examples:

HamlLint::Adapter::Haml4.new('%div')

Parameters:

  • source (String)

    Haml code to parse

  • options (Haml::Options) (defaults to: Haml::Options.new)


20
21
22
23
# File 'lib/haml_lint/adapter/haml_4.rb', line 20

def initialize(source, options = Haml::Options.new)
  @source = source
  @parser = Haml::Parser.new(source, options)
end

Instance Method Details

#precompileObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/haml_lint/adapter/haml_4.rb', line 25

def precompile
  # Haml uses the filters as part of precompilation... we don't care about those,
  # but without this tweak, it would fail on filters that are not loaded.
  real_defined = Haml::Filters.defined
  Haml::Filters.instance_variable_set(:@defined, Hash.new { real_defined['plain'] })

  ::Haml::Engine.new(source).precompiled
ensure
  Haml::Filters.instance_variable_set(:@defined, real_defined)
end