Sha256: 55767187eef5849243f5a3d80e4d71f34bfaea4b9bc945033f09094aa08cd5eb

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 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.camelize.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 :render_without_motorhead, :render
  alias_method :render, :render_with_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.camelize.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.4.1 lib/motorhead/action_view.rb
motorhead-0.4.0 lib/motorhead/action_view.rb