Merge pull request #188 from cookrn/cookrn_i32_rails_loading

Fix for Rails Loading Problems
This commit is contained in:
Steve Klabnik 2012-05-09 09:50:42 -07:00
commit e2151cd27a
2 changed files with 31 additions and 0 deletions

View File

@ -3,6 +3,28 @@ require 'rails/railtie'
module Draper
class Railtie < Rails::Railtie
##
# Decorators are loaded in
# => at app boot in non-development environments
# => after each request in the development environment
#
# This is necessary because we might never explicitly reference
# Decorator constants.
#
config.to_prepare do
::Draper::System.load_app_local_decorators
end
##
# The `app/decorators` path is eager loaded
#
# This is the standard "Rails Way" to add paths from which constants
# can be loaded.
#
config.before_initialize do |app|
app.config.paths.add 'app/decorators', :eager_load => true
end
initializer "draper.extend_action_controller_base" do |app|
ActiveSupport.on_load(:action_controller) do
Draper::System.setup(:action_controller)

View File

@ -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| require_dependency d }
end
def self.setup(component)
if component == :action_controller
ActionController::Base.send(:include, Draper::ViewContextFilter)