aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-17 11:50:19 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-17 11:50:19 +0200
commitb6843f22ac42b503f6b8ac00105ca0679049be7d (patch)
treee29e8bccd96db3a0e63f2bc5c515da7b86b6d8d0 /actionpack/lib
parenta9a20357220309e3bc7d06c5eac5619ca34b8c56 (diff)
downloadrails-b6843f22ac42b503f6b8ac00105ca0679049be7d.tar.gz
rails-b6843f22ac42b503f6b8ac00105ca0679049be7d.tar.bz2
rails-b6843f22ac42b503f6b8ac00105ca0679049be7d.zip
Lazily load sprockets.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/sprockets/railtie.rb91
1 files changed, 45 insertions, 46 deletions
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index e87382f29d..fe3c8c9783 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -1,57 +1,56 @@
-require "sprockets"
-
-# TODO: Move this to sprockets-rails
-# If so, we can move the require to a Gemfile and remove assets.enabled
-class Sprockets::Railtie < Rails::Railtie
- def self.using_coffee?
- require 'coffee-script'
- defined?(CoffeeScript)
- rescue LoadError
- false
- end
-
- def self.using_scss?
- require 'sass'
- defined?(Sass)
- rescue LoadError
- false
- end
-
- config.app_generators.javascript_engine :coffee if using_coffee?
- config.app_generators.stylesheet_engine :scss if using_scss?
+module Sprockets
+ class Railtie < Rails::Railtie
+ def self.using_coffee?
+ require 'coffee-script'
+ defined?(CoffeeScript)
+ rescue LoadError
+ false
+ end
- # Configure ActionController to use sprockets.
- initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app|
- ActiveSupport.on_load(:action_controller) do
- self.use_sprockets = app.config.assets.enabled
+ def self.using_scss?
+ require 'sass'
+ defined?(Sass)
+ rescue LoadError
+ false
end
- end
- # We need to configure this after initialization to ensure we collect
- # paths from all engines. This hook is invoked exactly before routes
- # are compiled.
- config.after_initialize do |app|
- assets = app.config.assets
- next unless assets.enabled
+ config.app_generators.javascript_engine :coffee if using_coffee?
+ config.app_generators.stylesheet_engine :scss if using_scss?
- app.assets = asset_environment(app)
- app.routes.append do
- mount app.assets => assets.prefix
+ # Configure ActionController to use sprockets.
+ initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app|
+ ActiveSupport.on_load(:action_controller) do
+ self.use_sprockets = app.config.assets.enabled
+ end
end
- if config.action_controller.perform_caching
- app.assets = app.assets.index
+ # We need to configure this after initialization to ensure we collect
+ # paths from all engines. This hook is invoked exactly before routes
+ # are compiled.
+ config.after_initialize do |app|
+ assets = app.config.assets
+ next unless assets.enabled
+
+ app.assets = asset_environment(app)
+ app.routes.append do
+ mount app.assets => assets.prefix
+ end
+
+ if config.action_controller.perform_caching
+ app.assets = app.assets.index
+ end
end
- end
- protected
+ protected
- def asset_environment(app)
- assets = app.config.assets
- env = Sprockets::Environment.new(app.root.to_s)
- env.static_root = File.join(app.root.join("public"), assets.prefix)
- env.paths.concat assets.paths
- env.logger = Rails.logger
- env
+ def asset_environment(app)
+ require "sprockets"
+ assets = app.config.assets
+ env = Sprockets::Environment.new(app.root.to_s)
+ env.static_root = File.join(app.root.join("public"), assets.prefix)
+ env.paths.concat assets.paths
+ env.logger = Rails.logger
+ env
+ end
end
end \ No newline at end of file