From 16b9547a881eb2e201c6f17ec7850bc05c8f6a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Apr 2011 10:26:32 +0200 Subject: Move controller configs to sprockets own railtie. --- actionpack/lib/sprockets/railtie.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 actionpack/lib/sprockets/railtie.rb (limited to 'actionpack/lib/sprockets/railtie.rb') diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb new file mode 100644 index 0000000000..4eb302d4a6 --- /dev/null +++ b/actionpack/lib/sprockets/railtie.rb @@ -0,0 +1,9 @@ +require "sprockets" + +class Sprockets::Railtie < Rails::Railtie + 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 +end \ No newline at end of file -- cgit v1.2.3 From 8f75c3abcde4f2ff64e855178027e1bd93976de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Apr 2011 10:51:07 +0200 Subject: Move app initializers to sprockets railtie. --- actionpack/lib/sprockets/railtie.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'actionpack/lib/sprockets/railtie.rb') diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 4eb302d4a6..5006a3a575 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -1,9 +1,40 @@ 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 + # 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 + + # 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 + + 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 + end end \ No newline at end of file -- cgit v1.2.3 From 3a68aec1a1c6329bfcbf0f87bdc2fbd75cb98feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Apr 2011 11:44:52 +0200 Subject: Make generators more modular, add hooks and improve test suite. --- actionpack/lib/sprockets/railtie.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'actionpack/lib/sprockets/railtie.rb') diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 5006a3a575..e87382f29d 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -3,6 +3,23 @@ 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? + # Configure ActionController to use sprockets. initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app| ActiveSupport.on_load(:action_controller) do -- cgit v1.2.3 From b6843f22ac42b503f6b8ac00105ca0679049be7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Apr 2011 11:50:19 +0200 Subject: Lazily load sprockets. --- actionpack/lib/sprockets/railtie.rb | 91 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'actionpack/lib/sprockets/railtie.rb') 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 -- cgit v1.2.3