aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb68
1 files changed, 30 insertions, 38 deletions
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