Skip to content

Commit

Permalink
Merge pull request #1488 from guilleiguaran/multiple_sources_in_sproc…
Browse files Browse the repository at this point in the history
…ket_helpers

Allow multiple sources in Sprockets helpers
  • Loading branch information
josevalim committed Jun 5, 2011
2 parents 75e5610 + db8eeaf commit 9cdd606
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
62 changes: 34 additions & 28 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Expand Up @@ -15,42 +15,48 @@ def asset_paths
end end
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? debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
body = options.key?(:body) ? options.delete(:body) : false body = options.key?(:body) ? options.delete(:body) : false


if debug && asset = asset_paths.asset_for(source, 'js') sources.collect do |source|
asset.to_a.map { |dep| if debug && asset = asset_paths.asset_for(source, 'js')
javascript_include_tag(dep, :debug => false, :body => true) asset.to_a.map { |dep|
}.join("\n").html_safe javascript_include_tag(dep, :debug => false, :body => true)
else }.join("\n").html_safe
options = { else
'type' => "text/javascript", tag_options = {
'src' => asset_path(source, 'js', body) 'type' => "text/javascript",
}.merge(options.stringify_keys) '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 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? debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
body = options.key?(:body) ? options.delete(:body) : false body = options.key?(:body) ? options.delete(:body) : false


if debug && asset = asset_paths.asset_for(source, 'css') sources.collect do |source|
asset.to_a.map { |dep| if debug && asset = asset_paths.asset_for(source, 'css')
stylesheet_link_tag(dep, :debug => false, :body => true) asset.to_a.map { |dep|
}.join("\n").html_safe stylesheet_link_tag(dep, :debug => false, :body => true)
else }.join("\n").html_safe
options = { else
'rel' => "stylesheet", tag_options = {
'type' => "text/css", 'rel' => "stylesheet",
'media' => "screen", 'type' => "text/css",
'href' => asset_path(source, 'css', body) 'media' => "screen",
}.merge(options.stringify_keys) '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 end


private private
Expand Down
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions actionpack/test/template/sprockets_helper_test.rb
Expand Up @@ -94,6 +94,9 @@ def url_for(*args)


assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>", assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>",
javascript_include_tag(:application, :debug => true) javascript_include_tag(:application, :debug => true)

assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>",
javascript_include_tag("xmlhr", "extra")
end end


test "stylesheet path" do test "stylesheet path" do
Expand Down Expand Up @@ -127,5 +130,8 @@ def url_for(*args)


assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />", assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />",
stylesheet_link_tag(:application, :debug => true) stylesheet_link_tag(:application, :debug => true)

assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />",
stylesheet_link_tag("style", "extra")
end end
end end

0 comments on commit 9cdd606

Please sign in to comment.