class HamlLint::Adapter::Haml5

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

Attributes

parser[R]

The Haml parser to adapt for HamlLint

@api private @return [Haml::Parser] the Haml 5 parser

source[R]

The Haml code to parse

@api private @return [String] Haml code to parse

Public Class Methods

new(source, options = Haml::Options.new) click to toggle source

Parses the specified Haml code into an abstract syntax tree

@example

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

@api public @param source [String] Haml code to parse @param options [Haml::Options]

# File lib/haml_lint/adapter/haml_5.rb, line 16
def initialize(source, options = Haml::Options.new)
  @source = source
  @parser = Haml::Parser.new(options)
end

Public Instance Methods

parse() click to toggle source

Parses the source code into an abstract syntax tree

@example

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

@api public @return [Haml::Parser::ParseNode] @raise [Haml::Error]

# File lib/haml_lint/adapter/haml_5.rb, line 29
def parse
  parser.call(source)
end
precompile() click to toggle source
# File lib/haml_lint/adapter/haml_5.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.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