Convert Draper to using a Railtie for loading
This commit is contained in:
parent
de2d62c75a
commit
051dec8360
|
@ -7,5 +7,5 @@ require 'draper/helper_support'
|
||||||
require 'draper/view_context'
|
require 'draper/view_context'
|
||||||
require 'draper/decorated_enumerable_proxy'
|
require 'draper/decorated_enumerable_proxy'
|
||||||
require 'draper/rspec_integration' if defined?(RSpec) and RSpec.respond_to?(:configure)
|
require 'draper/rspec_integration' if defined?(RSpec) and RSpec.respond_to?(:configure)
|
||||||
|
require 'draper/railtie'
|
||||||
|
|
||||||
Draper::System.setup
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
require 'rails/railtie'
|
||||||
|
|
||||||
|
module Draper
|
||||||
|
class Railtie < Rails::Railtie
|
||||||
|
|
||||||
|
initializer "draper.extend_action_controller_base" do |app|
|
||||||
|
ActiveSupport.on_load(:action_controller) do
|
||||||
|
Draper::System.setup(:action_controller)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
initializer "draper.extend_action_mailer_base" do |app|
|
||||||
|
ActiveSupport.on_load(:action_mailer) do
|
||||||
|
Draper::System.setup(:action_mailer)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,12 @@
|
||||||
module Draper
|
module Draper
|
||||||
class System
|
class System
|
||||||
def self.setup
|
def self.setup(component)
|
||||||
ActionController::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionController::Base)
|
if component == :action_controller
|
||||||
ActionMailer::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionMailer::Base)
|
ActionController::Base.send(:include, Draper::ViewContextFilter)
|
||||||
ActionController::Base.send(:helper, Draper::HelperSupport) if defined?(ActionController::Base)
|
ActionController::Base.extend(Draper::HelperSupport)
|
||||||
|
elsif component == :action_mailer
|
||||||
|
ActionMailer::Base.send(:include, Draper::ViewContextFilter)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,12 +9,11 @@ module ActionController
|
||||||
def self.before_filter(name)
|
def self.before_filter(name)
|
||||||
@@before_filters << name
|
@@before_filters << name
|
||||||
end
|
end
|
||||||
def self.helper(mod)
|
|
||||||
extend mod
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Draper::System.setup(:action_controller)
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
extend ActionView::Helpers
|
extend ActionView::Helpers
|
||||||
extend ActionView::Helpers::TagHelper
|
extend ActionView::Helpers::TagHelper
|
||||||
|
@ -42,5 +41,3 @@ class ApplicationController < ActionController::Base
|
||||||
@@capture ||= false
|
@@capture ||= false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Draper::System.setup
|
|
||||||
|
|
Loading…
Reference in New Issue