actionview 6.0.0

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.

Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +271 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +40 -0
  5. data/lib/action_view.rb +98 -0
  6. data/lib/action_view/base.rb +312 -0
  7. data/lib/action_view/buffers.rb +67 -0
  8. data/lib/action_view/cache_expiry.rb +54 -0
  9. data/lib/action_view/context.rb +32 -0
  10. data/lib/action_view/dependency_tracker.rb +175 -0
  11. data/lib/action_view/digestor.rb +126 -0
  12. data/lib/action_view/flows.rb +76 -0
  13. data/lib/action_view/gem_version.rb +17 -0
  14. data/lib/action_view/helpers.rb +66 -0
  15. data/lib/action_view/helpers/active_model_helper.rb +55 -0
  16. data/lib/action_view/helpers/asset_tag_helper.rb +488 -0
  17. data/lib/action_view/helpers/asset_url_helper.rb +470 -0
  18. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  19. data/lib/action_view/helpers/cache_helper.rb +271 -0
  20. data/lib/action_view/helpers/capture_helper.rb +216 -0
  21. data/lib/action_view/helpers/controller_helper.rb +36 -0
  22. data/lib/action_view/helpers/csp_helper.rb +26 -0
  23. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  24. data/lib/action_view/helpers/date_helper.rb +1200 -0
  25. data/lib/action_view/helpers/debug_helper.rb +36 -0
  26. data/lib/action_view/helpers/form_helper.rb +2569 -0
  27. data/lib/action_view/helpers/form_options_helper.rb +896 -0
  28. data/lib/action_view/helpers/form_tag_helper.rb +920 -0
  29. data/lib/action_view/helpers/javascript_helper.rb +95 -0
  30. data/lib/action_view/helpers/number_helper.rb +456 -0
  31. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  32. data/lib/action_view/helpers/rendering_helper.rb +101 -0
  33. data/lib/action_view/helpers/sanitize_helper.rb +171 -0
  34. data/lib/action_view/helpers/tag_helper.rb +314 -0
  35. data/lib/action_view/helpers/tags.rb +44 -0
  36. data/lib/action_view/helpers/tags/base.rb +196 -0
  37. data/lib/action_view/helpers/tags/check_box.rb +66 -0
  38. data/lib/action_view/helpers/tags/checkable.rb +18 -0
  39. data/lib/action_view/helpers/tags/collection_check_boxes.rb +36 -0
  40. data/lib/action_view/helpers/tags/collection_helpers.rb +119 -0
  41. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
  42. data/lib/action_view/helpers/tags/collection_select.rb +30 -0
  43. data/lib/action_view/helpers/tags/color_field.rb +27 -0
  44. data/lib/action_view/helpers/tags/date_field.rb +15 -0
  45. data/lib/action_view/helpers/tags/date_select.rb +74 -0
  46. data/lib/action_view/helpers/tags/datetime_field.rb +32 -0
  47. data/lib/action_view/helpers/tags/datetime_local_field.rb +21 -0
  48. data/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  49. data/lib/action_view/helpers/tags/email_field.rb +10 -0
  50. data/lib/action_view/helpers/tags/file_field.rb +10 -0
  51. data/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
  52. data/lib/action_view/helpers/tags/hidden_field.rb +10 -0
  53. data/lib/action_view/helpers/tags/label.rb +81 -0
  54. data/lib/action_view/helpers/tags/month_field.rb +15 -0
  55. data/lib/action_view/helpers/tags/number_field.rb +20 -0
  56. data/lib/action_view/helpers/tags/password_field.rb +14 -0
  57. data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  58. data/lib/action_view/helpers/tags/radio_button.rb +33 -0
  59. data/lib/action_view/helpers/tags/range_field.rb +10 -0
  60. data/lib/action_view/helpers/tags/search_field.rb +27 -0
  61. data/lib/action_view/helpers/tags/select.rb +43 -0
  62. data/lib/action_view/helpers/tags/tel_field.rb +10 -0
  63. data/lib/action_view/helpers/tags/text_area.rb +24 -0
  64. data/lib/action_view/helpers/tags/text_field.rb +34 -0
  65. data/lib/action_view/helpers/tags/time_field.rb +15 -0
  66. data/lib/action_view/helpers/tags/time_select.rb +10 -0
  67. data/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
  68. data/lib/action_view/helpers/tags/translator.rb +39 -0
  69. data/lib/action_view/helpers/tags/url_field.rb +10 -0
  70. data/lib/action_view/helpers/tags/week_field.rb +15 -0
  71. data/lib/action_view/helpers/text_helper.rb +486 -0
  72. data/lib/action_view/helpers/translation_helper.rb +145 -0
  73. data/lib/action_view/helpers/url_helper.rb +676 -0
  74. data/lib/action_view/layouts.rb +433 -0
  75. data/lib/action_view/locale/en.yml +56 -0
  76. data/lib/action_view/log_subscriber.rb +96 -0
  77. data/lib/action_view/lookup_context.rb +316 -0
  78. data/lib/action_view/model_naming.rb +14 -0
  79. data/lib/action_view/path_set.rb +95 -0
  80. data/lib/action_view/railtie.rb +105 -0
  81. data/lib/action_view/record_identifier.rb +112 -0
  82. data/lib/action_view/renderer/abstract_renderer.rb +108 -0
  83. data/lib/action_view/renderer/partial_renderer.rb +563 -0
  84. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
  85. data/lib/action_view/renderer/renderer.rb +68 -0
  86. data/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
  87. data/lib/action_view/renderer/template_renderer.rb +108 -0
  88. data/lib/action_view/rendering.rb +171 -0
  89. data/lib/action_view/routing_url_for.rb +146 -0
  90. data/lib/action_view/tasks/cache_digests.rake +25 -0
  91. data/lib/action_view/template.rb +393 -0
  92. data/lib/action_view/template/error.rb +161 -0
  93. data/lib/action_view/template/handlers.rb +92 -0
  94. data/lib/action_view/template/handlers/builder.rb +25 -0
  95. data/lib/action_view/template/handlers/erb.rb +84 -0
  96. data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
  97. data/lib/action_view/template/handlers/html.rb +11 -0
  98. data/lib/action_view/template/handlers/raw.rb +11 -0
  99. data/lib/action_view/template/html.rb +43 -0
  100. data/lib/action_view/template/inline.rb +22 -0
  101. data/lib/action_view/template/raw_file.rb +28 -0
  102. data/lib/action_view/template/resolver.rb +394 -0
  103. data/lib/action_view/template/sources.rb +13 -0
  104. data/lib/action_view/template/sources/file.rb +17 -0
  105. data/lib/action_view/template/text.rb +35 -0
  106. data/lib/action_view/template/types.rb +57 -0
  107. data/lib/action_view/test_case.rb +300 -0
  108. data/lib/action_view/testing/resolvers.rb +67 -0
  109. data/lib/action_view/unbound_template.rb +32 -0
  110. data/lib/action_view/version.rb +10 -0
  111. data/lib/action_view/view_paths.rb +129 -0
  112. data/lib/assets/compiled/rails-ujs.js +746 -0
  113. metadata +260 -0
@@ -0,0 +1,470 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zlib"
4
+
5
+ module ActionView
6
+ # = Action View Asset URL Helpers
7
+ module Helpers #:nodoc:
8
+ # This module provides methods for generating asset paths and
9
+ # URLs.
10
+ #
11
+ # image_path("rails.png")
12
+ # # => "/assets/rails.png"
13
+ #
14
+ # image_url("rails.png")
15
+ # # => "http://www.example.com/assets/rails.png"
16
+ #
17
+ # === Using asset hosts
18
+ #
19
+ # By default, Rails links to these assets on the current host in the public
20
+ # folder, but you can direct Rails to link to assets from a dedicated asset
21
+ # server by setting <tt>ActionController::Base.asset_host</tt> in the application
22
+ # configuration, typically in <tt>config/environments/production.rb</tt>.
23
+ # For example, you'd define <tt>assets.example.com</tt> to be your asset
24
+ # host this way, inside the <tt>configure</tt> block of your environment-specific
25
+ # configuration files or <tt>config/application.rb</tt>:
26
+ #
27
+ # config.action_controller.asset_host = "assets.example.com"
28
+ #
29
+ # Helpers take that into account:
30
+ #
31
+ # image_tag("rails.png")
32
+ # # => <img src="http://assets.example.com/assets/rails.png" />
33
+ # stylesheet_link_tag("application")
34
+ # # => <link href="http://assets.example.com/assets/application.css" media="screen" rel="stylesheet" />
35
+ #
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".
43
+ #
44
+ # image_tag("rails.png")
45
+ # # => <img src="http://assets0.example.com/assets/rails.png" />
46
+ # stylesheet_link_tag("application")
47
+ # # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
48
+ #
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.
58
+ #
59
+ # Note: This is purely a browser performance optimization and is not meant
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.
63
+ #
64
+ # Alternatively, you can exert more control over the asset host by setting
65
+ # +asset_host+ to a proc like this:
66
+ #
67
+ # ActionController::Base.asset_host = Proc.new { |source|
68
+ # "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
69
+ # }
70
+ # image_tag("rails.png")
71
+ # # => <img src="http://assets1.example.com/assets/rails.png" />
72
+ # stylesheet_link_tag("application")
73
+ # # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
74
+ #
75
+ # The example above generates "http://assets1.example.com" and
76
+ # "http://assets2.example.com". This option is useful for example if
77
+ # you need fewer/more than four hosts, custom host names, etc.
78
+ #
79
+ # As you see the proc takes a +source+ parameter. That's a string with the
80
+ # absolute path of the asset, for example "/assets/rails.png".
81
+ #
82
+ # ActionController::Base.asset_host = Proc.new { |source|
83
+ # if source.ends_with?('.css')
84
+ # "http://stylesheets.example.com"
85
+ # else
86
+ # "http://assets.example.com"
87
+ # end
88
+ # }
89
+ # image_tag("rails.png")
90
+ # # => <img src="http://assets.example.com/assets/rails.png" />
91
+ # stylesheet_link_tag("application")
92
+ # # => <link href="http://stylesheets.example.com/assets/application.css" media="screen" rel="stylesheet" />
93
+ #
94
+ # Alternatively you may ask for a second parameter +request+. That one is
95
+ # particularly useful for serving assets from an SSL-protected page. The
96
+ # example proc below disables asset hosting for HTTPS connections, while
97
+ # still sending assets for plain HTTP requests from asset hosts. If you don't
98
+ # have SSL certificates for each of the asset hosts this technique allows you
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 `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+.
104
+ #
105
+ # config.action_controller.asset_host = Proc.new { |source, request|
106
+ # if request && request.ssl?
107
+ # "#{request.protocol}#{request.host_with_port}"
108
+ # else
109
+ # "#{request.protocol}assets.example.com"
110
+ # end
111
+ # }
112
+ #
113
+ # You can also implement a custom asset host object that responds to +call+
114
+ # and takes either one or two parameters just like the proc.
115
+ #
116
+ # config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
117
+ # "http://asset%d.example.com", "https://asset1.example.com"
118
+ # )
119
+ #
120
+ module AssetUrlHelper
121
+ URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i
122
+
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.
127
+ #
128
+ # All other asset *_path helpers delegate through this method.
129
+ #
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"
184
+ def asset_path(source, options = {})
185
+ raise ArgumentError, "nil is not a valid asset source" if source.nil?
186
+
187
+ source = source.to_s
188
+ return "" if source.blank?
189
+ return source if URI_REGEXP.match?(source)
190
+
191
+ tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, "")
192
+
193
+ if extname = compute_asset_extname(source, options)
194
+ source = "#{source}#{extname}"
195
+ end
196
+
197
+ if source[0] != ?/
198
+ if options[:skip_pipeline]
199
+ source = public_compute_asset_path(source, options)
200
+ else
201
+ source = compute_asset_path(source, options)
202
+ end
203
+ end
204
+
205
+ relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
206
+ if relative_url_root
207
+ source = File.join(relative_url_root, source) unless source.starts_with?("#{relative_url_root}/")
208
+ end
209
+
210
+ if host = compute_asset_host(source, options)
211
+ source = File.join(host, source)
212
+ end
213
+
214
+ "#{source}#{tail}"
215
+ end
216
+ alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with an asset_path named route
217
+
218
+ # Computes the full URL to an asset in the public directory. This
219
+ # will use +asset_path+ internally, so most of their behaviors
220
+ # will be the same. If :host options is set, it overwrites global
221
+ # +config.action_controller.asset_host+ setting.
222
+ #
223
+ # All other options provided are forwarded to +asset_path+ call.
224
+ #
225
+ # asset_url "application.js" # => http://example.com/assets/application.js
226
+ # asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js
227
+ #
228
+ def asset_url(source, options = {})
229
+ path_to_asset(source, options.merge(protocol: :request))
230
+ end
231
+ alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
232
+
233
+ ASSET_EXTENSIONS = {
234
+ javascript: ".js",
235
+ stylesheet: ".css"
236
+ }
237
+
238
+ # Compute extname to append to asset path. Returns +nil+ if
239
+ # nothing should be added.
240
+ def compute_asset_extname(source, options = {})
241
+ return if options[:extname] == false
242
+ extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
243
+ if extname && File.extname(source) != extname
244
+ extname
245
+ else
246
+ nil
247
+ end
248
+ end
249
+
250
+ # Maps asset types to public directory.
251
+ ASSET_PUBLIC_DIRECTORIES = {
252
+ audio: "/audios",
253
+ font: "/fonts",
254
+ image: "/images",
255
+ javascript: "/javascripts",
256
+ stylesheet: "/stylesheets",
257
+ video: "/videos"
258
+ }
259
+
260
+ # Computes asset path to public directory. Plugins and
261
+ # extensions can override this method to point to custom assets
262
+ # or generate digested paths or query strings.
263
+ def compute_asset_path(source, options = {})
264
+ dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
265
+ File.join(dir, source)
266
+ end
267
+ alias :public_compute_asset_path :compute_asset_path
268
+
269
+ # Pick an asset host for this source. Returns +nil+ if no host is set,
270
+ # the host if no wildcard is set, the host interpolated with the
271
+ # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
272
+ # or the value returned from invoking call on an object responding to call
273
+ # (proc or otherwise).
274
+ def compute_asset_host(source = "", options = {})
275
+ request = self.request if respond_to?(:request)
276
+ host = options[:host]
277
+ host ||= config.asset_host if defined? config.asset_host
278
+
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
288
+ end
289
+
290
+ host ||= request.base_url if request && options[:protocol] == :request
291
+ return unless host
292
+
293
+ if URI_REGEXP.match?(host)
294
+ host
295
+ else
296
+ protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
297
+ case protocol
298
+ when :relative
299
+ "//#{host}"
300
+ when :request
301
+ "#{request.protocol}#{host}"
302
+ else
303
+ "#{protocol}://#{host}"
304
+ end
305
+ end
306
+ end
307
+
308
+ # Computes the path to a JavaScript asset in the public javascripts directory.
309
+ # If the +source+ filename has no extension, .js will be appended (except for explicit URIs)
310
+ # Full paths from the document root will be passed through.
311
+ # Used internally by +javascript_include_tag+ to build the script path.
312
+ #
313
+ # javascript_path "xmlhr" # => /assets/xmlhr.js
314
+ # javascript_path "dir/xmlhr.js" # => /assets/dir/xmlhr.js
315
+ # javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
316
+ # javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
317
+ # javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
318
+ def javascript_path(source, options = {})
319
+ path_to_asset(source, { type: :javascript }.merge!(options))
320
+ end
321
+ alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
322
+
323
+ # Computes the full URL to a JavaScript asset in the public javascripts directory.
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
+ #
330
+ def javascript_url(source, options = {})
331
+ url_to_asset(source, { type: :javascript }.merge!(options))
332
+ end
333
+ alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
334
+
335
+ # Computes the path to a stylesheet asset in the public stylesheets directory.
336
+ # If the +source+ filename has no extension, .css will be appended (except for explicit URIs).
337
+ # Full paths from the document root will be passed through.
338
+ # Used internally by +stylesheet_link_tag+ to build the stylesheet path.
339
+ #
340
+ # stylesheet_path "style" # => /assets/style.css
341
+ # stylesheet_path "dir/style.css" # => /assets/dir/style.css
342
+ # stylesheet_path "/dir/style.css" # => /dir/style.css
343
+ # stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
344
+ # stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
345
+ def stylesheet_path(source, options = {})
346
+ path_to_asset(source, { type: :stylesheet }.merge!(options))
347
+ end
348
+ alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
349
+
350
+ # Computes the full URL to a stylesheet asset in the public stylesheets directory.
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
+ #
357
+ def stylesheet_url(source, options = {})
358
+ url_to_asset(source, { type: :stylesheet }.merge!(options))
359
+ end
360
+ alias_method :url_to_stylesheet, :stylesheet_url # aliased to avoid conflicts with a stylesheet_url named route
361
+
362
+ # Computes the path to an image asset.
363
+ # Full paths from the document root will be passed through.
364
+ # Used internally by +image_tag+ to build the image path:
365
+ #
366
+ # image_path("edit") # => "/assets/edit"
367
+ # image_path("edit.png") # => "/assets/edit.png"
368
+ # image_path("icons/edit.png") # => "/assets/icons/edit.png"
369
+ # image_path("/icons/edit.png") # => "/icons/edit.png"
370
+ # image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
371
+ #
372
+ # If you have images as application resources this method may conflict with their named routes.
373
+ # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
374
+ # plugin authors are encouraged to do so.
375
+ def image_path(source, options = {})
376
+ path_to_asset(source, { type: :image }.merge!(options))
377
+ end
378
+ alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
379
+
380
+ # Computes the full URL to an image asset.
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
+ #
387
+ def image_url(source, options = {})
388
+ url_to_asset(source, { type: :image }.merge!(options))
389
+ end
390
+ alias_method :url_to_image, :image_url # aliased to avoid conflicts with an image_url named route
391
+
392
+ # Computes the path to a video asset in the public videos directory.
393
+ # Full paths from the document root will be passed through.
394
+ # Used internally by +video_tag+ to build the video path.
395
+ #
396
+ # video_path("hd") # => /videos/hd
397
+ # video_path("hd.avi") # => /videos/hd.avi
398
+ # video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
399
+ # video_path("/trailers/hd.avi") # => /trailers/hd.avi
400
+ # video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
401
+ def video_path(source, options = {})
402
+ path_to_asset(source, { type: :video }.merge!(options))
403
+ end
404
+ alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
405
+
406
+ # Computes the full URL to a video asset in the public videos directory.
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
+ #
413
+ def video_url(source, options = {})
414
+ url_to_asset(source, { type: :video }.merge!(options))
415
+ end
416
+ alias_method :url_to_video, :video_url # aliased to avoid conflicts with a video_url named route
417
+
418
+ # Computes the path to an audio asset in the public audios directory.
419
+ # Full paths from the document root will be passed through.
420
+ # Used internally by +audio_tag+ to build the audio path.
421
+ #
422
+ # audio_path("horse") # => /audios/horse
423
+ # audio_path("horse.wav") # => /audios/horse.wav
424
+ # audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
425
+ # audio_path("/sounds/horse.wav") # => /sounds/horse.wav
426
+ # audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
427
+ def audio_path(source, options = {})
428
+ path_to_asset(source, { type: :audio }.merge!(options))
429
+ end
430
+ alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
431
+
432
+ # Computes the full URL to an audio asset in the public audios directory.
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
+ #
439
+ def audio_url(source, options = {})
440
+ url_to_asset(source, { type: :audio }.merge!(options))
441
+ end
442
+ alias_method :url_to_audio, :audio_url # aliased to avoid conflicts with an audio_url named route
443
+
444
+ # Computes the path to a font asset.
445
+ # Full paths from the document root will be passed through.
446
+ #
447
+ # font_path("font") # => /fonts/font
448
+ # font_path("font.ttf") # => /fonts/font.ttf
449
+ # font_path("dir/font.ttf") # => /fonts/dir/font.ttf
450
+ # font_path("/dir/font.ttf") # => /dir/font.ttf
451
+ # font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
452
+ def font_path(source, options = {})
453
+ path_to_asset(source, { type: :font }.merge!(options))
454
+ end
455
+ alias_method :path_to_font, :font_path # aliased to avoid conflicts with a font_path named route
456
+
457
+ # Computes the full URL to a font asset.
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
+ #
464
+ def font_url(source, options = {})
465
+ url_to_asset(source, { type: :font }.merge!(options))
466
+ end
467
+ alias_method :url_to_font, :font_url # aliased to avoid conflicts with a font_url named route
468
+ end
469
+ end
470
+ end