diff options
Diffstat (limited to 'actionpack/lib/sprockets')
-rw-r--r-- | actionpack/lib/sprockets/compressors.rb | 30 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 14 |
2 files changed, 29 insertions, 15 deletions
diff --git a/actionpack/lib/sprockets/compressors.rb b/actionpack/lib/sprockets/compressors.rb index 6544953df4..351eff1085 100644 --- a/actionpack/lib/sprockets/compressors.rb +++ b/actionpack/lib/sprockets/compressors.rb @@ -1,21 +1,37 @@ module Sprockets - class NullCompressor + # An asset compressor which does nothing. + # + # This compressor simply returns the asset as-is, without any compression + # whatsoever. It is useful in development mode, when compression isn't + # needed but using the same asset pipeline as production is desired. + class NullCompressor #:nodoc: def compress(content) content end end - class LazyCompressor + # An asset compressor which only initializes the underlying compression + # engine when needed. + # + # This postpones the initialization of the compressor until + # <code>#compress</code> is called the first time. + class LazyCompressor #:nodoc: + # Initializes a new LazyCompressor. + # + # The block should return a compressor when called, i.e. an object + # which responds to <code>#compress</code>. def initialize(&block) @block = block end - def compressor - @compressor ||= @block.call || NullCompressor.new - end - def compress(content) compressor.compress(content) end + + private + + def compressor + @compressor ||= (@block.call || NullCompressor.new) + end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 53cc5ec019..7a2bf8bef6 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| - javascript_include_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true })) + super(dep.to_s, { :src => asset_path(dep, 'js', true) }.merge!(options)) } else - super(source.to_s, { 'src' => asset_path(source, 'js', body) }.merge!(options.stringify_keys)) + super(source.to_s, { :src => asset_path(source, 'js', body) }.merge!(options)) end end.join("\n").html_safe end @@ -42,10 +42,10 @@ module Sprockets sources.collect do |source| if debug && asset = asset_paths.asset_for(source, 'css') asset.to_a.map { |dep| - stylesheet_link_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true })) + super(dep.to_s, { :href => asset_path(dep, 'css', true, :request) }.merge!(options)) } else - super(source.to_s, { 'href' => asset_path(source, 'css', body, :request) }.merge!(options.stringify_keys)) + super(source.to_s, { :href => asset_path(source, 'css', body, :request) }.merge!(options)) end end.join("\n").html_safe end @@ -58,10 +58,8 @@ module Sprockets private def debug_assets? - Rails.application.config.assets.allow_debugging && - (Rails.application.config.assets.debug || - params[:debug_assets] == '1' || - params[:debug_assets] == 'true') + config = Rails.application.config.assets + config.allow_debugging && (config.debug || params[:debug_assets]) end # Override to specify an alternative prefix for asset path generation. |