Sha256: 59d1790d81f3442a00c614222fac08f38f1b2cbc14e74f6edfe6983e66558e99

Contents?: true

Size: 1.39 KB

Versions: 2

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
        return view_renderer.render(self, options, &block)
      else
        return capture(&block)
      end
    end
    render_without_motorhead options, locals, &block
  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

2 entries across 2 versions & 1 rubygems

Version Path
motorhead-0.2.0 lib/motorhead/action_view.rb
motorhead-0.1.0 lib/motorhead/action_view.rb