Class: HamlLint::Adapter::Haml6

Inherits:
HamlLint::Adapter show all
Defined in:
lib/haml_lint/adapter/haml_6.rb

Overview

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

Instance Method Summary collapse

Methods inherited from HamlLint::Adapter

detect_class

Constructor Details

#initialize(source, options = {}) ⇒ Haml6

Parses the specified Haml code into an abstract syntax tree

Examples:

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

Parameters:

  • source (String)

    Haml code to parse

  • options (private Haml::Parser::ParserOptions) (defaults to: {})


16
17
18
19
# File 'lib/haml_lint/adapter/haml_6.rb', line 16

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

Instance Method Details

#parseHaml::Parser::ParseNode

Parses the source code into an abstract syntax tree

Examples:

HamlLint::Adapter::Haml6.new('%div').parse

Returns:

  • (Haml::Parser::ParseNode)

Raises:

  • (Haml::Error)


29
30
31
# File 'lib/haml_lint/adapter/haml_6.rb', line 29

def parse
  parser.call(source)
end

#precompileObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/haml_lint/adapter/haml_6.rb', line 33

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.registered
  Haml::Filters.instance_variable_set(:@registered, Hash.new { real_defined['plain'] })

  ::Haml::Engine.new.call(source)
ensure
  Haml::Filters.instance_variable_set(:@registered, real_defined)
end