class Haml::Engine

def initialize(template, options = {})

Raises:
  • (Haml::Error) - if there's a Haml syntax error in the template

Parameters:
  • options ({Symbol => Object}) -- An options hash;
  • template (String) -- The Haml template
def initialize(template, options = {})
  @options = {
    :suppress_eval        => false,
    :attr_wrapper         => "'",
    # Don't forget to update the docs in doc-src/REFERENCE.md
    # if you update these
    :autoclose            => %w[meta img link br hr input area param col base],
    :preserve             => %w[textarea pre code],
    :filename             => '(haml)',
    :line                 => 1,
    :ugly                 => false,
    :format               => :xhtml,
    :escape_html          => false,
    :escape_attrs         => true,
    :hyphenate_data_attrs => true,
  }
  @index = nil # explicitily initialize to avoid warnings
  template = check_haml_encoding(template) do |msg, line|
    raise Haml::Error.new(msg, line)
  end
  set_up_encoding(options, template)
  @options.merge! options.reject {|k, v| v.nil?}
  @index = 0
  @options[:format] = :xhtml if @options[:mime_type] == 'text/xml'
  unless [:xhtml, :html4, :html5].include?(@options[:format])
    raise Haml::Error, "Invalid output format #{@options[:format].inspect}"
  end
  # :eod is a special end-of-document marker
  @template = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
  @template_index = 0
  @to_close_stack = []
  @output_tabs = 0
  @template_tabs = 0
  @flat = false
  @newlines = 0
  @precompiled = ''
  @to_merge = []
  @tab_change  = 0
  compile(parse)
rescue Haml::Error => e
  if @index || e.line
    e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}"
  end
  raise
end