Permalink
Browse files

Add support for Rails 3.0 asset_ids.

  • Loading branch information...
1 parent c3116c3 commit 7048bad5129158ac507c182468d03a73f5812ffc @airhorns committed Jun 7, 2012
@@ -7,6 +7,7 @@ class AssetPaths #:nodoc:
URI_REGEXP = %r{^[-a-z]+://|^cid:|^//}
attr_reader :config, :controller
+ attr_accessor :asset_id
def initialize(config, controller = nil)
@config = config
@@ -29,6 +30,7 @@ def compute_public_path(source, dir, options = {})
source = rewrite_asset_path(source, dir, options)
source = rewrite_relative_url_root(source, relative_url_root)
source = rewrite_host_and_protocol(source, options[:protocol])
+ source = rewrite_asset_id(source) if asset_id.present?
source
end
@@ -72,6 +74,10 @@ def rewrite_host_and_protocol(source, protocol = nil)
host ? "#{host}#{source}" : source
end
+ def rewrite_asset_id(source)
+ source + "?#{asset_id}"
+ end
+
def compute_protocol(protocol)
protocol ||= default_protocol
case protocol
@@ -15,6 +15,7 @@ def asset_paths
paths.asset_digests = asset_digests
paths.compile_assets = compile_assets?
paths.digest_assets = digest_assets?
+ paths.asset_id = asset_id
paths
end
end
@@ -97,6 +98,10 @@ def asset_prefix
::Rails.application.config.assets.prefix
end
+ def asset_id
+ ::Rails.application.config.assets.asset_id
+ end
+
def asset_digests
::Rails.application.config.assets.digests
end
@@ -145,6 +145,15 @@ def compute_host(source, request, options = {})
path_to_image("logo.png")
end
+ test "image_path with asset_id" do
+ @config.assets.asset_id = "100000"
+ assert_match %r{/assets/logo-[0-9a-f]+.png\?100000},
+ image_path("logo.png")
+
+ assert_match %r{/assets/logo-[0-9a-f]+.png\?100000},
+ path_to_image("logo.png")
+ end
+
test "font_path" do
assert_match %r{/assets/font-[0-9a-f]+.ttf},
font_path("font.ttf")

0 comments on commit 7048bad

Please sign in to comment.