diff options
Diffstat (limited to 'actionpack/lib/sprockets')
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 22 | ||||
-rw-r--r-- | actionpack/lib/sprockets/compressors.rb | 42 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 27 | ||||
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/sprockets/static_compiler.rb | 7 |
5 files changed, 60 insertions, 45 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index a61a121d55..2e92fe416b 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -1,12 +1,16 @@ require "fileutils" namespace :assets do - def ruby_rake_task(task) + def ruby_rake_task(task, fork = true) env = ENV['RAILS_ENV'] || 'production' groups = ENV['RAILS_GROUPS'] || 'assets' args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"] args << "--trace" if Rake.application.options.trace - ruby(*args) + if $0 =~ /rake\.bat\Z/i + Kernel.exec $0, *args + else + fork ? ruby(*args) : Kernel.exec(FileUtils::RUBY, *args) + end end # We are currently running with no explicit bundler group @@ -59,14 +63,14 @@ namespace :assets do # required in order to compile digestless assets as the # environment has already cached the assets on the primary # run. - ruby_rake_task "assets:precompile:nondigest" if Rails.application.config.assets.digest + ruby_rake_task("assets:precompile:nondigest", false) if Rails.application.config.assets.digest end - task :primary => ["assets:environment", "tmp:cache:clear"] do + task :primary => ["assets:cache:clean"] do internal_precompile end - task :nondigest => ["assets:environment", "tmp:cache:clear"] do + task :nondigest => ["assets:cache:clean"] do internal_precompile(false) end end @@ -77,13 +81,19 @@ namespace :assets do end namespace :clean do - task :all => ["assets:environment", "tmp:cache:clear"] do + task :all => ["assets:cache:clean"] do config = Rails.application.config public_asset_path = File.join(Rails.public_path, config.assets.prefix) rm_rf public_asset_path, :secure => true end end + namespace :cache do + task :clean => ["assets:environment"] do + Rails.application.assets.cache.clear + end + end + task :environment do if Rails.application.config.assets.initialize_on_precompile Rake::Task["environment"].invoke diff --git a/actionpack/lib/sprockets/compressors.rb b/actionpack/lib/sprockets/compressors.rb index cb3e13314b..8b728d6570 100644 --- a/actionpack/lib/sprockets/compressors.rb +++ b/actionpack/lib/sprockets/compressors.rb @@ -1,38 +1,28 @@ module Sprockets module Compressors + extend self + @@css_compressors = {} @@js_compressors = {} @@default_css_compressor = nil @@default_js_compressor = nil - def self.register_css_compressor(name, klass, options = {}) + def register_css_compressor(name, klass, options = {}) @@default_css_compressor = name.to_sym if options[:default] || @@default_css_compressor.nil? - @@css_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]} + @@css_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] } end - def self.register_js_compressor(name, klass, options = {}) + def register_js_compressor(name, klass, options = {}) @@default_js_compressor = name.to_sym if options[:default] || @@default_js_compressor.nil? - @@js_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]} + @@js_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] } end - def self.registered_css_compressor(name) - if name.respond_to?(:to_sym) - compressor = @@css_compressors[name.to_sym] || @@css_compressors[@@default_css_compressor] - require compressor[:require] if compressor[:require] - compressor[:klass].constantize.new - else - name - end + def registered_css_compressor(name) + find_registered_compressor name, @@css_compressors, @@default_css_compressor end - def self.registered_js_compressor(name) - if name.respond_to?(:to_sym) - compressor = @@js_compressors[name.to_sym] || @@js_compressors[@@default_js_compressor] - require compressor[:require] if compressor[:require] - compressor[:klass].constantize.new - else - name - end + def registered_js_compressor(name) + find_registered_compressor name, @@js_compressors, @@default_js_compressor end # The default compressors must be registered in default plugins (ex. Sass-Rails) @@ -43,6 +33,18 @@ module Sprockets register_css_compressor(:yui, 'YUI::CssCompressor', :require => 'yui/compressor') register_js_compressor(:closure, 'Closure::Compiler', :require => 'closure-compiler') register_js_compressor(:yui, 'YUI::JavaScriptCompressor', :require => 'yui/compressor') + + private + + def find_registered_compressor(name, compressors_hash, default_compressor_name) + if name.respond_to?(:to_sym) + compressor = compressors_hash[name.to_sym] || compressors_hash[default_compressor_name] + require compressor[:require] if compressor[:require] + compressor[:klass].constantize.new + else + name + end + end end # An asset compressor which does nothing. diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index ddf9b08b54..976ae5a76d 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -26,10 +26,10 @@ module Sprockets sources.collect do |source| if debug && asset = asset_paths.asset_for(source, 'js') asset.to_a.map { |dep| - super(dep.to_s, { :src => asset_path(dep, :ext => 'js', :body => true, :digest => digest) }.merge!(options)) + super(dep.pathname.to_s, { :src => path_to_asset(dep, :ext => 'js', :body => true, :digest => digest) }.merge!(options)) } else - super(source.to_s, { :src => asset_path(source, :ext => 'js', :body => body, :digest => digest) }.merge!(options)) + super(source.to_s, { :src => path_to_asset(source, :ext => 'js', :body => body, :digest => digest) }.merge!(options)) end end.join("\n").html_safe end @@ -43,10 +43,10 @@ module Sprockets sources.collect do |source| if debug && asset = asset_paths.asset_for(source, 'css') asset.to_a.map { |dep| - super(dep.to_s, { :href => asset_path(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) }.merge!(options)) + super(dep.pathname.to_s, { :href => path_to_asset(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) }.merge!(options)) } else - super(source.to_s, { :href => asset_path(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) }.merge!(options)) + super(source.to_s, { :href => path_to_asset(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) }.merge!(options)) end end.join("\n").html_safe end @@ -56,19 +56,25 @@ module Sprockets path = asset_paths.compute_public_path(source, asset_prefix, options.merge(:body => true)) options[:body] ? "#{path}?body=1" : path end + alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with an asset_path named route def image_path(source) - asset_path(source) + path_to_asset(source) end alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route + def font_path(source) + path_to_asset(source) + end + alias_method :path_to_font, :font_path # aliased to avoid conflicts with an font_path named route + def javascript_path(source) - asset_path(source) + path_to_asset(source, :ext => 'js') end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with an javascript_path named route def stylesheet_path(source) - asset_path(source) + path_to_asset(source, :ext => 'css') end alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with an stylesheet_path named route @@ -113,11 +119,6 @@ module Sprockets class AssetNotPrecompiledError < StandardError; end - # Return the filesystem path for the source - def compute_source_path(source, ext) - asset_for(source, ext) - end - def asset_for(source, ext) source = source.to_s return nil if is_uri?(source) @@ -154,7 +155,7 @@ module Sprockets end def rewrite_extension(source, dir, ext) - if ext && File.extname(source).empty? + if ext && File.extname(source) != ".#{ext}" "#{source}.#{ext}" else source diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 3d330bd91a..2bc482a39d 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -10,8 +10,6 @@ module Sprockets # TODO: Get rid of config.assets.enabled class Railtie < ::Rails::Railtie - config.action_controller.default_asset_host_protocol = :relative - rake_tasks do load "sprockets/assets.rake" end @@ -23,9 +21,12 @@ module Sprockets require 'sprockets' app.assets = Sprockets::Environment.new(app.root.to_s) do |env| - env.logger = ::Rails.logger env.version = ::Rails.env + "-#{config.assets.version}" + if config.assets.logger != false + env.logger = config.assets.logger || ::Rails.logger + end + if config.assets.cache_store != false env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache end diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb index 32a9d66e6e..9bbb464474 100644 --- a/actionpack/lib/sprockets/static_compiler.rb +++ b/actionpack/lib/sprockets/static_compiler.rb @@ -8,9 +8,10 @@ module Sprockets @env = env @target = target @paths = paths - @digest = options.key?(:digest) ? options.delete(:digest) : true - @manifest = options.key?(:manifest) ? options.delete(:manifest) : true + @digest = options.fetch(:digest, true) + @manifest = options.fetch(:manifest, true) @manifest_path = options.delete(:manifest_path) || target + @zip_files = options.delete(:zip_files) || /\.(?:css|html|js|svg|txt|xml)$/ end def compile @@ -36,7 +37,7 @@ module Sprockets filename = File.join(target, path) FileUtils.mkdir_p File.dirname(filename) asset.write_to(filename) - asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/ + asset.write_to("#{filename}.gz") if filename.to_s =~ @zip_files end end |