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.delete(:locale) if options[:locale] # Backwards compat ::I18n.locale = options.delete(:lang) if options[:lang] end # Sandboxed class for template eval context = @app.template_context_class.new(@app, locals, options) # Add extension helpers to context. @app.extensions.add_exposed_to_context(context) locals.each do |k, _| next unless context.respond_to?(k) && ![:current_path, :paginate, :page_articles, :blog_controller, :lang, :locale, :data].include?(k.to_sym) msg = "Template local `#{k}` tried to overwrite an existing context value. Please rename the key when passing to `locals`" if @app.build? throw msg else @app.logger.error(msg) end end content = ::Middleman::Util.instrument 'builder.output.resource.render-template', path: File.basename(path) do _render_with_all_renderers(path, locals, context, options, &block) end # If we need a layout and have a layout, use it layout_file = fetch_layout(engine, options) if layout_file content = if layout_file = fetch_layout(engine, options) layout_renderer = ::Middleman::FileRenderer.new(@app, layout_file[:relative_path].to_s) ::Middleman::Util.instrument 'builder.output.resource.render-layout', path: File.basename(layout_file[:relative_path].to_s) do layout_renderer.render(locals, options, context) { content } end else content end 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