提交 9208390f 编写于 作者: J Jeremy Kemper

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
上级 b1ce7e4d
*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]
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册