Class: Hamlit::Parser

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

Constant Summary collapse

AVAILABLE_OPTIONS =
%i[
  autoclose
  escape_html
  escape_attrs
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.


21
22
23
24
25
26
# File 'lib/hamlit/parser.rb', line 21

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

Instance Method Details

#call(template) ⇒ Object


28
29
30
31
32
33
34
35
# File 'lib/hamlit/parser.rb', line 28

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