Second attempt at view_context fix
This commit is contained in:
parent
6887ade43c
commit
a54e3f3772
|
@ -1,18 +1,35 @@
|
||||||
module Draper
|
module Draper
|
||||||
module ViewContext
|
module ViewContext
|
||||||
def self.current
|
def self.current
|
||||||
Thread.current[:current_view_context] || ApplicationController.new.view_context
|
Thread.current[:current_view_context] ||= build_view_context
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.current=(input)
|
def self.current=(input)
|
||||||
Thread.current[:current_view_context] = input
|
Thread.current[:current_view_context] = input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.build_view_context
|
||||||
|
ApplicationController.new.view_context.tap do |context|
|
||||||
|
context.instance_eval do
|
||||||
|
def url_options
|
||||||
|
ActionMailer::Base.default_url_options
|
||||||
|
end
|
||||||
|
end unless context.request
|
||||||
|
if defined?(ActionController::TestRequest)
|
||||||
|
context.controller.request ||= ActionController::TestRequest.new
|
||||||
|
context.request ||= context.controller.request
|
||||||
|
context.params ||= {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ViewContextFilter
|
module ViewContextFilter
|
||||||
def view_context
|
def view_context
|
||||||
ApplicationController.new.view_context.tap do |context|
|
super.tap do |context|
|
||||||
Draper::ViewContext.current = self.view_context
|
Draper::ViewContext.current = context
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue