diff --git a/lib/draper/railtie.rb b/lib/draper/railtie.rb index 5334994..f0c9a32 100644 --- a/lib/draper/railtie.rb +++ b/lib/draper/railtie.rb @@ -3,6 +3,10 @@ require 'rails/railtie' module Draper class Railtie < Rails::Railtie + config.to_prepare do + ::Draper::System.load_app_local_decorators + end + initializer "draper.extend_action_controller_base" do |app| ActiveSupport.on_load(:action_controller) do Draper::System.setup(:action_controller) diff --git a/lib/draper/system.rb b/lib/draper/system.rb index cea1643..af1e9f4 100644 --- a/lib/draper/system.rb +++ b/lib/draper/system.rb @@ -1,5 +1,14 @@ module Draper class System + def self.app_local_decorator_glob + 'app/decorators/**/*_decorator.rb' + end + + def self.load_app_local_decorators + decorator_files = Dir[ "#{ Rails.root }/#{ app_local_decorator_glob }" ] + decorator_files.each { |d| load d } + end + def self.setup(component) if component == :action_controller ActionController::Base.send(:include, Draper::ViewContextFilter)