Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for configuration of the default view context controller #776

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/draper/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Railtie < Rails::Railtie

console do
require 'action_controller/test_case'
ApplicationController.new.view_context
Draper::ViewContext.default_controller.new.view_context
Draper::ViewContext.build
end

Expand Down
13 changes: 13 additions & 0 deletions lib/draper/view_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

module Draper
module ViewContext

# Default controller for view context
#
# @return [Class]
def self.default_controller
(@@default_controller ||= "ApplicationController").constantize
end

# Set default controller for view context
def self.default_controller=(controller)
@@default_controller = controller
end

# Hooks into a controller or mailer to save the view context in {current}.
def view_context
super.tap do |context|
Expand Down
4 changes: 2 additions & 2 deletions lib/draper/view_context/build_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def call
attr_reader :block

def controller
(Draper::ViewContext.controller || ApplicationController.new).tap do |controller|
controller.request ||= new_test_request controller if defined?(ActionController::TestRequest)
(Draper::ViewContext.controller || Draper::ViewContext.default_controller.new).tap do |controller|
controller.request ||= new_test_request(controller) if defined?(ActionController::TestRequest)
end
end

Expand Down