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

Simplify railtie #342

Merged
merged 1 commit into from Nov 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 14 additions & 21 deletions lib/draper/railtie.rb
Expand Up @@ -3,49 +3,42 @@
module ActiveModel module ActiveModel
class Railtie < Rails::Railtie class Railtie < Rails::Railtie
generators do |app| generators do |app|
Rails::Generators.configure!(app.config.generators) Rails::Generators.configure! app.config.generators
require "generators/resource_override" require 'generators/resource_override'
end end
end end
end end


module Draper module Draper
class Railtie < Rails::Railtie class Railtie < Rails::Railtie


##
# The `app/decorators` path is eager loaded
#
# This is the standard "Rails Way" to add paths from which constants
# can be loaded.
#
config.after_initialize do |app| config.after_initialize do |app|
app.config.paths.add 'app/decorators', :eager_load => true app.config.paths.add 'app/decorators', eager_load: true
end end


initializer "draper.extend_action_controller_base" do |app| initializer "draper.setup_action_controller" do |app|
ActiveSupport.on_load(:action_controller) do ActiveSupport.on_load :action_controller do
Draper.setup_action_controller(self) Draper.setup_action_controller self
end end
end end


initializer "draper.extend_action_mailer_base" do |app| initializer "draper.setup_action_mailer" do |app|
ActiveSupport.on_load(:action_mailer) do ActiveSupport.on_load :action_mailer do
Draper.setup_action_mailer(self) Draper.setup_action_mailer self
end end
end end


initializer "draper.extend_active_record_base" do |app| initializer "draper.setup_active_record" do |app|
ActiveSupport.on_load(:active_record) do ActiveSupport.on_load :active_record do
Draper.setup_active_record(self) Draper.setup_active_record self
end end
end end


console do console do
require 'action_controller/test_case' require 'action_controller/test_case'
ApplicationController.new.view_context ApplicationController.new.view_context
Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new Draper::ViewContext.build_view_context
Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request
Draper::ViewContext.current.params ||= {}
end end

end end
end end
14 changes: 6 additions & 8 deletions lib/draper/view_context.rb
@@ -1,5 +1,11 @@
module Draper module Draper
module ViewContext module ViewContext
def view_context
super.tap do |context|
Draper::ViewContext.current = context
end
end

def self.current_controller def self.current_controller
Thread.current[:current_controller] || ApplicationController.new Thread.current[:current_controller] || ApplicationController.new
end end
Expand All @@ -16,14 +22,6 @@ def self.current=(context)
Thread.current[:current_view_context] = context Thread.current[:current_view_context] = context
end end


def view_context
super.tap do |context|
Draper::ViewContext.current = context
end
end

private

def self.build_view_context def self.build_view_context
current_controller.view_context.tap do |context| current_controller.view_context.tap do |context|
if defined?(ActionController::TestRequest) if defined?(ActionController::TestRequest)
Expand Down