Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cache more file existence checks. Flip-flop escaping.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7610 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8db51ee3c0d3e2f339da5537177b38129c5d21fa 1 parent 871b87a
@jeremy jeremy authored
Showing with 16 additions and 9 deletions.
  1. +16 −9 actionpack/lib/action_view/helpers/asset_tag_helper.rb
View
25 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -179,7 +179,7 @@ def javascript_include_tag(*sources)
joined_javascript_name = (cache == true ? "all" : cache) + ".js"
joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name)
- if !File.exists?(joined_javascript_path)
+ if !file_exist?(joined_javascript_path)
File.open(joined_javascript_path, "w+") do |cache|
javascript_paths = expand_javascript_sources(sources).collect do |source|
compute_public_path(source, 'javascripts', 'js', false)
@@ -288,8 +288,7 @@ def stylesheet_link_tag(*sources)
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name)
- @@file_exist_cache ||= {}
- if !(@@file_exist_cache[joined_stylesheet_name] ||= File.exist?(joined_stylesheet_path))
+ if !file_exist?(joined_stylesheet_path)
File.open(joined_stylesheet_path, "w+") do |cache|
stylesheet_paths = expand_stylesheet_sources(sources).collect do |source|
compute_public_path(source, 'stylesheets', 'css', false)
@@ -297,21 +296,19 @@ def stylesheet_link_tag(*sources)
cache.write(join_asset_file_contents(stylesheet_paths))
end
-
- @@file_exist_cache[joined_stylesheet_name] = true
end
tag("link", {
"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen",
"href" => html_escape(stylesheet_path(joined_stylesheet_name))
- }.merge(options), false, true)
+ }.merge(options), false, false)
else
options.delete("cache")
expand_stylesheet_sources(sources).collect do |source|
tag("link", {
"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(stylesheet_path(source))
- }.merge(options), false, true)
+ }.merge(options), false, false)
end.join("\n")
end
end
@@ -371,6 +368,16 @@ def image_tag(source, options = {})
end
private
+ def file_exist?(path)
+ @@file_exist_cache ||= {}
+ if !(@@file_exist_cache[path] ||= File.exist?(path))
+ @@file_exist_cache[path] = true
+ false
+ else
+ true
+ end
+ end
+
# Add the .ext if not present. Return full URLs otherwise untouched.
# Prefix with /dir/ if lacking a leading /. Account for relative URL
# roots. Rewrite the asset path for cache-busting asset ids. Include
@@ -416,7 +423,7 @@ def rails_asset_id(source)
asset_id
else
@@asset_id_cache[source] ||=
- if File.exist?(path = File.join(ASSETS_DIR, source))
+ if file_exist?(path = File.join(ASSETS_DIR, source))
File.mtime(path).to_i.to_s
else
''
@@ -444,7 +451,7 @@ def expand_javascript_sources(sources)
sources[(sources.index(:defaults) + 1)..sources.length]
sources.delete(:defaults)
- sources << "application" if File.exists?(File.join(JAVASCRIPTS_DIR, "application.js"))
+ sources << "application" if file_exist?(File.join(JAVASCRIPTS_DIR, "application.js"))
end
sources
Please sign in to comment.
Something went wrong with that request. Please try again.