Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure asset cache directories are automatically created. Closes #10337.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8366 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9208390f32bc28fc3af85b21d7c6a58675c658ab 1 parent b1ce7e4
@jeremy jeremy authored
View
3  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Ensure asset cache directories are automatically created. #10337 [Josh Peek]
+
* render :xml and :json preserve custom content types. #10388 [jmettraux, Chu Yeow]
* Refactor Action View template handlers. #10437 [Josh Peek]
@@ -8,6 +10,7 @@
* Clean up some cruft around ActionController::Base#head. Closes #10417 [ssoroka]
+
*2.0.1* (December 7th, 2007)
* Fixed send_file/binary_content for testing #8044 [tolsen]
View
68 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -201,23 +201,10 @@ 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_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)
- end
-
- cache.write(join_asset_file_contents(javascript_paths))
- end
- end
-
- content_tag("script", "", {
- "type" => Mime::JS, "src" => path_to_javascript(joined_javascript_name)
- }.merge(options))
+ write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources))
+ javascript_tag(joined_javascript_name, options)
else
- expand_javascript_sources(sources).collect do |source|
- content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(source) }.merge(options))
- end.join("\n")
+ expand_javascript_sources(sources).collect { |source| javascript_tag(source, options) }.join("\n")
end
end
@@ -311,28 +298,10 @@ def stylesheet_link_tag(*sources)
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name)
- 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)
- end
-
- cache.write(join_asset_file_contents(stylesheet_paths))
- end
- end
-
- tag("link", {
- "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen",
- "href" => html_escape(path_to_stylesheet(joined_stylesheet_name))
- }.merge(options), false, false)
+ write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources))
+ stylesheet_tag(joined_stylesheet_name, options)
else
- options.delete("cache")
-
- expand_stylesheet_sources(sources).collect do |source|
- tag("link", {
- "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(source))
- }.merge(options), false, false)
- end.join("\n")
+ expand_stylesheet_sources(sources).collect { |source| stylesheet_tag(source, options) }.join("\n")
end
end
@@ -492,7 +461,23 @@ def rewrite_asset_path!(source)
source << "?#{asset_id}" if !asset_id.blank?
end
- def expand_javascript_sources(sources)
+ def javascript_tag(source, options)
+ content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(source) }.merge(options))
+ end
+
+ def stylesheet_tag(source, options)
+ tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(source)) }.merge(options), false, false)
+ end
+
+ def compute_javascript_paths(sources)
+ expand_javascript_sources(sources).collect { |source| compute_public_path(source, 'javascripts', 'js', false) }
+ end
+
+ def compute_stylesheet_paths(sources)
+ expand_stylesheet_sources(sources).collect { |source| compute_public_path(source, 'stylesheets', 'css', false) }
+ end
+
+ def expand_javascript_sources(sources)
case
when sources.include?(:all)
all_javascript_files = Dir[File.join(JAVASCRIPTS_DIR, '*.js')].collect { |file| File.basename(file).split(".", 0).first }.sort
@@ -521,6 +506,13 @@ def expand_stylesheet_sources(sources)
def join_asset_file_contents(paths)
paths.collect { |path| File.read(File.join(ASSETS_DIR, path.split("?").first)) }.join("\n\n")
end
+
+ def write_asset_file_contents(joined_asset_path, asset_paths)
+ unless file_exist?(joined_asset_path)
+ FileUtils.mkdir_p(File.dirname(joined_asset_path))
+ File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.