Class: Hamlit::Parser

Inherits:
Object show all
Defined in:
lib/hamlit/parser.rb

Constant Summary collapse

AVAILABLE_OPTIONS =
%i[
  autoclose
  escape_html
  escape_attrs
  check_syntax
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



26
27
28
29
30
31
# File 'lib/hamlit/parser.rb', line 26

def initialize(options = {})
  @options = HamlOptions.defaults.dup
  AVAILABLE_OPTIONS.each do |key|
    @options[key] = options[key]
  end
end

Instance Method Details

#call(template) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/hamlit/parser.rb', line 33

def call(template)
  template = Hamlit::HamlUtil.check_haml_encoding(template) do |msg, line|
    raise Hamlit::Error.new(msg, line)
  end
  HamlParser.new(HamlOptions.new(@options)).call(template)
rescue ::Hamlit::HamlError => e
  raise e if @options[:check_syntax]
  error_with_lineno(e)
end