Skip to content
Browse files

Make asset extension rewriting faster.

  • Loading branch information...
1 parent 05e53b4 commit 7b2d51817d58336324bce5de422ff82fcab8e18a @thedarkone thedarkone committed Sep 22, 2010
Showing with 11 additions and 5 deletions.
  1. +11 −5 actionpack/lib/action_view/helpers/asset_tag_helper.rb
View
16 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -705,9 +705,15 @@ def audio_tag(source, options = {})
private
- def rewrite_extension?(source, dir, ext)
- source_ext = File.extname(source)[1..-1]
- ext && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}"))))
+ def rewrite_extension(source, dir, ext)
+ source_ext = File.extname(source)
+
+ if source_ext.empty?
+ "#{source}.#{ext}"
+ elsif ext != source_ext[1..-1]
+ with_ext = "#{source}.#{ext}"
+ with_ext if File.exist?(File.join(config.assets_dir, dir, with_ext))
+ end || source
end
def rewrite_host_and_protocol(source, has_request)
@@ -729,8 +735,8 @@ def rewrite_relative_url_root(source, relative_url_root)
def compute_public_path(source, dir, ext = nil, include_host = true)
return source if is_uri?(source)
- source += ".#{ext}" if rewrite_extension?(source, dir, ext)
- source = "/#{dir}/#{source}" unless source[0] == ?/
+ source = rewrite_extension(source, dir, ext) if ext
+ source = "/#{dir}/#{source}" unless source[0] == ?/
if controller.respond_to?(:env) && controller.env["action_dispatch.asset_path"]
source = rewrite_asset_path(source, controller.env["action_dispatch.asset_path"])
end

0 comments on commit 7b2d518

Please sign in to comment.
Something went wrong with that request. Please try again.