1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2007-12-10 06:09:30 +00:00
parent b1ce7e4d4a
commit 9208390f32
2 changed files with 33 additions and 38 deletions

View file

@ -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 file

@ -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