Sha256: 32573fa6c2bffa03b9c89957b966edb5e654ec0f44783957f304bdb26bbe631e

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'hocus_pocus/engine'
require 'hocus_pocus/filter'

module HocusPocus
  VIEW_FILENAMES = :__hocus_pocus_view_filenames__
  EDITOR = :__hocus_pocus_editor__
  GENERATOR = :__hocus_pocus_generator__
  SPEC = :__hocus_pocus_spec__
end

if Rails.env.development?
  ActiveSupport.on_load(:after_initialize) do
    Rails.application.routes.append do
      mount HocusPocus::Engine, :at => '/'
    end
  end

  class ::ActionController::Base
    before_filter HocusPocus::Filter
    after_filter HocusPocus::Filter
  end

  class ::ActionView::Base
    def method_missing(method, args = {}, &blk)
      if method.to_s =~ /(new_|edit_)?(.*)(_path|_url)\z/
        # to avoid DoubleRenderError
        controller.instance_variable_set :@_response_body, nil
        #FIXME preserve args
        controller.redirect_to "/#{$2.pluralize}?return_path=#{method}(#{args})"
      else
        super
      end
    end
  end

  class ::ActionView::PartialRenderer
    def render_partial_with_filename_caching
      (Thread.current[HocusPocus::VIEW_FILENAMES] ||= []) << @template unless @view.controller.is_a?(HocusPocus::EditorController)
      render_partial_without_filename_caching
    end
    alias_method_chain :render_partial, :filename_caching
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hocus_pocus-0.0.1 lib/hocus_pocus.rb
hocus_pocus-0.0.0 lib/hocus_pocus.rb