From c690b7124d2f2206342d11aebb7aa3fc990046d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Jun 2011 09:39:41 -0300 Subject: [IMPORTANT] Make "sprockets/railtie" require explicit. This makes "sprockets/railtie" explicit. This means that sprockets will be loaded when you require "rails/all". If you are not using requiring "rails/all", you need to manually load it with all other framework railties. In order to be complete, this commit also adds --skip-sprockets to the rails generator. --- actionpack/lib/action_controller/railtie.rb | 1 - actionpack/lib/sprockets/assets.rake | 26 ++++++++++++++++++++++++++ actionpack/lib/sprockets/railtie.rb | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 actionpack/lib/sprockets/assets.rake (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index d2ba052c8d..f0c29825ba 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -4,7 +4,6 @@ require "action_dispatch/railtie" require "action_view/railtie" require "abstract_controller/railties/routes_helpers" require "action_controller/railties/paths" -require "sprockets/railtie" module ActionController class Railtie < Rails::Railtie diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake new file mode 100644 index 0000000000..0236350576 --- /dev/null +++ b/actionpack/lib/sprockets/assets.rake @@ -0,0 +1,26 @@ +namespace :assets do + desc "Compile all the assets named in config.assets.precompile" + task :precompile do + if ENV["RAILS_GROUPS"].to_s.empty? + ENV["RAILS_GROUPS"] = "assets" + Kernel.exec $0, *ARGV + else + Rake::Task["environment"].invoke + Sprockets::Helpers::RailsHelper + + assets = Rails.application.config.assets.precompile + Rails.application.assets.precompile(*assets) + end + end + + desc "Remove compiled assets" + task :clean => :environment do + assets = Rails.application.config.assets + public_asset_path = Rails.public_path + assets.prefix + file_list = FileList.new("#{public_asset_path}/**/*") + file_list.each do |file| + rm_rf file + rm_rf "#{file}.gz" + end + end +end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index ab5101f6fc..1535716fb9 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -1,6 +1,7 @@ module Sprockets autoload :Helpers, "sprockets/helpers" + # TODO: Get rid of config.assets.enabled class Railtie < ::Rails::Railtie def self.using_coffee? require 'coffee-script' @@ -11,6 +12,10 @@ module Sprockets config.app_generators.javascript_engine :coffee if using_coffee? + rake_tasks do + load "sprockets/assets.rake" + end + # 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