Skip to content
This repository
Browse code

Merge pull request #2677 from guilleiguaran/refactor-sprockets-helpers

Refactoring javascript_include_tag and stylesheet_link_tag Sprockets helpers
  • Loading branch information...
commit e7634c2fdd7d1f4f177e593d0783e4d94149cba1 2 parents 09e2109 + 23b5c55
Santiago Pastorino spastorino authored

Showing 1 changed file with 6 additions and 19 deletions. Show diff stats Hide diff stats

  1. +6 19 actionpack/lib/sprockets/helpers/rails_helper.rb
25 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -26,15 +26,10 @@ def javascript_include_tag(*sources)
26 26 sources.collect do |source|
27 27 if debug && asset = asset_paths.asset_for(source, 'js')
28 28 asset.to_a.map { |dep|
29   - javascript_include_tag(dep, :debug => false, :body => true)
30   - }.join("\n").html_safe
  29 + javascript_include_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true }))
  30 + }
31 31 else
32   - tag_options = {
33   - 'type' => "text/javascript",
34   - 'src' => asset_path(source, 'js', body)
35   - }.merge(options.stringify_keys)
36   -
37   - content_tag 'script', "", tag_options
  32 + super(source.to_s, { 'src' => asset_path(source, 'js', body) }.merge!(options.stringify_keys))
38 33 end
39 34 end.join("\n").html_safe
40 35 end
@@ -43,22 +38,14 @@ def stylesheet_link_tag(*sources)
43 38 options = sources.extract_options!
44 39 debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
45 40 body = options.key?(:body) ? options.delete(:body) : false
46   - media = options.key?(:media) ? options.delete(:media) : "screen"
47 41
48 42 sources.collect do |source|
49 43 if debug && asset = asset_paths.asset_for(source, 'css')
50 44 asset.to_a.map { |dep|
51   - stylesheet_link_tag(dep, :media => media, :debug => false, :body => true)
52   - }.join("\n").html_safe
  45 + stylesheet_link_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true }))
  46 + }
53 47 else
54   - tag_options = {
55   - 'rel' => "stylesheet",
56   - 'type' => "text/css",
57   - 'media' => media,
58   - 'href' => asset_path(source, 'css', body, :request)
59   - }.merge(options.stringify_keys)
60   -
61   - tag 'link', tag_options
  48 + super(source.to_s, { 'href' => asset_path(source, 'css', body, :request) }.merge!(options.stringify_keys))
62 49 end
63 50 end.join("\n").html_safe
64 51 end

0 comments on commit e7634c2

Please sign in to comment.
Something went wrong with that request. Please try again.