class Middleman::TemplateRenderer

def render(locs={}, opts={}, &block)

def render(locs={}, opts={}, &block)
  path = @path.dup
  locals = locs.dup.freeze
  options = opts.dup
  extension = File.extname(path)
  engine = extension[1..-1].to_sym
  if defined?(::I18n)
    old_locale = ::I18n.locale
    ::I18n.locale = options[:lang] if options[:lang]
  end
  # Sandboxed class for template eval
  context = @app.template_context_class.new(@app, locals, options)
  # TODO: Only for HAML files
  context.init_haml_helpers if context.respond_to?(:init_haml_helpers)
  content = _render_with_all_renderers(path, locs, context, opts, &block)
  # If we need a layout and have a layout, use it
  if layout_file = fetch_layout(engine, options)
    layout_renderer = ::Middleman::FileRenderer.new(@app, layout_file[:relative_path].to_s)
    content = layout_renderer.render(locals, options, context) { content }
  end
  # Return result
  content
ensure
  # Pop all the saved variables from earlier as we may be returning to a
  # previous render (layouts, partials, nested layouts).
  ::I18n.locale = old_locale if defined?(::I18n)
end