diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
commit | 19965402b2f868c79d78269ca17cb6282f271382 (patch) | |
tree | 8635415f386595650c27469d6b6d04335121d070 /actionpack/lib/sprockets/assets.rake | |
parent | 9d54f8994d09db5435d6c234430ae13333928fb9 (diff) | |
parent | ec53b802dab9b676dcc9b53e542bcd840983b7a2 (diff) | |
download | rails-19965402b2f868c79d78269ca17cb6282f271382.tar.gz rails-19965402b2f868c79d78269ca17cb6282f271382.tar.bz2 rails-19965402b2f868c79d78269ca17cb6282f271382.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack/lib/sprockets/assets.rake')
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index 9b2f3a3f94..bb5cf6740a 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -6,58 +6,55 @@ namespace :assets do if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty? ENV["RAILS_GROUPS"] ||= "assets" ENV["RAILS_ENV"] ||= "production" - Kernel.exec $0, *ARGV + ruby $0, *ARGV else - Rake::Task["environment"].invoke + require "fileutils" Rake::Task["tmp:cache:clear"].invoke + Rake::Task["assets:environment"].invoke - # Ensure that action view is loaded and the appropriate sprockets hooks get executed - ActionView::Base - - # Always compile files - Rails.application.config.assets.compile = true + unless Rails.application.config.assets.enabled + raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true" + end - # Always ignore asset host - Rails.application.config.action_controller.asset_host = nil + # Ensure that action view is loaded and the appropriate sprockets hooks get executed + _ = ActionView::Base config = Rails.application.config + config.assets.compile = true + config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"] + env = Rails.application.assets - target = Pathname.new(File.join(Rails.public_path, config.assets.prefix)) - manifest = {} + + # Always compile files and avoid use of existing precompiled assets + config.assets.compile = true + config.assets.digests = {} + + target = File.join(Rails.public_path, config.assets.prefix) + static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) + + manifest = static_compiler.precompile(config.assets.precompile) manifest_path = config.assets.manifest || target + FileUtils.mkdir_p(manifest_path) - config.assets.precompile.each do |path| - env.each_logical_path do |logical_path| - if path.is_a?(Regexp) - next unless path.match(logical_path) - elsif path.is_a?(Proc) - next unless path.call(logical_path) - else - next unless File.fnmatch(path.to_s, logical_path) - end - - if asset = env.find_asset(logical_path) - asset_path = config.assets.digest ? asset.digest_path : logical_path - manifest[logical_path] = asset_path - filename = target.join(asset_path) - - mkdir_p filename.dirname - asset.write_to(filename) - asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/ - end + unless ENV["RAILS_ASSETS_NONDIGEST"] + File.open("#{manifest_path}/manifest.yml", 'wb') do |f| + YAML.dump(manifest, f) end - end - - File.open("#{manifest_path}/manifest.yml", 'wb') do |f| - YAML.dump(manifest, f) + ENV["RAILS_ASSETS_NONDIGEST"] = "true" + ruby $0, *ARGV end end end desc "Remove compiled assets" - task :clean => [:environment, 'tmp:cache:clear'] do + task :clean => ['assets:environment', 'tmp:cache:clear'] do config = Rails.application.config public_asset_path = File.join(Rails.public_path, config.assets.prefix) rm_rf public_asset_path, :secure => true end + + task :environment do + Rails.application.initialize!(:assets) + Sprockets::Bootstrap.new(Rails.application).run + end end |