diff options
author | Joshua Peek <josh@joshpeek.com> | 2011-05-22 20:11:36 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2011-05-22 20:11:36 -0500 |
commit | 5e519fb0150e6ccb7e2486fc8aa2d60d11b53b75 (patch) | |
tree | dfadca323c6488c167d434e607caaf96c75c8a5c /actionpack/lib/action_view | |
parent | ba3ea9c90b000d8520944b51b2f6d41af148090c (diff) | |
parent | 7ad24a7d962be62fc7538e8a9dc1046daf896497 (diff) | |
download | rails-5e519fb0150e6ccb7e2486fc8aa2d60d11b53b75.tar.gz rails-5e519fb0150e6ccb7e2486fc8aa2d60d11b53b75.tar.bz2 rails-5e519fb0150e6ccb7e2486fc8aa2d60d11b53b75.zip |
Merge branch '3-1-stable'
Conflicts:
actionpack/actionpack.gemspec
activemodel/activemodel.gemspec
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/sprockets_helper.rb | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index ab98da9624..e5d780225b 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -4,28 +4,53 @@ require 'action_view/helpers/asset_paths' module ActionView module Helpers module SprocketsHelper - def asset_path(source, default_ext = nil) - sprockets_asset_paths.compute_public_path(source, 'assets', default_ext, true) + def debug_assets? + params[:debug_assets] == '1' || + params[:debug_assets] == 'true' + end + + def asset_path(source, default_ext = nil, body = false) + source = source.logical_path if source.respond_to?(:logical_path) + path = sprockets_asset_paths.compute_public_path(source, 'assets', default_ext, true) + body ? "#{path}?body=1" : path end def sprockets_javascript_include_tag(source, options = {}) - options = { - 'type' => "text/javascript", - 'src' => asset_path(source, 'js') - }.merge(options.stringify_keys) + debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? + body = options.key?(:body) ? options.delete(:body) : false - content_tag 'script', "", options + if debug && asset = sprockets_asset_paths.asset_for(source, 'js') + asset.to_a.map { |dep| + sprockets_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) + + content_tag 'script', "", options + end end def sprockets_stylesheet_link_tag(source, options = {}) - options = { - 'rel' => "stylesheet", - 'type' => "text/css", - 'media' => "screen", - 'href' => asset_path(source, 'css') - }.merge(options.stringify_keys) + debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? + body = options.key?(:body) ? options.delete(:body) : false - tag 'link', options + if debug && asset = sprockets_asset_paths.asset_for(source, 'css') + asset.to_a.map { |dep| + sprockets_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) + + tag 'link', options + end end private @@ -39,6 +64,13 @@ module ActionView end class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc: + def asset_for(source, ext) + source = source.to_s + return nil if is_uri?(source) + source = rewrite_extension(source, nil, ext) + assets[source] + end + def rewrite_asset_path(source, dir) if source[0] == ?/ source @@ -66,4 +98,4 @@ module ActionView end end end -end
\ No newline at end of file +end |