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/HAML_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,
  }
  unless ruby1_8?
    @options[:encoding] = Encoding.default_internal || "utf-8"
  end
  @options.merge! options.reject {|k, v| v.nil?}
  @index = 0
  unless [:xhtml, :html4, :html5].include?(@options[:format])
    raise Haml::Error, "Invalid format #{@options[:format].inspect}"
  end
  if @options[:encoding] && @options[:encoding].is_a?(Encoding)
    @options[:encoding] = @options[:encoding].name
  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
  precompile
rescue Haml::Error => e
  e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}" if @index
  raise
end