actionpack 3.1.0.rc4 → 3.1.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +6 -0
- data/lib/abstract_controller/asset_paths.rb +1 -1
- data/lib/abstract_controller/layouts.rb +10 -8
- data/lib/action_controller/base.rb +13 -11
- data/lib/action_controller/caching/sweeping.rb +1 -0
- data/lib/action_controller/metal/redirecting.rb +1 -0
- data/lib/action_controller/metal/request_forgery_protection.rb +10 -9
- data/lib/action_controller/metal/responder.rb +5 -0
- data/lib/action_controller/metal/streaming.rb +6 -14
- data/lib/action_controller/railtie.rb +0 -1
- data/lib/action_controller/test_case.rb +19 -0
- data/lib/action_dispatch/http/upload.rb +11 -1
- data/lib/action_dispatch/middleware/cookies.rb +5 -0
- data/lib/action_dispatch/routing/mapper.rb +10 -9
- data/lib/action_dispatch/routing/polymorphic_routes.rb +4 -9
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +1 -0
- data/lib/action_view/asset_paths.rb +148 -0
- data/lib/action_view/base.rb +1 -1
- data/lib/action_view/helpers/asset_paths.rb +2 -78
- data/lib/action_view/helpers/asset_tag_helper.rb +8 -2
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +11 -12
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +4 -3
- data/lib/action_view/helpers/cache_helper.rb +4 -6
- data/lib/action_view/helpers/controller_helper.rb +2 -0
- data/lib/action_view/helpers/date_helper.rb +47 -47
- data/lib/action_view/helpers/form_helper.rb +45 -11
- data/lib/action_view/helpers/form_tag_helper.rb +1 -1
- data/lib/action_view/helpers/number_helper.rb +3 -1
- data/lib/action_view/helpers/text_helper.rb +5 -6
- data/lib/action_view/helpers/translation_helper.rb +2 -2
- data/lib/action_view/helpers/url_helper.rb +11 -11
- data/lib/action_view/renderer/partial_renderer.rb +27 -22
- data/lib/sprockets/assets.rake +23 -0
- data/lib/sprockets/compressors.rb +21 -0
- data/lib/sprockets/helpers/rails_helper.rb +44 -19
- data/lib/sprockets/railtie.rb +29 -18
- metadata +29 -54
@@ -4,6 +4,7 @@ require 'action_view/helpers/tag_helper'
|
|
4
4
|
require 'action_view/helpers/form_tag_helper'
|
5
5
|
require 'active_support/core_ext/class/attribute'
|
6
6
|
require 'active_support/core_ext/hash/slice'
|
7
|
+
require 'active_support/core_ext/module/method_names'
|
7
8
|
require 'active_support/core_ext/object/blank'
|
8
9
|
require 'active_support/core_ext/string/output_safety'
|
9
10
|
require 'active_support/core_ext/array/extract_options'
|
@@ -48,7 +49,7 @@ module ActionView
|
|
48
49
|
# <label for="person_last_name">Last name</label>:
|
49
50
|
# <input id="person_last_name" name="person[last_name]" size="30" type="text" /><br />
|
50
51
|
#
|
51
|
-
# <input
|
52
|
+
# <input name="commit" type="submit" value="Create Person" />
|
52
53
|
# </form>
|
53
54
|
#
|
54
55
|
# As you see, the HTML reflects knowledge about the resource in several spots,
|
@@ -79,7 +80,7 @@ module ActionView
|
|
79
80
|
# <label for="person_last_name">Last name</label>:
|
80
81
|
# <input id="person_last_name" name="person[last_name]" size="30" type="text" value="Smith" /><br />
|
81
82
|
#
|
82
|
-
# <input
|
83
|
+
# <input name="commit" type="submit" value="Update Person" />
|
83
84
|
# </form>
|
84
85
|
#
|
85
86
|
# Note that the endpoint, default values, and submit button label are tailored for <tt>@person</tt>.
|
@@ -219,9 +220,9 @@ module ActionView
|
|
219
220
|
# <% end %>
|
220
221
|
#
|
221
222
|
# If you have an object that needs to be represented as a different
|
222
|
-
# parameter, like a
|
223
|
+
# parameter, like a Person that acts as a Client:
|
223
224
|
#
|
224
|
-
# <%= form_for(@
|
225
|
+
# <%= form_for(@person, :as => :client) do |f| %>
|
225
226
|
# ...
|
226
227
|
# <% end %>
|
227
228
|
#
|
@@ -232,7 +233,7 @@ module ActionView
|
|
232
233
|
# <% end %>
|
233
234
|
#
|
234
235
|
# If your resource has associations defined, for example, you want to add comments
|
235
|
-
# to the
|
236
|
+
# to the document given that the routes are set correctly:
|
236
237
|
#
|
237
238
|
# <%= form_for([@document, @comment]) do |f| %>
|
238
239
|
# ...
|
@@ -258,8 +259,8 @@ module ActionView
|
|
258
259
|
# :remote => true
|
259
260
|
#
|
260
261
|
# in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its
|
261
|
-
#
|
262
|
-
# POST arrangement, but ultimately the
|
262
|
+
# behavior. The expected default behavior is an XMLHttpRequest in the background instead of the regular
|
263
|
+
# POST arrangement, but ultimately the behavior is the choice of the JavaScript driver implementor.
|
263
264
|
# Even though it's using JavaScript to serialize the form elements, the form submission will work just like
|
264
265
|
# a regular submission as viewed by the receiving side (all elements available in <tt>params</tt>).
|
265
266
|
#
|
@@ -290,7 +291,7 @@ module ActionView
|
|
290
291
|
#
|
291
292
|
# Example:
|
292
293
|
#
|
293
|
-
# <%=
|
294
|
+
# <%= form_for(@post) do |f| %>
|
294
295
|
# <% f.fields_for(:comments, :include_id => false) do |cf| %>
|
295
296
|
# ...
|
296
297
|
# <% end %>
|
@@ -846,7 +847,28 @@ module ActionView
|
|
846
847
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_radio_button_tag(tag_value, options)
|
847
848
|
end
|
848
849
|
|
849
|
-
# Returns
|
850
|
+
# Returns an input of type "search" for accessing a specified attribute (identified by +method+) on an object
|
851
|
+
# assigned to the template (identified by +object+). Inputs of type "search" may be styled differently by
|
852
|
+
# some browsers
|
853
|
+
#
|
854
|
+
# ==== Examples
|
855
|
+
#
|
856
|
+
# search_field(:user, :name)
|
857
|
+
# # => <input id="user_name" name="user[name]" size="30" type="search" />
|
858
|
+
# search_field(:user, :name, :autosave => false)
|
859
|
+
# # => <input autosave="false" id="user_name" name="user[name]" size="30" type="search" />
|
860
|
+
# search_field(:user, :name, :results => 3)
|
861
|
+
# # => <input id="user_name" name="user[name]" results="3" size="30" type="search" />
|
862
|
+
# # Assume request.host returns "www.example.com"
|
863
|
+
# search_field(:user, :name, :autosave => true)
|
864
|
+
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" size="30" type="search" />
|
865
|
+
# search_field(:user, :name, :onsearch => true)
|
866
|
+
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
|
867
|
+
# search_field(:user, :name, :autosave => false, :onsearch => true)
|
868
|
+
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
|
869
|
+
# search_field(:user, :name, :autosave => true, :onsearch => true)
|
870
|
+
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" size="30" type="search" />
|
871
|
+
|
850
872
|
def search_field(object_name, method, options = {})
|
851
873
|
options = options.stringify_keys
|
852
874
|
|
@@ -865,17 +887,29 @@ module ActionView
|
|
865
887
|
end
|
866
888
|
|
867
889
|
# Returns a text_field of type "tel".
|
890
|
+
#
|
891
|
+
# telephone_field("user", "phone")
|
892
|
+
# # => <input id="user_phone" name="user[phone]" size="30" type="tel" />
|
893
|
+
|
868
894
|
def telephone_field(object_name, method, options = {})
|
869
895
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("tel", options)
|
870
896
|
end
|
871
897
|
alias phone_field telephone_field
|
872
898
|
|
873
899
|
# Returns a text_field of type "url".
|
900
|
+
#
|
901
|
+
# url_field("user", "homepage")
|
902
|
+
# # => <input id="user_homepage" size="30" name="user[homepage]" type="url" />
|
903
|
+
|
874
904
|
def url_field(object_name, method, options = {})
|
875
905
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("url", options)
|
876
906
|
end
|
877
907
|
|
878
908
|
# Returns a text_field of type "email".
|
909
|
+
#
|
910
|
+
# email_field("user", "address")
|
911
|
+
# # => <input id="user_address" size="30" name="user[address]" type="email" />
|
912
|
+
|
879
913
|
def email_field(object_name, method, options = {})
|
880
914
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("email", options)
|
881
915
|
end
|
@@ -1136,7 +1170,7 @@ module ActionView
|
|
1136
1170
|
options["name"] ||= tag_name_with_index(@auto_index)
|
1137
1171
|
options["id"] = options.fetch("id"){ tag_id_with_index(@auto_index) }
|
1138
1172
|
else
|
1139
|
-
options["name"] ||= tag_name + (options
|
1173
|
+
options["name"] ||= tag_name + (options['multiple'] ? '[]' : '')
|
1140
1174
|
options["id"] = options.fetch("id"){ tag_id }
|
1141
1175
|
end
|
1142
1176
|
end
|
@@ -1217,7 +1251,7 @@ module ActionView
|
|
1217
1251
|
end
|
1218
1252
|
|
1219
1253
|
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
|
1220
|
-
fields_options, record_object = record_object, nil if record_object.is_a?(Hash)
|
1254
|
+
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
|
1221
1255
|
fields_options[:builder] ||= options[:builder]
|
1222
1256
|
fields_options[:parent_builder] = self
|
1223
1257
|
|
@@ -30,7 +30,7 @@ module ActionView
|
|
30
30
|
# (by passing <tt>false</tt>).
|
31
31
|
# * A list of parameters to feed to the URL the form will be posted to.
|
32
32
|
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
|
33
|
-
# submit
|
33
|
+
# submit behavior. By default this behavior is an ajax submit.
|
34
34
|
#
|
35
35
|
# ==== Examples
|
36
36
|
# form_tag('/posts')
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'active_support/core_ext/big_decimal/conversions'
|
2
4
|
require 'active_support/core_ext/float/rounding'
|
3
5
|
require 'active_support/core_ext/object/blank'
|
@@ -211,7 +213,7 @@ module ActionView
|
|
211
213
|
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
|
212
214
|
options = options.reverse_merge(defaults)
|
213
215
|
|
214
|
-
parts = number.to_s.split('.')
|
216
|
+
parts = number.to_s.to_str.split('.')
|
215
217
|
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
|
216
218
|
parts.join(options[:separator]).html_safe
|
217
219
|
|
@@ -255,16 +255,15 @@ module ActionView
|
|
255
255
|
# simple_format("<span>I'm allowed!</span> It's true.", {}, :sanitize => false)
|
256
256
|
# # => "<p><span>I'm allowed!</span> It's true.</p>"
|
257
257
|
def simple_format(text, html_options={}, options={})
|
258
|
-
text =
|
259
|
-
text = text.dup if text.frozen?
|
258
|
+
text = '' if text.nil?
|
260
259
|
start_tag = tag('p', html_options, true)
|
260
|
+
text = sanitize(text) unless options[:sanitize] == false
|
261
|
+
text = text.to_str
|
261
262
|
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
262
263
|
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
|
263
264
|
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
264
265
|
text.insert 0, start_tag
|
265
|
-
text.
|
266
|
-
text = sanitize(text) unless options[:sanitize] == false
|
267
|
-
text
|
266
|
+
text.html_safe.safe_concat("</p>")
|
268
267
|
end
|
269
268
|
|
270
269
|
# Creates a Cycle object whose _to_s_ method cycles through elements of an
|
@@ -281,7 +280,7 @@ module ActionView
|
|
281
280
|
# @items = [1,2,3,4]
|
282
281
|
# <table>
|
283
282
|
# <% @items.each do |item| %>
|
284
|
-
# <tr class="<%= cycle("
|
283
|
+
# <tr class="<%= cycle("odd", "even") -%>">
|
285
284
|
# <td>item</td>
|
286
285
|
# </tr>
|
287
286
|
# <% end %>
|
@@ -5,7 +5,7 @@ module I18n
|
|
5
5
|
class ExceptionHandler
|
6
6
|
include Module.new {
|
7
7
|
def call(exception, locale, key, options)
|
8
|
-
exception.is_a?(MissingTranslation) ? super.html_safe : super
|
8
|
+
exception.is_a?(MissingTranslation) && options[:rescue_format] == :html ? super.html_safe : super
|
9
9
|
end
|
10
10
|
}
|
11
11
|
end
|
@@ -25,7 +25,7 @@ module ActionView
|
|
25
25
|
# * a titleized version of the last key segment as a text.
|
26
26
|
#
|
27
27
|
# E.g. the value returned for a missing translation key :"blog.post.title" will be
|
28
|
-
# <span class="translation_missing" title="translation missing: blog.post.title">Title</span>.
|
28
|
+
# <span class="translation_missing" title="translation missing: en.blog.post.title">Title</span>.
|
29
29
|
# This way your views will display rather reasonable strings but it will still
|
30
30
|
# be easy to spot missing translations.
|
31
31
|
#
|
@@ -55,9 +55,9 @@ module ActionView
|
|
55
55
|
#
|
56
56
|
# ==== Relying on named routes
|
57
57
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
58
|
+
# Passing a record (like an Active Record or Active Resource) instead of a Hash as the options parameter will
|
59
|
+
# trigger the named route for that record. The lookup will happen on the name of the class. So passing a
|
60
|
+
# Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as
|
61
61
|
# +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route).
|
62
62
|
#
|
63
63
|
# ==== Examples
|
@@ -112,13 +112,13 @@ module ActionView
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
# Creates a link tag of the given +name+ using a URL created by the set
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# of
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
115
|
+
# Creates a link tag of the given +name+ using a URL created by the set of +options+.
|
116
|
+
# See the valid options in the documentation for +url_for+. It's also possible to
|
117
|
+
# pass a String instead of an options hash, which generates a link tag that uses the
|
118
|
+
# value of the String as the href for the link. Using a <tt>:back</tt> Symbol instead
|
119
|
+
# of an options hash will generate a link to the referrer (a JavaScript back link
|
120
|
+
# will be used in place of a referrer if none exists). If +nil+ is passed as the name
|
121
|
+
# the value of the link itself will become the name.
|
122
122
|
#
|
123
123
|
# ==== Signatures
|
124
124
|
#
|
@@ -278,7 +278,7 @@ module ActionView
|
|
278
278
|
# prompt with the question specified. If the user accepts, the link is
|
279
279
|
# processed normally, otherwise no action is taken.
|
280
280
|
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
|
281
|
-
# submit
|
281
|
+
# submit behavior. By default this behavior is an ajax submit.
|
282
282
|
# * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
|
283
283
|
# be placed
|
284
284
|
#
|
@@ -12,8 +12,7 @@ module ActionView
|
|
12
12
|
#
|
13
13
|
# <%= render :partial => "account" %>
|
14
14
|
#
|
15
|
-
# This would render "advertiser/_account.html.erb"
|
16
|
-
# +account+ to the template for display.
|
15
|
+
# This would render "advertiser/_account.html.erb".
|
17
16
|
#
|
18
17
|
# In another template for Advertiser#buy, we could have:
|
19
18
|
#
|
@@ -28,32 +27,24 @@ module ActionView
|
|
28
27
|
#
|
29
28
|
# == The :as and :object options
|
30
29
|
#
|
31
|
-
# By default <tt>ActionView::Partials::PartialRenderer</tt>
|
32
|
-
#
|
30
|
+
# By default <tt>ActionView::Partials::PartialRenderer</tt> doesn't have any local variables.
|
31
|
+
# The <tt>:object</tt> option can be used to pass an object to the partial. For instance:
|
33
32
|
#
|
34
|
-
# <%= render :partial => "
|
33
|
+
# <%= render :partial => "account", :object => @buyer %>
|
35
34
|
#
|
36
|
-
#
|
35
|
+
# would provide the +@buyer+ object to the partial, available under the local variable +account+ and is
|
36
|
+
# equivalent to:
|
37
37
|
#
|
38
|
-
# <%= render :partial => "
|
38
|
+
# <%= render :partial => "account", :locals => { :account => @buyer } %>
|
39
39
|
#
|
40
40
|
# With the <tt>:as</tt> option we can specify a different name for said local variable. For example, if we
|
41
|
-
# wanted it to be +
|
42
|
-
#
|
43
|
-
# <%= render :partial => "contract", :as => 'agreement' %>
|
44
|
-
#
|
45
|
-
# The <tt>:object</tt> option can be used to directly specify which object is rendered into the partial;
|
46
|
-
# useful when the template's object is elsewhere, in a different ivar or in a local variable for instance.
|
41
|
+
# wanted it to be +user+ instead of +account+ we'd do:
|
47
42
|
#
|
48
|
-
#
|
43
|
+
# <%= render :partial => "account", :object => @buyer, :as => 'user' %>
|
49
44
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# <% @advertisements.each do |ad| %>
|
53
|
-
# <%= render :partial => "ad", :object => ad %>
|
54
|
-
# <% end %>
|
45
|
+
# This is equivalent to
|
55
46
|
#
|
56
|
-
#
|
47
|
+
# <%= render :partial => "account", :locals => { :user => @buyer } %>
|
57
48
|
#
|
58
49
|
# == Rendering a collection of partials
|
59
50
|
#
|
@@ -366,14 +357,28 @@ module ActionView
|
|
366
357
|
def partial_path(object = @object)
|
367
358
|
@partial_names[object.class.name] ||= begin
|
368
359
|
object = object.to_model if object.respond_to?(:to_model)
|
369
|
-
|
370
360
|
object.class.model_name.partial_path.dup.tap do |partial|
|
371
361
|
path = @lookup_context.prefixes.first
|
372
|
-
|
362
|
+
merge_path_into_partial(path, partial)
|
373
363
|
end
|
374
364
|
end
|
375
365
|
end
|
376
366
|
|
367
|
+
def merge_path_into_partial(path, partial)
|
368
|
+
if path.include?(?/) && partial.include?(?/)
|
369
|
+
overlap = []
|
370
|
+
path_array = File.dirname(path).split('/')
|
371
|
+
partial_array = partial.split('/')[0..-3] # skip model dir & partial
|
372
|
+
|
373
|
+
path_array.each_with_index do |dir, index|
|
374
|
+
overlap << dir if dir == partial_array[index]
|
375
|
+
end
|
376
|
+
|
377
|
+
partial.gsub!(/^#{overlap.join('/')}\//,'')
|
378
|
+
partial.insert(0, "#{File.dirname(path)}/")
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
377
382
|
def retrieve_variable(path)
|
378
383
|
variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym
|
379
384
|
variable_counter = :"#{variable}_counter" if @collection
|
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :assets do
|
2
|
+
# Ensures the RAILS_GROUPS environment variable is set
|
3
|
+
task :ensure_env do
|
4
|
+
ENV["RAILS_GROUPS"] ||= "assets"
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Compile all the assets named in config.assets.precompile"
|
8
|
+
task :precompile => :ensure_env do
|
9
|
+
Rake::Task["environment"].invoke
|
10
|
+
Sprockets::Helpers::RailsHelper
|
11
|
+
|
12
|
+
assets = Rails.application.config.assets.precompile
|
13
|
+
Rails.application.config.action_controller.perform_caching = true
|
14
|
+
Rails.application.assets.precompile(*assets)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Remove compiled assets"
|
18
|
+
task :clean => :environment do
|
19
|
+
assets = Rails.application.config.assets
|
20
|
+
public_asset_path = Rails.public_path + assets.prefix
|
21
|
+
rm_rf public_asset_path, :secure => true
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sprockets
|
2
|
+
class NullCompressor
|
3
|
+
def compress(content)
|
4
|
+
content
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class LazyCompressor
|
9
|
+
def initialize(&block)
|
10
|
+
@block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def compressor
|
14
|
+
@compressor ||= @block.call || NullCompressor.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def compress(content)
|
18
|
+
compressor.compress(content)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,17 +1,20 @@
|
|
1
|
-
require "action_view
|
2
|
-
require "action_view/helpers/asset_tag_helper"
|
1
|
+
require "action_view"
|
3
2
|
|
4
3
|
module Sprockets
|
5
4
|
module Helpers
|
6
5
|
module RailsHelper
|
7
6
|
extend ActiveSupport::Concern
|
8
7
|
include ActionView::Helpers::AssetTagHelper
|
9
|
-
|
8
|
+
|
10
9
|
def asset_paths
|
11
10
|
@asset_paths ||= begin
|
12
11
|
config = self.config if respond_to?(:config)
|
12
|
+
config ||= Rails.application.config
|
13
13
|
controller = self.controller if respond_to?(:controller)
|
14
|
-
RailsHelper::AssetPaths.new(config, controller)
|
14
|
+
paths = RailsHelper::AssetPaths.new(config, controller)
|
15
|
+
paths.asset_environment = asset_environment
|
16
|
+
paths.asset_prefix = asset_prefix
|
17
|
+
paths
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
@@ -51,7 +54,7 @@ module Sprockets
|
|
51
54
|
'rel' => "stylesheet",
|
52
55
|
'type' => "text/css",
|
53
56
|
'media' => "screen",
|
54
|
-
'href' => asset_path(source, 'css', body)
|
57
|
+
'href' => asset_path(source, 'css', body, :request)
|
55
58
|
}.merge(options.stringify_keys)
|
56
59
|
|
57
60
|
tag 'link', tag_options
|
@@ -59,35 +62,61 @@ module Sprockets
|
|
59
62
|
end.join("\n").html_safe
|
60
63
|
end
|
61
64
|
|
65
|
+
def asset_path(source, default_ext = nil, body = false, protocol = nil)
|
66
|
+
source = source.logical_path if source.respond_to?(:logical_path)
|
67
|
+
path = asset_paths.compute_public_path(source, 'assets', default_ext, true, protocol)
|
68
|
+
body ? "#{path}?body=1" : path
|
69
|
+
end
|
70
|
+
|
62
71
|
private
|
63
72
|
def debug_assets?
|
64
73
|
params[:debug_assets] == '1' ||
|
65
74
|
params[:debug_assets] == 'true'
|
75
|
+
rescue NoMethodError
|
76
|
+
false
|
66
77
|
end
|
67
78
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
# Override to specify an alternative prefix for asset path generation.
|
80
|
+
# When combined with a custom +asset_environment+, this can be used to
|
81
|
+
# implement themes that can take advantage of the asset pipeline.
|
82
|
+
#
|
83
|
+
# If you only want to change where the assets are mounted, refer to
|
84
|
+
# +config.assets.prefix+ instead.
|
85
|
+
def asset_prefix
|
86
|
+
Rails.application.config.assets.prefix
|
72
87
|
end
|
73
88
|
|
74
|
-
|
75
|
-
|
76
|
-
|
89
|
+
# Override to specify an alternative asset environment for asset
|
90
|
+
# path generation. The environment should already have been mounted
|
91
|
+
# at the prefix returned by +asset_prefix+.
|
92
|
+
def asset_environment
|
93
|
+
Rails.application.assets
|
94
|
+
end
|
95
|
+
|
96
|
+
class AssetPaths < ::ActionView::AssetPaths #:nodoc:
|
97
|
+
attr_accessor :asset_environment, :asset_prefix
|
98
|
+
|
99
|
+
def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil)
|
100
|
+
super(source, asset_prefix, ext, include_host, protocol)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Return the filesystem path for the source
|
104
|
+
def compute_source_path(source, ext)
|
105
|
+
asset_for(source, ext)
|
77
106
|
end
|
78
107
|
|
79
108
|
def asset_for(source, ext)
|
80
109
|
source = source.to_s
|
81
110
|
return nil if is_uri?(source)
|
82
111
|
source = rewrite_extension(source, nil, ext)
|
83
|
-
|
112
|
+
asset_environment[source]
|
84
113
|
end
|
85
114
|
|
86
115
|
def rewrite_asset_path(source, dir)
|
87
116
|
if source[0] == ?/
|
88
117
|
source
|
89
118
|
else
|
90
|
-
|
119
|
+
asset_environment.path(source, performing_caching?, dir)
|
91
120
|
end
|
92
121
|
end
|
93
122
|
|
@@ -99,13 +128,9 @@ module Sprockets
|
|
99
128
|
end
|
100
129
|
end
|
101
130
|
|
102
|
-
def assets
|
103
|
-
Rails.application.assets
|
104
|
-
end
|
105
|
-
|
106
131
|
# When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
|
107
132
|
def performing_caching?
|
108
|
-
|
133
|
+
config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching
|
109
134
|
end
|
110
135
|
end
|
111
136
|
end
|