lib/sprockets/helpers/rails_helper.rb in actionpack-3.1.0.rc8 vs lib/sprockets/helpers/rails_helper.rb in actionpack-3.1.0

- old
+ new

@@ -12,10 +12,11 @@ config ||= Rails.application.config controller = self.controller if respond_to?(:controller) paths = RailsHelper::AssetPaths.new(config, controller) paths.asset_environment = asset_environment paths.asset_prefix = asset_prefix + paths.asset_digests = asset_digests paths end end def javascript_include_tag(*sources) @@ -69,14 +70,18 @@ body ? "#{path}?body=1" : path end private def debug_assets? - Rails.application.config.assets.allow_debugging && - (Rails.application.config.assets.debug || - params[:debug_assets] == '1' || - params[:debug_assets] == 'true') + begin + Rails.application.config.assets.compile && + (Rails.application.config.assets.debug || + params[:debug_assets] == '1' || + params[:debug_assets] == 'true') + rescue NoMethodError + false + end end # Override to specify an alternative prefix for asset path generation. # When combined with a custom +asset_environment+, this can be used to # implement themes that can take advantage of the asset pipeline. @@ -85,20 +90,26 @@ # +config.assets.prefix+ instead. def asset_prefix Rails.application.config.assets.prefix end + def asset_digests + Rails.application.config.assets.digests + end + # Override to specify an alternative asset environment for asset # path generation. The environment should already have been mounted # at the prefix returned by +asset_prefix+. def asset_environment Rails.application.assets end class AssetPaths < ::ActionView::AssetPaths #:nodoc: - attr_accessor :asset_environment, :asset_prefix + attr_accessor :asset_environment, :asset_prefix, :asset_digests + class AssetNotPrecompiledError < StandardError; end + def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil) super(source, asset_prefix, ext, include_host, protocol) end # Return the filesystem path for the source @@ -112,22 +123,29 @@ source = rewrite_extension(source, nil, ext) asset_environment[source] end def digest_for(logical_path) - if asset = asset_environment[logical_path] - return asset.digest_path + if asset_digests && (digest = asset_digests[logical_path]) + return digest end - logical_path + if Rails.application.config.assets.compile + if asset = asset_environment[logical_path] + return asset.digest_path + end + return logical_path + else + raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled") + end end def rewrite_asset_path(source, dir) if source[0] == ?/ source else - source = digest_for(source) if performing_caching? + source = digest_for(source) if Rails.application.config.assets.digest source = File.join(dir, source) source = "/#{source}" unless source =~ /^\// source end end @@ -136,14 +154,9 @@ if ext && File.extname(source).empty? "#{source}.#{ext}" else source end - end - - # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available - def performing_caching? - config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching end end end end end