aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-12-10 06:09:30 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-12-10 06:09:30 +0000
commit9208390f32bc28fc3af85b21d7c6a58675c658ab (patch)
treee21e890b20773764acbf4e2eed1bb89cf51fa773 /actionpack
parentb1ce7e4d4ada3eedc361d90b637ca06274a0ac3d (diff)
downloadrails-9208390f32bc28fc3af85b21d7c6a58675c658ab.tar.gz
rails-9208390f32bc28fc3af85b21d7c6a58675c658ab.tar.bz2
rails-9208390f32bc28fc3af85b21d7c6a58675c658ab.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG3
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb68
2 files changed, 33 insertions, 38 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 6270392742..483c255085 100644
--- a/actionpack/CHANGELOG
+++ b/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]
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 90e511dcc0..41d5e0a17a 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -201,23 +201,10 @@ module ActionView
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 @@ module ActionView
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 @@ module ActionView
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 @@ module ActionView
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