From 6e9714ca1e275ac0ce1479ea932e35dc04dedd8f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 5 Jun 2011 00:58:37 -0500 Subject: [PATCH] Allow multiple sources in Sprockets helpers --- .../lib/sprockets/helpers/rails_helper.rb | 58 ++++++++++--------- .../sprockets/app/javascripts/extra.js | 0 .../sprockets/app/stylesheets/extra.css | 0 .../test/template/sprockets_helper_test.rb | 6 ++ 4 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/extra.js create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/extra.css diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 00d3aaf884..925faae48f 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -15,42 +15,48 @@ module Sprockets end end - def javascript_include_tag(source, options = {}) + def javascript_include_tag(*sources) + options = sources.extract_options! debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = asset_paths.asset_for(source, 'js') - asset.to_a.map { |dep| - javascript_include_tag(dep, :debug => false, :body => true) - }.join("\n").html_safe - else - options = { - 'type' => "text/javascript", - 'src' => asset_path(source, 'js', body) - }.merge(options.stringify_keys) + sources.collect do |source| + if debug && asset = asset_paths.asset_for(source, 'js') + asset.to_a.map { |dep| + javascript_include_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + tag_options = { + 'type' => "text/javascript", + 'src' => asset_path(source, 'js', body) + }.merge(options.stringify_keys) - content_tag 'script', "", options - end + content_tag 'script', "", tag_options + end + end.join("\n").html_safe end - def stylesheet_link_tag(source, options = {}) + def stylesheet_link_tag(*sources) + options = sources.extract_options! debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = asset_paths.asset_for(source, 'css') - asset.to_a.map { |dep| - stylesheet_link_tag(dep, :debug => false, :body => true) - }.join("\n").html_safe - else - options = { - 'rel' => "stylesheet", - 'type' => "text/css", - 'media' => "screen", - 'href' => asset_path(source, 'css', body) - }.merge(options.stringify_keys) + sources.collect do |source| + if debug && asset = asset_paths.asset_for(source, 'css') + asset.to_a.map { |dep| + stylesheet_link_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + tag_options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => asset_path(source, 'css', body) + }.merge(options.stringify_keys) - tag 'link', options - end + tag 'link', tag_options + end + end.join("\n").html_safe end private diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/extra.js b/actionpack/test/fixtures/sprockets/app/javascripts/extra.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css b/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 5a1f31cecb..815bcc1d8a 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -96,6 +96,9 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "\n", javascript_include_tag(:application, :debug => true) + + assert_equal "\n", + javascript_include_tag("xmlhr", "extra") end test "stylesheet path" do @@ -129,5 +132,8 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "\n", stylesheet_link_tag(:application, :debug => true) + + assert_equal "\n", + stylesheet_link_tag("style", "extra") end end