Skip to content

Commit

Permalink
Merge pull request #2677 from guilleiguaran/refactor-sprockets-helpers
Browse files Browse the repository at this point in the history
Refactoring javascript_include_tag and stylesheet_link_tag Sprockets helpers
  • Loading branch information
spastorino committed Aug 24, 2011
2 parents 09e2109 + 23b5c55 commit e7634c2
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Expand Up @@ -26,15 +26,10 @@ def javascript_include_tag(*sources)
sources.collect do |source| sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'js') if debug && asset = asset_paths.asset_for(source, 'js')
asset.to_a.map { |dep| asset.to_a.map { |dep|
javascript_include_tag(dep, :debug => false, :body => true) javascript_include_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true }))
}.join("\n").html_safe }
else else
tag_options = { super(source.to_s, { 'src' => asset_path(source, 'js', body) }.merge!(options.stringify_keys))
'type' => "text/javascript",
'src' => asset_path(source, 'js', body)
}.merge(options.stringify_keys)

content_tag 'script', "", tag_options
end end
end.join("\n").html_safe end.join("\n").html_safe
end end
Expand All @@ -43,22 +38,14 @@ def stylesheet_link_tag(*sources)
options = sources.extract_options! 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
media = options.key?(:media) ? options.delete(:media) : "screen"


sources.collect do |source| sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'css') if debug && asset = asset_paths.asset_for(source, 'css')
asset.to_a.map { |dep| asset.to_a.map { |dep|
stylesheet_link_tag(dep, :media => media, :debug => false, :body => true) stylesheet_link_tag(dep, options.stringify_keys.merge!({ :debug => false, :body => true }))
}.join("\n").html_safe }
else else
tag_options = { super(source.to_s, { 'href' => asset_path(source, 'css', body, :request) }.merge!(options.stringify_keys))
'rel' => "stylesheet",
'type' => "text/css",
'media' => media,
'href' => asset_path(source, 'css', body, :request)
}.merge(options.stringify_keys)

tag 'link', tag_options
end end
end.join("\n").html_safe end.join("\n").html_safe
end end
Expand Down

0 comments on commit e7634c2

Please sign in to comment.