actionview 4.1.13 → 6.1.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionview might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +181 -359
- data/MIT-LICENSE +1 -1
- data/README.rdoc +12 -6
- data/lib/action_view/base.rb +115 -43
- data/lib/action_view/buffers.rb +22 -4
- data/lib/action_view/cache_expiry.rb +52 -0
- data/lib/action_view/context.rb +8 -12
- data/lib/action_view/dependency_tracker.rb +61 -21
- data/lib/action_view/digestor.rb +89 -84
- data/lib/action_view/flows.rb +12 -13
- data/lib/action_view/gem_version.rb +6 -4
- data/lib/action_view/helpers/active_model_helper.rb +16 -11
- data/lib/action_view/helpers/asset_tag_helper.rb +311 -105
- data/lib/action_view/helpers/asset_url_helper.rb +197 -80
- data/lib/action_view/helpers/atom_feed_helper.rb +20 -17
- data/lib/action_view/helpers/cache_helper.rb +109 -45
- data/lib/action_view/helpers/capture_helper.rb +20 -22
- data/lib/action_view/helpers/controller_helper.rb +15 -4
- data/lib/action_view/helpers/csp_helper.rb +26 -0
- data/lib/action_view/helpers/csrf_helper.rb +8 -6
- data/lib/action_view/helpers/date_helper.rb +245 -140
- data/lib/action_view/helpers/debug_helper.rb +14 -17
- data/lib/action_view/helpers/form_helper.rb +875 -148
- data/lib/action_view/helpers/form_options_helper.rb +128 -82
- data/lib/action_view/helpers/form_tag_helper.rb +253 -91
- data/lib/action_view/helpers/javascript_helper.rb +37 -15
- data/lib/action_view/helpers/number_helper.rb +100 -77
- data/lib/action_view/helpers/output_safety_helper.rb +42 -10
- data/lib/action_view/helpers/rendering_helper.rb +26 -15
- data/lib/action_view/helpers/sanitize_helper.rb +79 -164
- data/lib/action_view/helpers/tag_helper.rb +277 -64
- data/lib/action_view/helpers/tags/base.rb +143 -92
- data/lib/action_view/helpers/tags/check_box.rb +20 -19
- data/lib/action_view/helpers/tags/checkable.rb +4 -2
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -30
- data/lib/action_view/helpers/tags/collection_helpers.rb +69 -36
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -12
- data/lib/action_view/helpers/tags/collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/color_field.rb +4 -3
- data/lib/action_view/helpers/tags/date_field.rb +3 -2
- data/lib/action_view/helpers/tags/date_select.rb +38 -37
- data/lib/action_view/helpers/tags/datetime_field.rb +14 -5
- data/lib/action_view/helpers/tags/datetime_local_field.rb +3 -2
- data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
- data/lib/action_view/helpers/tags/email_field.rb +2 -0
- data/lib/action_view/helpers/tags/file_field.rb +2 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/hidden_field.rb +2 -0
- data/lib/action_view/helpers/tags/label.rb +41 -22
- data/lib/action_view/helpers/tags/month_field.rb +3 -2
- data/lib/action_view/helpers/tags/number_field.rb +2 -0
- data/lib/action_view/helpers/tags/password_field.rb +3 -1
- data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
- data/lib/action_view/helpers/tags/radio_button.rb +7 -6
- data/lib/action_view/helpers/tags/range_field.rb +2 -0
- data/lib/action_view/helpers/tags/search_field.rb +3 -0
- data/lib/action_view/helpers/tags/select.rb +11 -10
- data/lib/action_view/helpers/tags/tel_field.rb +2 -0
- data/lib/action_view/helpers/tags/text_area.rb +7 -1
- data/lib/action_view/helpers/tags/text_field.rb +11 -7
- data/lib/action_view/helpers/tags/time_field.rb +3 -2
- data/lib/action_view/helpers/tags/time_select.rb +2 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
- data/lib/action_view/helpers/tags/translator.rb +39 -0
- data/lib/action_view/helpers/tags/url_field.rb +2 -0
- data/lib/action_view/helpers/tags/week_field.rb +3 -2
- data/lib/action_view/helpers/tags.rb +4 -1
- data/lib/action_view/helpers/text_helper.rb +80 -45
- data/lib/action_view/helpers/translation_helper.rb +148 -67
- data/lib/action_view/helpers/url_helper.rb +289 -147
- data/lib/action_view/helpers.rb +5 -3
- data/lib/action_view/layouts.rb +68 -63
- data/lib/action_view/log_subscriber.rb +80 -13
- data/lib/action_view/lookup_context.rb +137 -92
- data/lib/action_view/model_naming.rb +4 -2
- data/lib/action_view/path_set.rb +30 -16
- data/lib/action_view/railtie.rb +62 -13
- data/lib/action_view/record_identifier.rb +53 -26
- data/lib/action_view/renderer/abstract_renderer.rb +152 -13
- data/lib/action_view/renderer/collection_renderer.rb +196 -0
- data/lib/action_view/renderer/object_renderer.rb +34 -0
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +102 -0
- data/lib/action_view/renderer/partial_renderer.rb +61 -261
- data/lib/action_view/renderer/renderer.rb +67 -6
- data/lib/action_view/renderer/streaming_template_renderer.rb +58 -54
- data/lib/action_view/renderer/template_renderer.rb +83 -75
- data/lib/action_view/rendering.rb +73 -46
- data/lib/action_view/routing_url_for.rb +54 -17
- data/lib/action_view/tasks/cache_digests.rake +25 -0
- data/lib/action_view/template/error.rb +44 -29
- data/lib/action_view/template/handlers/builder.rb +12 -13
- data/lib/action_view/template/handlers/erb/erubi.rb +89 -0
- data/lib/action_view/template/handlers/erb.rb +23 -89
- data/lib/action_view/template/handlers/html.rb +11 -0
- data/lib/action_view/template/handlers/raw.rb +4 -4
- data/lib/action_view/template/handlers.rb +22 -9
- data/lib/action_view/template/html.rb +10 -11
- data/lib/action_view/template/inline.rb +22 -0
- data/lib/action_view/template/raw_file.rb +25 -0
- data/lib/action_view/template/renderable.rb +24 -0
- data/lib/action_view/template/resolver.rb +267 -181
- data/lib/action_view/template/sources/file.rb +17 -0
- data/lib/action_view/template/sources.rb +13 -0
- data/lib/action_view/template/text.rb +8 -10
- data/lib/action_view/template/types.rb +18 -18
- data/lib/action_view/template.rb +109 -99
- data/lib/action_view/test_case.rb +73 -53
- data/lib/action_view/testing/resolvers.rb +24 -33
- data/lib/action_view/unbound_template.rb +31 -0
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +74 -44
- data/lib/action_view.rb +14 -9
- data/lib/assets/compiled/rails-ujs.js +746 -0
- metadata +71 -26
- data/lib/action_view/helpers/record_tag_helper.rb +0 -108
- data/lib/action_view/tasks/dependencies.rake +0 -23
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_view/vendor/html-scanner.rb +0 -20
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zlib"
|
2
4
|
|
3
5
|
module ActionView
|
4
6
|
# = Action View Asset URL Helpers
|
5
|
-
module Helpers
|
7
|
+
module Helpers #:nodoc:
|
6
8
|
# This module provides methods for generating asset paths and
|
7
|
-
#
|
9
|
+
# URLs.
|
8
10
|
#
|
9
11
|
# image_path("rails.png")
|
10
12
|
# # => "/assets/rails.png"
|
@@ -27,30 +29,37 @@ module ActionView
|
|
27
29
|
# Helpers take that into account:
|
28
30
|
#
|
29
31
|
# image_tag("rails.png")
|
30
|
-
# # => <img
|
32
|
+
# # => <img src="http://assets.example.com/assets/rails.png" />
|
31
33
|
# stylesheet_link_tag("application")
|
32
34
|
# # => <link href="http://assets.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
33
35
|
#
|
34
|
-
# Browsers
|
35
|
-
# host
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
36
|
+
# Browsers open a limited number of simultaneous connections to a single
|
37
|
+
# host. The exact number varies by browser and version. This limit may cause
|
38
|
+
# some asset downloads to wait for previous assets to finish before they can
|
39
|
+
# begin. You can use the <tt>%d</tt> wildcard in the +asset_host+ to
|
40
|
+
# distribute the requests over four hosts. For example,
|
41
|
+
# <tt>assets%d.example.com</tt> will spread the asset requests over
|
42
|
+
# "assets0.example.com", ..., "assets3.example.com".
|
41
43
|
#
|
42
44
|
# image_tag("rails.png")
|
43
|
-
# # => <img
|
45
|
+
# # => <img src="http://assets0.example.com/assets/rails.png" />
|
44
46
|
# stylesheet_link_tag("application")
|
45
47
|
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
46
48
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
49
|
+
# This may improve the asset loading performance of your application.
|
50
|
+
# It is also possible the combination of additional connection overhead
|
51
|
+
# (DNS, SSL) and the overall browser connection limits may result in this
|
52
|
+
# solution being slower. You should be sure to measure your actual
|
53
|
+
# performance across targeted browsers both before and after this change.
|
54
|
+
#
|
55
|
+
# To implement the corresponding hosts you can either set up four actual
|
56
|
+
# hosts or use wildcard DNS to CNAME the wildcard to a single asset host.
|
57
|
+
# You can read more about setting up your DNS CNAME records from your ISP.
|
50
58
|
#
|
51
59
|
# Note: This is purely a browser performance optimization and is not meant
|
52
|
-
# for server load balancing. See
|
53
|
-
# for background.
|
60
|
+
# for server load balancing. See https://www.die.net/musings/page_load_time/
|
61
|
+
# for background and https://www.browserscope.org/?category=network for
|
62
|
+
# connection limit data.
|
54
63
|
#
|
55
64
|
# Alternatively, you can exert more control over the asset host by setting
|
56
65
|
# +asset_host+ to a proc like this:
|
@@ -59,7 +68,7 @@ module ActionView
|
|
59
68
|
# "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
|
60
69
|
# }
|
61
70
|
# image_tag("rails.png")
|
62
|
-
# # => <img
|
71
|
+
# # => <img src="http://assets1.example.com/assets/rails.png" />
|
63
72
|
# stylesheet_link_tag("application")
|
64
73
|
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
65
74
|
#
|
@@ -71,14 +80,14 @@ module ActionView
|
|
71
80
|
# absolute path of the asset, for example "/assets/rails.png".
|
72
81
|
#
|
73
82
|
# ActionController::Base.asset_host = Proc.new { |source|
|
74
|
-
# if source.
|
83
|
+
# if source.end_with?('.css')
|
75
84
|
# "http://stylesheets.example.com"
|
76
85
|
# else
|
77
86
|
# "http://assets.example.com"
|
78
87
|
# end
|
79
88
|
# }
|
80
89
|
# image_tag("rails.png")
|
81
|
-
# # => <img
|
90
|
+
# # => <img src="http://assets.example.com/assets/rails.png" />
|
82
91
|
# stylesheet_link_tag("application")
|
83
92
|
# # => <link href="http://stylesheets.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
84
93
|
#
|
@@ -88,9 +97,13 @@ module ActionView
|
|
88
97
|
# still sending assets for plain HTTP requests from asset hosts. If you don't
|
89
98
|
# have SSL certificates for each of the asset hosts this technique allows you
|
90
99
|
# to avoid warnings in the client about mixed media.
|
100
|
+
# Note that the +request+ parameter might not be supplied, e.g. when the assets
|
101
|
+
# are precompiled with the command <tt>bin/rails assets:precompile</tt>. Make sure to use a
|
102
|
+
# +Proc+ instead of a lambda, since a +Proc+ allows missing parameters and sets them
|
103
|
+
# to +nil+.
|
91
104
|
#
|
92
105
|
# config.action_controller.asset_host = Proc.new { |source, request|
|
93
|
-
# if request.ssl?
|
106
|
+
# if request && request.ssl?
|
94
107
|
# "#{request.protocol}#{request.host_with_port}"
|
95
108
|
# else
|
96
109
|
# "#{request.protocol}assets.example.com"
|
@@ -107,34 +120,93 @@ module ActionView
|
|
107
120
|
module AssetUrlHelper
|
108
121
|
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i
|
109
122
|
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
123
|
+
# This is the entry point for all assets.
|
124
|
+
# When using the asset pipeline (i.e. sprockets and sprockets-rails), the
|
125
|
+
# behavior is "enhanced". You can bypass the asset pipeline by passing in
|
126
|
+
# <tt>skip_pipeline: true</tt> to the options.
|
113
127
|
#
|
114
128
|
# All other asset *_path helpers delegate through this method.
|
115
129
|
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
130
|
+
# === With the asset pipeline
|
131
|
+
#
|
132
|
+
# All options passed to +asset_path+ will be passed to +compute_asset_path+
|
133
|
+
# which is implemented by sprockets-rails.
|
134
|
+
#
|
135
|
+
# asset_path("application.js") # => "/assets/application-60aa4fdc5cea14baf5400fba1abf4f2a46a5166bad4772b1effe341570f07de9.js"
|
136
|
+
# asset_path('application.js', host: 'example.com') # => "//example.com/assets/application.js"
|
137
|
+
# asset_path("application.js", host: 'example.com', protocol: 'https') # => "https://example.com/assets/application.js"
|
138
|
+
#
|
139
|
+
# === Without the asset pipeline (<tt>skip_pipeline: true</tt>)
|
140
|
+
#
|
141
|
+
# Accepts a <tt>type</tt> option that can specify the asset's extension. No error
|
142
|
+
# checking is done to verify the source passed into +asset_path+ is valid
|
143
|
+
# and that the file exists on disk.
|
144
|
+
#
|
145
|
+
# asset_path("application.js", skip_pipeline: true) # => "application.js"
|
146
|
+
# asset_path("filedoesnotexist.png", skip_pipeline: true) # => "filedoesnotexist.png"
|
147
|
+
# asset_path("application", type: :javascript, skip_pipeline: true) # => "/javascripts/application.js"
|
148
|
+
# asset_path("application", type: :stylesheet, skip_pipeline: true) # => "/stylesheets/application.css"
|
149
|
+
#
|
150
|
+
# === Options applying to all assets
|
151
|
+
#
|
152
|
+
# Below lists scenarios that apply to +asset_path+ whether or not you're
|
153
|
+
# using the asset pipeline.
|
154
|
+
#
|
155
|
+
# - All fully qualified URLs are returned immediately. This bypasses the
|
156
|
+
# asset pipeline and all other behavior described.
|
157
|
+
#
|
158
|
+
# asset_path("http://www.example.com/js/xmlhr.js") # => "http://www.example.com/js/xmlhr.js"
|
159
|
+
#
|
160
|
+
# - All assets that begin with a forward slash are assumed to be full
|
161
|
+
# URLs and will not be expanded. This will bypass the asset pipeline.
|
162
|
+
#
|
163
|
+
# asset_path("/foo.png") # => "/foo.png"
|
164
|
+
#
|
165
|
+
# - All blank strings will be returned immediately. This bypasses the
|
166
|
+
# asset pipeline and all other behavior described.
|
167
|
+
#
|
168
|
+
# asset_path("") # => ""
|
169
|
+
#
|
170
|
+
# - If <tt>config.relative_url_root</tt> is specified, all assets will have that
|
171
|
+
# root prepended.
|
172
|
+
#
|
173
|
+
# Rails.application.config.relative_url_root = "bar"
|
174
|
+
# asset_path("foo.js", skip_pipeline: true) # => "bar/foo.js"
|
175
|
+
#
|
176
|
+
# - A different asset host can be specified via <tt>config.action_controller.asset_host</tt>
|
177
|
+
# this is commonly used in conjunction with a CDN.
|
178
|
+
#
|
179
|
+
# Rails.application.config.action_controller.asset_host = "assets.example.com"
|
180
|
+
# asset_path("foo.js", skip_pipeline: true) # => "http://assets.example.com/foo.js"
|
181
|
+
#
|
182
|
+
# - An extension name can be specified manually with <tt>extname</tt>.
|
183
|
+
#
|
184
|
+
# asset_path("foo", skip_pipeline: true, extname: ".js") # => "/foo.js"
|
185
|
+
# asset_path("foo.css", skip_pipeline: true, extname: ".js") # => "/foo.css.js"
|
120
186
|
def asset_path(source, options = {})
|
187
|
+
raise ArgumentError, "nil is not a valid asset source" if source.nil?
|
188
|
+
|
121
189
|
source = source.to_s
|
122
|
-
return ""
|
123
|
-
return source if source
|
190
|
+
return "" if source.blank?
|
191
|
+
return source if URI_REGEXP.match?(source)
|
124
192
|
|
125
|
-
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/,
|
193
|
+
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, "")
|
126
194
|
|
127
195
|
if extname = compute_asset_extname(source, options)
|
128
196
|
source = "#{source}#{extname}"
|
129
197
|
end
|
130
198
|
|
131
199
|
if source[0] != ?/
|
132
|
-
|
200
|
+
if options[:skip_pipeline]
|
201
|
+
source = public_compute_asset_path(source, options)
|
202
|
+
else
|
203
|
+
source = compute_asset_path(source, options)
|
204
|
+
end
|
133
205
|
end
|
134
206
|
|
135
207
|
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
|
136
208
|
if relative_url_root
|
137
|
-
source = File.join(relative_url_root, source) unless source.
|
209
|
+
source = File.join(relative_url_root, source) unless source.start_with?("#{relative_url_root}/")
|
138
210
|
end
|
139
211
|
|
140
212
|
if host = compute_asset_host(source, options)
|
@@ -147,33 +219,44 @@ module ActionView
|
|
147
219
|
|
148
220
|
# Computes the full URL to an asset in the public directory. This
|
149
221
|
# will use +asset_path+ internally, so most of their behaviors
|
150
|
-
# will be the same.
|
222
|
+
# will be the same. If :host options is set, it overwrites global
|
223
|
+
# +config.action_controller.asset_host+ setting.
|
224
|
+
#
|
225
|
+
# All other options provided are forwarded to +asset_path+ call.
|
226
|
+
#
|
227
|
+
# asset_url "application.js" # => http://example.com/assets/application.js
|
228
|
+
# asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js
|
229
|
+
#
|
151
230
|
def asset_url(source, options = {})
|
152
|
-
path_to_asset(source, options.merge(:
|
231
|
+
path_to_asset(source, options.merge(protocol: :request))
|
153
232
|
end
|
154
233
|
alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
|
155
234
|
|
156
235
|
ASSET_EXTENSIONS = {
|
157
|
-
javascript:
|
158
|
-
stylesheet:
|
236
|
+
javascript: ".js",
|
237
|
+
stylesheet: ".css"
|
159
238
|
}
|
160
239
|
|
161
|
-
# Compute extname to append to asset path. Returns nil if
|
240
|
+
# Compute extname to append to asset path. Returns +nil+ if
|
162
241
|
# nothing should be added.
|
163
242
|
def compute_asset_extname(source, options = {})
|
164
243
|
return if options[:extname] == false
|
165
244
|
extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
|
166
|
-
|
245
|
+
if extname && File.extname(source) != extname
|
246
|
+
extname
|
247
|
+
else
|
248
|
+
nil
|
249
|
+
end
|
167
250
|
end
|
168
251
|
|
169
252
|
# Maps asset types to public directory.
|
170
253
|
ASSET_PUBLIC_DIRECTORIES = {
|
171
|
-
audio:
|
172
|
-
font:
|
173
|
-
image:
|
174
|
-
javascript:
|
175
|
-
stylesheet:
|
176
|
-
video:
|
254
|
+
audio: "/audios",
|
255
|
+
font: "/fonts",
|
256
|
+
image: "/images",
|
257
|
+
javascript: "/javascripts",
|
258
|
+
stylesheet: "/stylesheets",
|
259
|
+
video: "/videos"
|
177
260
|
}
|
178
261
|
|
179
262
|
# Computes asset path to public directory. Plugins and
|
@@ -183,6 +266,7 @@ module ActionView
|
|
183
266
|
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
|
184
267
|
File.join(dir, source)
|
185
268
|
end
|
269
|
+
alias :public_compute_asset_path :compute_asset_path
|
186
270
|
|
187
271
|
# Pick an asset host for this source. Returns +nil+ if no host is set,
|
188
272
|
# the host if no wildcard is set, the host interpolated with the
|
@@ -191,21 +275,24 @@ module ActionView
|
|
191
275
|
# (proc or otherwise).
|
192
276
|
def compute_asset_host(source = "", options = {})
|
193
277
|
request = self.request if respond_to?(:request)
|
194
|
-
host =
|
278
|
+
host = options[:host]
|
279
|
+
host ||= config.asset_host if defined? config.asset_host
|
195
280
|
|
196
|
-
if host
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
281
|
+
if host
|
282
|
+
if host.respond_to?(:call)
|
283
|
+
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
|
284
|
+
args = [source]
|
285
|
+
args << request if request && (arity > 1 || arity < 0)
|
286
|
+
host = host.call(*args)
|
287
|
+
elsif host.include?("%d")
|
288
|
+
host = host % (Zlib.crc32(source) % 4)
|
289
|
+
end
|
203
290
|
end
|
204
291
|
|
205
292
|
host ||= request.base_url if request && options[:protocol] == :request
|
206
293
|
return unless host
|
207
294
|
|
208
|
-
if host
|
295
|
+
if URI_REGEXP.match?(host)
|
209
296
|
host
|
210
297
|
else
|
211
298
|
protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
|
@@ -220,47 +307,57 @@ module ActionView
|
|
220
307
|
end
|
221
308
|
end
|
222
309
|
|
223
|
-
# Computes the path to a
|
310
|
+
# Computes the path to a JavaScript asset in the public javascripts directory.
|
224
311
|
# If the +source+ filename has no extension, .js will be appended (except for explicit URIs)
|
225
312
|
# Full paths from the document root will be passed through.
|
226
|
-
# Used internally by javascript_include_tag to build the script path.
|
313
|
+
# Used internally by +javascript_include_tag+ to build the script path.
|
227
314
|
#
|
228
|
-
# javascript_path "xmlhr" # => /
|
229
|
-
# javascript_path "dir/xmlhr.js" # => /
|
315
|
+
# javascript_path "xmlhr" # => /assets/xmlhr.js
|
316
|
+
# javascript_path "dir/xmlhr.js" # => /assets/dir/xmlhr.js
|
230
317
|
# javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
|
231
318
|
# javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
|
232
319
|
# javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
|
233
320
|
def javascript_path(source, options = {})
|
234
|
-
path_to_asset(source, {type: :javascript}.merge!(options))
|
321
|
+
path_to_asset(source, { type: :javascript }.merge!(options))
|
235
322
|
end
|
236
323
|
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
|
237
324
|
|
238
|
-
# Computes the full URL to a
|
325
|
+
# Computes the full URL to a JavaScript asset in the public javascripts directory.
|
239
326
|
# This will use +javascript_path+ internally, so most of their behaviors will be the same.
|
327
|
+
# Since +javascript_url+ is based on +asset_url+ method you can set :host options. If :host
|
328
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
329
|
+
#
|
330
|
+
# javascript_url "js/xmlhr.js", host: "http://stage.example.com" # => http://stage.example.com/assets/js/xmlhr.js
|
331
|
+
#
|
240
332
|
def javascript_url(source, options = {})
|
241
|
-
url_to_asset(source, {type: :javascript}.merge!(options))
|
333
|
+
url_to_asset(source, { type: :javascript }.merge!(options))
|
242
334
|
end
|
243
335
|
alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
|
244
336
|
|
245
337
|
# Computes the path to a stylesheet asset in the public stylesheets directory.
|
246
|
-
# If the +source+ filename has no extension,
|
338
|
+
# If the +source+ filename has no extension, .css will be appended (except for explicit URIs).
|
247
339
|
# Full paths from the document root will be passed through.
|
248
340
|
# Used internally by +stylesheet_link_tag+ to build the stylesheet path.
|
249
341
|
#
|
250
|
-
# stylesheet_path "style" # => /
|
251
|
-
# stylesheet_path "dir/style.css" # => /
|
342
|
+
# stylesheet_path "style" # => /assets/style.css
|
343
|
+
# stylesheet_path "dir/style.css" # => /assets/dir/style.css
|
252
344
|
# stylesheet_path "/dir/style.css" # => /dir/style.css
|
253
345
|
# stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
|
254
346
|
# stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
|
255
347
|
def stylesheet_path(source, options = {})
|
256
|
-
path_to_asset(source, {type: :stylesheet}.merge!(options))
|
348
|
+
path_to_asset(source, { type: :stylesheet }.merge!(options))
|
257
349
|
end
|
258
350
|
alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
|
259
351
|
|
260
352
|
# Computes the full URL to a stylesheet asset in the public stylesheets directory.
|
261
353
|
# This will use +stylesheet_path+ internally, so most of their behaviors will be the same.
|
354
|
+
# Since +stylesheet_url+ is based on +asset_url+ method you can set :host options. If :host
|
355
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
356
|
+
#
|
357
|
+
# stylesheet_url "css/style.css", host: "http://stage.example.com" # => http://stage.example.com/assets/css/style.css
|
358
|
+
#
|
262
359
|
def stylesheet_url(source, options = {})
|
263
|
-
url_to_asset(source, {type: :stylesheet}.merge!(options))
|
360
|
+
url_to_asset(source, { type: :stylesheet }.merge!(options))
|
264
361
|
end
|
265
362
|
alias_method :url_to_stylesheet, :stylesheet_url # aliased to avoid conflicts with a stylesheet_url named route
|
266
363
|
|
@@ -278,14 +375,19 @@ module ActionView
|
|
278
375
|
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
279
376
|
# plugin authors are encouraged to do so.
|
280
377
|
def image_path(source, options = {})
|
281
|
-
path_to_asset(source, {type: :image}.merge!(options))
|
378
|
+
path_to_asset(source, { type: :image }.merge!(options))
|
282
379
|
end
|
283
380
|
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
|
284
381
|
|
285
382
|
# Computes the full URL to an image asset.
|
286
383
|
# This will use +image_path+ internally, so most of their behaviors will be the same.
|
384
|
+
# Since +image_url+ is based on +asset_url+ method you can set :host options. If :host
|
385
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
386
|
+
#
|
387
|
+
# image_url "edit.png", host: "http://stage.example.com" # => http://stage.example.com/assets/edit.png
|
388
|
+
#
|
287
389
|
def image_url(source, options = {})
|
288
|
-
url_to_asset(source, {type: :image}.merge!(options))
|
390
|
+
url_to_asset(source, { type: :image }.merge!(options))
|
289
391
|
end
|
290
392
|
alias_method :url_to_image, :image_url # aliased to avoid conflicts with an image_url named route
|
291
393
|
|
@@ -299,16 +401,21 @@ module ActionView
|
|
299
401
|
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
300
402
|
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
|
301
403
|
def video_path(source, options = {})
|
302
|
-
path_to_asset(source, {type: :video}.merge!(options))
|
404
|
+
path_to_asset(source, { type: :video }.merge!(options))
|
303
405
|
end
|
304
406
|
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
|
305
407
|
|
306
408
|
# Computes the full URL to a video asset in the public videos directory.
|
307
409
|
# This will use +video_path+ internally, so most of their behaviors will be the same.
|
410
|
+
# Since +video_url+ is based on +asset_url+ method you can set :host options. If :host
|
411
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
412
|
+
#
|
413
|
+
# video_url "hd.avi", host: "http://stage.example.com" # => http://stage.example.com/videos/hd.avi
|
414
|
+
#
|
308
415
|
def video_url(source, options = {})
|
309
|
-
url_to_asset(source, {type: :video}.merge!(options))
|
416
|
+
url_to_asset(source, { type: :video }.merge!(options))
|
310
417
|
end
|
311
|
-
alias_method :url_to_video, :video_url # aliased to avoid conflicts with
|
418
|
+
alias_method :url_to_video, :video_url # aliased to avoid conflicts with a video_url named route
|
312
419
|
|
313
420
|
# Computes the path to an audio asset in the public audios directory.
|
314
421
|
# Full paths from the document root will be passed through.
|
@@ -320,36 +427,46 @@ module ActionView
|
|
320
427
|
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
321
428
|
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
|
322
429
|
def audio_path(source, options = {})
|
323
|
-
path_to_asset(source, {type: :audio}.merge!(options))
|
430
|
+
path_to_asset(source, { type: :audio }.merge!(options))
|
324
431
|
end
|
325
432
|
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
|
326
433
|
|
327
434
|
# Computes the full URL to an audio asset in the public audios directory.
|
328
435
|
# This will use +audio_path+ internally, so most of their behaviors will be the same.
|
436
|
+
# Since +audio_url+ is based on +asset_url+ method you can set :host options. If :host
|
437
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
438
|
+
#
|
439
|
+
# audio_url "horse.wav", host: "http://stage.example.com" # => http://stage.example.com/audios/horse.wav
|
440
|
+
#
|
329
441
|
def audio_url(source, options = {})
|
330
|
-
url_to_asset(source, {type: :audio}.merge!(options))
|
442
|
+
url_to_asset(source, { type: :audio }.merge!(options))
|
331
443
|
end
|
332
444
|
alias_method :url_to_audio, :audio_url # aliased to avoid conflicts with an audio_url named route
|
333
445
|
|
334
446
|
# Computes the path to a font asset.
|
335
447
|
# Full paths from the document root will be passed through.
|
336
448
|
#
|
337
|
-
# font_path("font") # => /
|
338
|
-
# font_path("font.ttf") # => /
|
339
|
-
# font_path("dir/font.ttf") # => /
|
449
|
+
# font_path("font") # => /fonts/font
|
450
|
+
# font_path("font.ttf") # => /fonts/font.ttf
|
451
|
+
# font_path("dir/font.ttf") # => /fonts/dir/font.ttf
|
340
452
|
# font_path("/dir/font.ttf") # => /dir/font.ttf
|
341
453
|
# font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
|
342
454
|
def font_path(source, options = {})
|
343
|
-
path_to_asset(source, {type: :font}.merge!(options))
|
455
|
+
path_to_asset(source, { type: :font }.merge!(options))
|
344
456
|
end
|
345
|
-
alias_method :path_to_font, :font_path # aliased to avoid conflicts with
|
457
|
+
alias_method :path_to_font, :font_path # aliased to avoid conflicts with a font_path named route
|
346
458
|
|
347
459
|
# Computes the full URL to a font asset.
|
348
460
|
# This will use +font_path+ internally, so most of their behaviors will be the same.
|
461
|
+
# Since +font_url+ is based on +asset_url+ method you can set :host options. If :host
|
462
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
463
|
+
#
|
464
|
+
# font_url "font.ttf", host: "http://stage.example.com" # => http://stage.example.com/fonts/font.ttf
|
465
|
+
#
|
349
466
|
def font_url(source, options = {})
|
350
|
-
url_to_asset(source, {type: :font}.merge!(options))
|
467
|
+
url_to_asset(source, { type: :font }.merge!(options))
|
351
468
|
end
|
352
|
-
alias_method :url_to_font, :font_url # aliased to avoid conflicts with
|
469
|
+
alias_method :url_to_font, :font_url # aliased to avoid conflicts with a font_url named route
|
353
470
|
end
|
354
471
|
end
|
355
472
|
end
|