Sha256: 59371a1be69e196074b73a28fce8a82a50e6a603656d89fd50c62691eadccab7

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

ActionView::Base.class_eval do
  #FIXME FIXHAML AMCing here because prepending on `render` causes infinite loop when Haml is bundled
  def render_with_motorhead(options = {}, locals = {}, &block)
    if (Hash === options) && options.key?(:engine)
      ext_name = options[:engine][/[^\/]*/]
      if ext_name.classify.constantize::Engine.active? controller
        view_renderer.render(self, options, &block)
      elsif block
        capture(&block)
      end
    else
      render_without_motorhead options, locals, &block
    end
  end

  alias_method_chain :render, :motorhead
end

module Motorhead
  module ActionView
    module Renderer
      def render(context, options, &block)
        if options.key? :engine
          render_engine(context, options, &block)
        else
          super
        end
      end

      def render_engine(context, options, &block)
        partial_name = options.delete :engine
        Motorhead::EngineRenderer.new(@lookup_context).render(context, options.merge(partial: partial_name), block)
      end
    end
  end

  class EngineRenderer < ::ActionView::PartialRenderer
    def render(context, options, block)
      super
    rescue => e
      ext_name = options[:partial][/[^\/]*/]
      (ext_name.classify.constantize::Engine.on_error || Motorhead.config.on_error).call(e)
      context.capture(&block)
    end
  end
end

ActionView::Renderer.prepend Motorhead::ActionView::Renderer

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motorhead-0.3.3 lib/motorhead/action_view.rb
motorhead-0.3.2 lib/motorhead/action_view.rb
motorhead-0.3.1 lib/motorhead/action_view.rb
motorhead-0.3.0 lib/motorhead/action_view.rb