actionview 4.2.11.1 → 6.0.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 +4 -4
- data/CHANGELOG.md +187 -221
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -8
- data/lib/action_view/base.rb +144 -37
- data/lib/action_view/buffers.rb +18 -1
- data/lib/action_view/cache_expiry.rb +53 -0
- data/lib/action_view/context.rb +8 -12
- data/lib/action_view/dependency_tracker.rb +54 -20
- data/lib/action_view/digestor.rb +88 -85
- data/lib/action_view/flows.rb +11 -12
- data/lib/action_view/gem_version.rb +5 -3
- data/lib/action_view/helpers/active_model_helper.rb +16 -11
- data/lib/action_view/helpers/asset_tag_helper.rb +241 -82
- data/lib/action_view/helpers/asset_url_helper.rb +171 -67
- data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
- data/lib/action_view/helpers/cache_helper.rb +112 -42
- data/lib/action_view/helpers/capture_helper.rb +20 -13
- 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 +230 -129
- data/lib/action_view/helpers/debug_helper.rb +7 -6
- data/lib/action_view/helpers/form_helper.rb +755 -129
- data/lib/action_view/helpers/form_options_helper.rb +130 -75
- data/lib/action_view/helpers/form_tag_helper.rb +117 -71
- data/lib/action_view/helpers/javascript_helper.rb +30 -14
- data/lib/action_view/helpers/number_helper.rb +84 -59
- data/lib/action_view/helpers/output_safety_helper.rb +36 -4
- data/lib/action_view/helpers/rendering_helper.rb +11 -8
- data/lib/action_view/helpers/sanitize_helper.rb +30 -31
- data/lib/action_view/helpers/tag_helper.rb +201 -75
- data/lib/action_view/helpers/tags/base.rb +138 -98
- 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 -34
- 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 +2 -1
- data/lib/action_view/helpers/tags/date_select.rb +37 -36
- data/lib/action_view/helpers/tags/datetime_field.rb +4 -3
- data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -1
- 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 +3 -2
- data/lib/action_view/helpers/tags/month_field.rb +2 -1
- 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 +3 -1
- 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 +14 -9
- 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 +4 -2
- data/lib/action_view/helpers/tags/text_field.rb +8 -8
- data/lib/action_view/helpers/tags/time_field.rb +2 -1
- 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 +15 -16
- data/lib/action_view/helpers/tags/url_field.rb +2 -0
- data/lib/action_view/helpers/tags/week_field.rb +2 -1
- data/lib/action_view/helpers/tags.rb +3 -1
- data/lib/action_view/helpers/text_helper.rb +56 -38
- data/lib/action_view/helpers/translation_helper.rb +82 -48
- data/lib/action_view/helpers/url_helper.rb +160 -105
- data/lib/action_view/helpers.rb +5 -3
- data/lib/action_view/layouts.rb +65 -61
- data/lib/action_view/log_subscriber.rb +61 -10
- data/lib/action_view/lookup_context.rb +147 -89
- data/lib/action_view/model_naming.rb +3 -1
- data/lib/action_view/path_set.rb +28 -23
- data/lib/action_view/railtie.rb +62 -6
- data/lib/action_view/record_identifier.rb +53 -26
- data/lib/action_view/renderer/abstract_renderer.rb +71 -13
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
- data/lib/action_view/renderer/partial_renderer.rb +239 -225
- data/lib/action_view/renderer/renderer.rb +22 -8
- data/lib/action_view/renderer/streaming_template_renderer.rb +54 -54
- data/lib/action_view/renderer/template_renderer.rb +79 -73
- data/lib/action_view/rendering.rb +68 -44
- data/lib/action_view/routing_url_for.rb +33 -22
- 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 +87 -0
- data/lib/action_view/template/handlers/erb.rb +24 -86
- 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 +38 -8
- data/lib/action_view/template/html.rb +19 -10
- data/lib/action_view/template/inline.rb +22 -0
- data/lib/action_view/template/raw_file.rb +28 -0
- data/lib/action_view/template/resolver.rb +217 -193
- 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 +11 -10
- data/lib/action_view/template/types.rb +18 -18
- data/lib/action_view/template.rb +146 -90
- data/lib/action_view/test_case.rb +52 -32
- data/lib/action_view/testing/resolvers.rb +46 -34
- data/lib/action_view/unbound_template.rb +31 -0
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +48 -31
- data/lib/action_view.rb +11 -8
- data/lib/assets/compiled/rails-ujs.js +746 -0
- metadata +38 -29
- data/lib/action_view/helpers/record_tag_helper.rb +0 -108
- data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -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 setup 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
|
#
|
@@ -78,7 +87,7 @@ module ActionView
|
|
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,10 @@ 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.
|
91
|
-
# Note that the request parameter might not be supplied, e.g. when the assets
|
92
|
-
# are precompiled
|
93
|
-
# since a Proc allows missing parameters and sets them
|
100
|
+
# Note that the +request+ parameter might not be supplied, e.g. when the assets
|
101
|
+
# are precompiled with the command `rails assets:precompile`. Make sure to use a
|
102
|
+
# +Proc+ instead of a lambda, since a +Proc+ allows missing parameters and sets them
|
103
|
+
# to +nil+.
|
94
104
|
#
|
95
105
|
# config.action_controller.asset_host = Proc.new { |source, request|
|
96
106
|
# if request && request.ssl?
|
@@ -110,29 +120,86 @@ module ActionView
|
|
110
120
|
module AssetUrlHelper
|
111
121
|
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i
|
112
122
|
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
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.
|
116
127
|
#
|
117
128
|
# All other asset *_path helpers delegate through this method.
|
118
129
|
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
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
|
+
#
|
137
|
+
# === Without the asset pipeline (<tt>skip_pipeline: true</tt>)
|
138
|
+
#
|
139
|
+
# Accepts a <tt>type</tt> option that can specify the asset's extension. No error
|
140
|
+
# checking is done to verify the source passed into +asset_path+ is valid
|
141
|
+
# and that the file exists on disk.
|
142
|
+
#
|
143
|
+
# asset_path("application.js", skip_pipeline: true) # => "application.js"
|
144
|
+
# asset_path("filedoesnotexist.png", skip_pipeline: true) # => "filedoesnotexist.png"
|
145
|
+
# asset_path("application", type: :javascript, skip_pipeline: true) # => "/javascripts/application.js"
|
146
|
+
# asset_path("application", type: :stylesheet, skip_pipeline: true) # => "/stylesheets/application.css"
|
147
|
+
#
|
148
|
+
# === Options applying to all assets
|
149
|
+
#
|
150
|
+
# Below lists scenarios that apply to +asset_path+ whether or not you're
|
151
|
+
# using the asset pipeline.
|
152
|
+
#
|
153
|
+
# - All fully qualified URLs are returned immediately. This bypasses the
|
154
|
+
# asset pipeline and all other behavior described.
|
155
|
+
#
|
156
|
+
# asset_path("http://www.example.com/js/xmlhr.js") # => "http://www.example.com/js/xmlhr.js"
|
157
|
+
#
|
158
|
+
# - All assets that begin with a forward slash are assumed to be full
|
159
|
+
# URLs and will not be expanded. This will bypass the asset pipeline.
|
160
|
+
#
|
161
|
+
# asset_path("/foo.png") # => "/foo.png"
|
162
|
+
#
|
163
|
+
# - All blank strings will be returned immediately. This bypasses the
|
164
|
+
# asset pipeline and all other behavior described.
|
165
|
+
#
|
166
|
+
# asset_path("") # => ""
|
167
|
+
#
|
168
|
+
# - If <tt>config.relative_url_root</tt> is specified, all assets will have that
|
169
|
+
# root prepended.
|
170
|
+
#
|
171
|
+
# Rails.application.config.relative_url_root = "bar"
|
172
|
+
# asset_path("foo.js", skip_pipeline: true) # => "bar/foo.js"
|
173
|
+
#
|
174
|
+
# - A different asset host can be specified via <tt>config.action_controller.asset_host</tt>
|
175
|
+
# this is commonly used in conjunction with a CDN.
|
176
|
+
#
|
177
|
+
# Rails.application.config.action_controller.asset_host = "assets.example.com"
|
178
|
+
# asset_path("foo.js", skip_pipeline: true) # => "http://assets.example.com/foo.js"
|
179
|
+
#
|
180
|
+
# - An extension name can be specified manually with <tt>extname</tt>.
|
181
|
+
#
|
182
|
+
# asset_path("foo", skip_pipeline: true, extname: ".js") # => "/foo.js"
|
183
|
+
# asset_path("foo.css", skip_pipeline: true, extname: ".js") # => "/foo.css.js"
|
123
184
|
def asset_path(source, options = {})
|
185
|
+
raise ArgumentError, "nil is not a valid asset source" if source.nil?
|
186
|
+
|
124
187
|
source = source.to_s
|
125
|
-
return ""
|
126
|
-
return source if source
|
188
|
+
return "" if source.blank?
|
189
|
+
return source if URI_REGEXP.match?(source)
|
127
190
|
|
128
|
-
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/,
|
191
|
+
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, "")
|
129
192
|
|
130
193
|
if extname = compute_asset_extname(source, options)
|
131
194
|
source = "#{source}#{extname}"
|
132
195
|
end
|
133
196
|
|
134
197
|
if source[0] != ?/
|
135
|
-
|
198
|
+
if options[:skip_pipeline]
|
199
|
+
source = public_compute_asset_path(source, options)
|
200
|
+
else
|
201
|
+
source = compute_asset_path(source, options)
|
202
|
+
end
|
136
203
|
end
|
137
204
|
|
138
205
|
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
|
@@ -159,31 +226,35 @@ module ActionView
|
|
159
226
|
# asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js
|
160
227
|
#
|
161
228
|
def asset_url(source, options = {})
|
162
|
-
path_to_asset(source, options.merge(:
|
229
|
+
path_to_asset(source, options.merge(protocol: :request))
|
163
230
|
end
|
164
231
|
alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
|
165
232
|
|
166
233
|
ASSET_EXTENSIONS = {
|
167
|
-
javascript:
|
168
|
-
stylesheet:
|
234
|
+
javascript: ".js",
|
235
|
+
stylesheet: ".css"
|
169
236
|
}
|
170
237
|
|
171
|
-
# Compute extname to append to asset path. Returns nil if
|
238
|
+
# Compute extname to append to asset path. Returns +nil+ if
|
172
239
|
# nothing should be added.
|
173
240
|
def compute_asset_extname(source, options = {})
|
174
241
|
return if options[:extname] == false
|
175
242
|
extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
|
176
|
-
|
243
|
+
if extname && File.extname(source) != extname
|
244
|
+
extname
|
245
|
+
else
|
246
|
+
nil
|
247
|
+
end
|
177
248
|
end
|
178
249
|
|
179
250
|
# Maps asset types to public directory.
|
180
251
|
ASSET_PUBLIC_DIRECTORIES = {
|
181
|
-
audio:
|
182
|
-
font:
|
183
|
-
image:
|
184
|
-
javascript:
|
185
|
-
stylesheet:
|
186
|
-
video:
|
252
|
+
audio: "/audios",
|
253
|
+
font: "/fonts",
|
254
|
+
image: "/images",
|
255
|
+
javascript: "/javascripts",
|
256
|
+
stylesheet: "/stylesheets",
|
257
|
+
video: "/videos"
|
187
258
|
}
|
188
259
|
|
189
260
|
# Computes asset path to public directory. Plugins and
|
@@ -193,6 +264,7 @@ module ActionView
|
|
193
264
|
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
|
194
265
|
File.join(dir, source)
|
195
266
|
end
|
267
|
+
alias :public_compute_asset_path :compute_asset_path
|
196
268
|
|
197
269
|
# Pick an asset host for this source. Returns +nil+ if no host is set,
|
198
270
|
# the host if no wildcard is set, the host interpolated with the
|
@@ -204,19 +276,21 @@ module ActionView
|
|
204
276
|
host = options[:host]
|
205
277
|
host ||= config.asset_host if defined? config.asset_host
|
206
278
|
|
207
|
-
if host
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
279
|
+
if host
|
280
|
+
if host.respond_to?(:call)
|
281
|
+
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
|
282
|
+
args = [source]
|
283
|
+
args << request if request && (arity > 1 || arity < 0)
|
284
|
+
host = host.call(*args)
|
285
|
+
elsif host.include?("%d")
|
286
|
+
host = host % (Zlib.crc32(source) % 4)
|
287
|
+
end
|
214
288
|
end
|
215
289
|
|
216
290
|
host ||= request.base_url if request && options[:protocol] == :request
|
217
291
|
return unless host
|
218
292
|
|
219
|
-
if host
|
293
|
+
if URI_REGEXP.match?(host)
|
220
294
|
host
|
221
295
|
else
|
222
296
|
protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
|
@@ -242,14 +316,19 @@ module ActionView
|
|
242
316
|
# javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
|
243
317
|
# javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
|
244
318
|
def javascript_path(source, options = {})
|
245
|
-
path_to_asset(source, {type: :javascript}.merge!(options))
|
319
|
+
path_to_asset(source, { type: :javascript }.merge!(options))
|
246
320
|
end
|
247
321
|
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
|
248
322
|
|
249
323
|
# Computes the full URL to a JavaScript asset in the public javascripts directory.
|
250
324
|
# This will use +javascript_path+ internally, so most of their behaviors will be the same.
|
325
|
+
# Since +javascript_url+ is based on +asset_url+ method you can set :host options. If :host
|
326
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
327
|
+
#
|
328
|
+
# javascript_url "js/xmlhr.js", host: "http://stage.example.com" # => http://stage.example.com/assets/js/xmlhr.js
|
329
|
+
#
|
251
330
|
def javascript_url(source, options = {})
|
252
|
-
url_to_asset(source, {type: :javascript}.merge!(options))
|
331
|
+
url_to_asset(source, { type: :javascript }.merge!(options))
|
253
332
|
end
|
254
333
|
alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
|
255
334
|
|
@@ -264,14 +343,19 @@ module ActionView
|
|
264
343
|
# stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
|
265
344
|
# stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
|
266
345
|
def stylesheet_path(source, options = {})
|
267
|
-
path_to_asset(source, {type: :stylesheet}.merge!(options))
|
346
|
+
path_to_asset(source, { type: :stylesheet }.merge!(options))
|
268
347
|
end
|
269
348
|
alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
|
270
349
|
|
271
350
|
# Computes the full URL to a stylesheet asset in the public stylesheets directory.
|
272
351
|
# This will use +stylesheet_path+ internally, so most of their behaviors will be the same.
|
352
|
+
# Since +stylesheet_url+ is based on +asset_url+ method you can set :host options. If :host
|
353
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
354
|
+
#
|
355
|
+
# stylesheet_url "css/style.css", host: "http://stage.example.com" # => http://stage.example.com/assets/css/style.css
|
356
|
+
#
|
273
357
|
def stylesheet_url(source, options = {})
|
274
|
-
url_to_asset(source, {type: :stylesheet}.merge!(options))
|
358
|
+
url_to_asset(source, { type: :stylesheet }.merge!(options))
|
275
359
|
end
|
276
360
|
alias_method :url_to_stylesheet, :stylesheet_url # aliased to avoid conflicts with a stylesheet_url named route
|
277
361
|
|
@@ -289,14 +373,19 @@ module ActionView
|
|
289
373
|
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
290
374
|
# plugin authors are encouraged to do so.
|
291
375
|
def image_path(source, options = {})
|
292
|
-
path_to_asset(source, {type: :image}.merge!(options))
|
376
|
+
path_to_asset(source, { type: :image }.merge!(options))
|
293
377
|
end
|
294
378
|
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
|
295
379
|
|
296
380
|
# Computes the full URL to an image asset.
|
297
381
|
# This will use +image_path+ internally, so most of their behaviors will be the same.
|
382
|
+
# Since +image_url+ is based on +asset_url+ method you can set :host options. If :host
|
383
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
384
|
+
#
|
385
|
+
# image_url "edit.png", host: "http://stage.example.com" # => http://stage.example.com/assets/edit.png
|
386
|
+
#
|
298
387
|
def image_url(source, options = {})
|
299
|
-
url_to_asset(source, {type: :image}.merge!(options))
|
388
|
+
url_to_asset(source, { type: :image }.merge!(options))
|
300
389
|
end
|
301
390
|
alias_method :url_to_image, :image_url # aliased to avoid conflicts with an image_url named route
|
302
391
|
|
@@ -310,16 +399,21 @@ module ActionView
|
|
310
399
|
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
311
400
|
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
|
312
401
|
def video_path(source, options = {})
|
313
|
-
path_to_asset(source, {type: :video}.merge!(options))
|
402
|
+
path_to_asset(source, { type: :video }.merge!(options))
|
314
403
|
end
|
315
404
|
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
|
316
405
|
|
317
406
|
# Computes the full URL to a video asset in the public videos directory.
|
318
407
|
# This will use +video_path+ internally, so most of their behaviors will be the same.
|
408
|
+
# Since +video_url+ is based on +asset_url+ method you can set :host options. If :host
|
409
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
410
|
+
#
|
411
|
+
# video_url "hd.avi", host: "http://stage.example.com" # => http://stage.example.com/videos/hd.avi
|
412
|
+
#
|
319
413
|
def video_url(source, options = {})
|
320
|
-
url_to_asset(source, {type: :video}.merge!(options))
|
414
|
+
url_to_asset(source, { type: :video }.merge!(options))
|
321
415
|
end
|
322
|
-
alias_method :url_to_video, :video_url # aliased to avoid conflicts with
|
416
|
+
alias_method :url_to_video, :video_url # aliased to avoid conflicts with a video_url named route
|
323
417
|
|
324
418
|
# Computes the path to an audio asset in the public audios directory.
|
325
419
|
# Full paths from the document root will be passed through.
|
@@ -331,14 +425,19 @@ module ActionView
|
|
331
425
|
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
332
426
|
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
|
333
427
|
def audio_path(source, options = {})
|
334
|
-
path_to_asset(source, {type: :audio}.merge!(options))
|
428
|
+
path_to_asset(source, { type: :audio }.merge!(options))
|
335
429
|
end
|
336
430
|
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
|
337
431
|
|
338
432
|
# Computes the full URL to an audio asset in the public audios directory.
|
339
433
|
# This will use +audio_path+ internally, so most of their behaviors will be the same.
|
434
|
+
# Since +audio_url+ is based on +asset_url+ method you can set :host options. If :host
|
435
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
436
|
+
#
|
437
|
+
# audio_url "horse.wav", host: "http://stage.example.com" # => http://stage.example.com/audios/horse.wav
|
438
|
+
#
|
340
439
|
def audio_url(source, options = {})
|
341
|
-
url_to_asset(source, {type: :audio}.merge!(options))
|
440
|
+
url_to_asset(source, { type: :audio }.merge!(options))
|
342
441
|
end
|
343
442
|
alias_method :url_to_audio, :audio_url # aliased to avoid conflicts with an audio_url named route
|
344
443
|
|
@@ -351,16 +450,21 @@ module ActionView
|
|
351
450
|
# font_path("/dir/font.ttf") # => /dir/font.ttf
|
352
451
|
# font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
|
353
452
|
def font_path(source, options = {})
|
354
|
-
path_to_asset(source, {type: :font}.merge!(options))
|
453
|
+
path_to_asset(source, { type: :font }.merge!(options))
|
355
454
|
end
|
356
|
-
alias_method :path_to_font, :font_path # aliased to avoid conflicts with
|
455
|
+
alias_method :path_to_font, :font_path # aliased to avoid conflicts with a font_path named route
|
357
456
|
|
358
457
|
# Computes the full URL to a font asset.
|
359
458
|
# This will use +font_path+ internally, so most of their behaviors will be the same.
|
459
|
+
# Since +font_url+ is based on +asset_url+ method you can set :host options. If :host
|
460
|
+
# options is set, it overwrites global +config.action_controller.asset_host+ setting.
|
461
|
+
#
|
462
|
+
# font_url "font.ttf", host: "http://stage.example.com" # => http://stage.example.com/fonts/font.ttf
|
463
|
+
#
|
360
464
|
def font_url(source, options = {})
|
361
|
-
url_to_asset(source, {type: :font}.merge!(options))
|
465
|
+
url_to_asset(source, { type: :font }.merge!(options))
|
362
466
|
end
|
363
|
-
alias_method :url_to_font, :font_url # aliased to avoid conflicts with
|
467
|
+
alias_method :url_to_font, :font_url # aliased to avoid conflicts with a font_url named route
|
364
468
|
end
|
365
469
|
end
|
366
470
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
2
4
|
|
3
5
|
module ActionView
|
4
6
|
# = Action View Atom Feed Helpers
|
5
|
-
module Helpers
|
7
|
+
module Helpers #:nodoc:
|
6
8
|
module AtomFeedHelper
|
7
9
|
# Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERB or any other
|
8
10
|
# template languages).
|
@@ -16,7 +18,7 @@ module ActionView
|
|
16
18
|
# end
|
17
19
|
#
|
18
20
|
# app/controllers/posts_controller.rb:
|
19
|
-
# class PostsController < ApplicationController
|
21
|
+
# class PostsController < ApplicationController
|
20
22
|
# # GET /posts.html
|
21
23
|
# # GET /posts.atom
|
22
24
|
# def index
|
@@ -51,7 +53,7 @@ module ActionView
|
|
51
53
|
# * <tt>:language</tt>: Defaults to "en-US".
|
52
54
|
# * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host.
|
53
55
|
# * <tt>:url</tt>: The URL for this feed. Defaults to the current URL.
|
54
|
-
# * <tt>:id</tt>: The id for this feed. Defaults to "tag
|
56
|
+
# * <tt>:id</tt>: The id for this feed. Defaults to "tag:localhost,2005:/posts", in this case.
|
55
57
|
# * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you
|
56
58
|
# created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,
|
57
59
|
# 2005 is used (as an "I don't care" value).
|
@@ -103,7 +105,7 @@ module ActionView
|
|
103
105
|
xml = options.delete(:xml) || eval("xml", block.binding)
|
104
106
|
xml.instruct!
|
105
107
|
if options[:instruct]
|
106
|
-
options[:instruct].each do |target,attrs|
|
108
|
+
options[:instruct].each do |target, attrs|
|
107
109
|
if attrs.respond_to?(:keys)
|
108
110
|
xml.instruct!(target, attrs)
|
109
111
|
elsif attrs.respond_to?(:each)
|
@@ -112,13 +114,13 @@ module ActionView
|
|
112
114
|
end
|
113
115
|
end
|
114
116
|
|
115
|
-
feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" =>
|
116
|
-
feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)}
|
117
|
+
feed_opts = { "xml:lang" => options[:language] || "en-US", "xmlns" => "http://www.w3.org/2005/Atom" }
|
118
|
+
feed_opts.merge!(options).reject! { |k, v| !k.to_s.match(/^xml/) }
|
117
119
|
|
118
120
|
xml.feed(feed_opts) do
|
119
121
|
xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}")
|
120
|
-
xml.link(:
|
121
|
-
xml.link(:
|
122
|
+
xml.link(rel: "alternate", type: "text/html", href: options[:root_url] || (request.protocol + request.host_with_port))
|
123
|
+
xml.link(rel: "self", type: "application/atom+xml", href: options[:url] || request.url)
|
122
124
|
|
123
125
|
yield AtomFeedBuilder.new(xml, self, options)
|
124
126
|
end
|
@@ -132,13 +134,13 @@ module ActionView
|
|
132
134
|
end
|
133
135
|
|
134
136
|
private
|
135
|
-
# Delegate to xml builder, first wrapping the element in
|
137
|
+
# Delegate to xml builder, first wrapping the element in an xhtml
|
136
138
|
# namespaced div element if the method and arguments indicate
|
137
139
|
# that an xhtml_block? is desired.
|
138
140
|
def method_missing(method, *arguments, &block)
|
139
141
|
if xhtml_block?(method, arguments)
|
140
142
|
@xml.__send__(method, *arguments) do
|
141
|
-
@xml.div(:
|
143
|
+
@xml.div(xmlns: "http://www.w3.org/1999/xhtml") do |xhtml|
|
142
144
|
block.call(xhtml)
|
143
145
|
end
|
144
146
|
end
|
@@ -153,7 +155,7 @@ module ActionView
|
|
153
155
|
def xhtml_block?(method, arguments)
|
154
156
|
if XHTML_TAG_NAMES.include?(method.to_s)
|
155
157
|
last = arguments.last
|
156
|
-
last.is_a?(Hash) && last[:type].to_s ==
|
158
|
+
last.is_a?(Hash) && last[:type].to_s == "xhtml"
|
157
159
|
end
|
158
160
|
end
|
159
161
|
end
|
@@ -163,7 +165,7 @@ module ActionView
|
|
163
165
|
@xml, @view, @feed_options = xml, view, feed_options
|
164
166
|
end
|
165
167
|
|
166
|
-
# Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used.
|
168
|
+
# Accepts a Date or Time object and inserts it in the proper format. If +nil+ is passed, current time in UTC is used.
|
167
169
|
def updated(date_or_time = nil)
|
168
170
|
@xml.updated((date_or_time || Time.now.utc).xmlschema)
|
169
171
|
end
|
@@ -174,7 +176,7 @@ module ActionView
|
|
174
176
|
#
|
175
177
|
# * <tt>:published</tt>: Time first published. Defaults to the created_at attribute on the record if one such exists.
|
176
178
|
# * <tt>:updated</tt>: Time of update. Defaults to the updated_at attribute on the record if one such exists.
|
177
|
-
# * <tt>:url</tt>: The URL for this entry. Defaults to the polymorphic_url for the record.
|
179
|
+
# * <tt>:url</tt>: The URL for this entry or +false+ or +nil+ for not having a link tag. Defaults to the +polymorphic_url+ for the record.
|
178
180
|
# * <tt>:id</tt>: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}"
|
179
181
|
# * <tt>:type</tt>: The TYPE for this entry. Defaults to "text/html".
|
180
182
|
def entry(record, options = {})
|
@@ -189,15 +191,15 @@ module ActionView
|
|
189
191
|
@xml.updated((options[:updated] || record.updated_at).xmlschema)
|
190
192
|
end
|
191
193
|
|
192
|
-
type = options.fetch(:type,
|
194
|
+
type = options.fetch(:type, "text/html")
|
193
195
|
|
194
|
-
|
196
|
+
url = options.fetch(:url) { @view.polymorphic_url(record) }
|
197
|
+
@xml.link(rel: "alternate", type: type, href: url) if url
|
195
198
|
|
196
199
|
yield AtomBuilder.new(@xml)
|
197
200
|
end
|
198
201
|
end
|
199
202
|
end
|
200
|
-
|
201
203
|
end
|
202
204
|
end
|
203
205
|
end
|