actionview 5.2.3

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 (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +142 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +38 -0
  5. data/lib/action_view.rb +97 -0
  6. data/lib/action_view/base.rb +215 -0
  7. data/lib/action_view/buffers.rb +52 -0
  8. data/lib/action_view/context.rb +36 -0
  9. data/lib/action_view/dependency_tracker.rb +175 -0
  10. data/lib/action_view/digestor.rb +134 -0
  11. data/lib/action_view/flows.rb +76 -0
  12. data/lib/action_view/gem_version.rb +17 -0
  13. data/lib/action_view/helpers.rb +68 -0
  14. data/lib/action_view/helpers/active_model_helper.rb +55 -0
  15. data/lib/action_view/helpers/asset_tag_helper.rb +511 -0
  16. data/lib/action_view/helpers/asset_url_helper.rb +469 -0
  17. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  18. data/lib/action_view/helpers/cache_helper.rb +263 -0
  19. data/lib/action_view/helpers/capture_helper.rb +212 -0
  20. data/lib/action_view/helpers/controller_helper.rb +36 -0
  21. data/lib/action_view/helpers/csp_helper.rb +24 -0
  22. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  23. data/lib/action_view/helpers/date_helper.rb +1156 -0
  24. data/lib/action_view/helpers/debug_helper.rb +36 -0
  25. data/lib/action_view/helpers/form_helper.rb +2337 -0
  26. data/lib/action_view/helpers/form_options_helper.rb +887 -0
  27. data/lib/action_view/helpers/form_tag_helper.rb +917 -0
  28. data/lib/action_view/helpers/javascript_helper.rb +94 -0
  29. data/lib/action_view/helpers/number_helper.rb +451 -0
  30. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  31. data/lib/action_view/helpers/record_tag_helper.rb +23 -0
  32. data/lib/action_view/helpers/rendering_helper.rb +99 -0
  33. data/lib/action_view/helpers/sanitize_helper.rb +177 -0
  34. data/lib/action_view/helpers/tag_helper.rb +313 -0
  35. data/lib/action_view/helpers/tags.rb +44 -0
  36. data/lib/action_view/helpers/tags/base.rb +192 -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 +44 -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 +141 -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 +274 -0
  78. data/lib/action_view/model_naming.rb +14 -0
  79. data/lib/action_view/path_set.rb +100 -0
  80. data/lib/action_view/railtie.rb +82 -0
  81. data/lib/action_view/record_identifier.rb +112 -0
  82. data/lib/action_view/renderer/abstract_renderer.rb +55 -0
  83. data/lib/action_view/renderer/partial_renderer.rb +552 -0
  84. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +57 -0
  85. data/lib/action_view/renderer/renderer.rb +56 -0
  86. data/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
  87. data/lib/action_view/renderer/template_renderer.rb +102 -0
  88. data/lib/action_view/rendering.rb +151 -0
  89. data/lib/action_view/routing_url_for.rb +145 -0
  90. data/lib/action_view/tasks/cache_digests.rake +25 -0
  91. data/lib/action_view/template.rb +361 -0
  92. data/lib/action_view/template/error.rb +141 -0
  93. data/lib/action_view/template/handlers.rb +66 -0
  94. data/lib/action_view/template/handlers/builder.rb +25 -0
  95. data/lib/action_view/template/handlers/erb.rb +74 -0
  96. data/lib/action_view/template/handlers/erb/erubi.rb +83 -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 +34 -0
  100. data/lib/action_view/template/resolver.rb +391 -0
  101. data/lib/action_view/template/text.rb +33 -0
  102. data/lib/action_view/template/types.rb +57 -0
  103. data/lib/action_view/test_case.rb +300 -0
  104. data/lib/action_view/testing/resolvers.rb +54 -0
  105. data/lib/action_view/version.rb +10 -0
  106. data/lib/action_view/view_paths.rb +105 -0
  107. data/lib/assets/compiled/rails-ujs.js +720 -0
  108. metadata +255 -0
@@ -0,0 +1,469 @@
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 via a Rake task. Make sure to use a +Proc+ instead of a lambda,
102
+ # since a +Proc+ allows missing parameters and sets them to +nil+.
103
+ #
104
+ # config.action_controller.asset_host = Proc.new { |source, request|
105
+ # if request && request.ssl?
106
+ # "#{request.protocol}#{request.host_with_port}"
107
+ # else
108
+ # "#{request.protocol}assets.example.com"
109
+ # end
110
+ # }
111
+ #
112
+ # You can also implement a custom asset host object that responds to +call+
113
+ # and takes either one or two parameters just like the proc.
114
+ #
115
+ # config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
116
+ # "http://asset%d.example.com", "https://asset1.example.com"
117
+ # )
118
+ #
119
+ module AssetUrlHelper
120
+ URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i
121
+
122
+ # This is the entry point for all assets.
123
+ # When using the asset pipeline (i.e. sprockets and sprockets-rails), the
124
+ # behavior is "enhanced". You can bypass the asset pipeline by passing in
125
+ # <tt>skip_pipeline: true</tt> to the options.
126
+ #
127
+ # All other asset *_path helpers delegate through this method.
128
+ #
129
+ # === With the asset pipeline
130
+ #
131
+ # All options passed to +asset_path+ will be passed to +compute_asset_path+
132
+ # which is implemented by sprockets-rails.
133
+ #
134
+ # asset_path("application.js") # => "/assets/application-60aa4fdc5cea14baf5400fba1abf4f2a46a5166bad4772b1effe341570f07de9.js"
135
+ #
136
+ # === Without the asset pipeline (<tt>skip_pipeline: true</tt>)
137
+ #
138
+ # Accepts a <tt>type</tt> option that can specify the asset's extension. No error
139
+ # checking is done to verify the source passed into +asset_path+ is valid
140
+ # and that the file exists on disk.
141
+ #
142
+ # asset_path("application.js", skip_pipeline: true) # => "application.js"
143
+ # asset_path("filedoesnotexist.png", skip_pipeline: true) # => "filedoesnotexist.png"
144
+ # asset_path("application", type: :javascript, skip_pipeline: true) # => "/javascripts/application.js"
145
+ # asset_path("application", type: :stylesheet, skip_pipeline: true) # => "/stylesheets/application.css"
146
+ #
147
+ # === Options applying to all assets
148
+ #
149
+ # Below lists scenarios that apply to +asset_path+ whether or not you're
150
+ # using the asset pipeline.
151
+ #
152
+ # - All fully qualified URLs are returned immediately. This bypasses the
153
+ # asset pipeline and all other behavior described.
154
+ #
155
+ # asset_path("http://www.example.com/js/xmlhr.js") # => "http://www.example.com/js/xmlhr.js"
156
+ #
157
+ # - All assets that begin with a forward slash are assumed to be full
158
+ # URLs and will not be expanded. This will bypass the asset pipeline.
159
+ #
160
+ # asset_path("/foo.png") # => "/foo.png"
161
+ #
162
+ # - All blank strings will be returned immediately. This bypasses the
163
+ # asset pipeline and all other behavior described.
164
+ #
165
+ # asset_path("") # => ""
166
+ #
167
+ # - If <tt>config.relative_url_root</tt> is specified, all assets will have that
168
+ # root prepended.
169
+ #
170
+ # Rails.application.config.relative_url_root = "bar"
171
+ # asset_path("foo.js", skip_pipeline: true) # => "bar/foo.js"
172
+ #
173
+ # - A different asset host can be specified via <tt>config.action_controller.asset_host</tt>
174
+ # this is commonly used in conjunction with a CDN.
175
+ #
176
+ # Rails.application.config.action_controller.asset_host = "assets.example.com"
177
+ # asset_path("foo.js", skip_pipeline: true) # => "http://assets.example.com/foo.js"
178
+ #
179
+ # - An extension name can be specified manually with <tt>extname</tt>.
180
+ #
181
+ # asset_path("foo", skip_pipeline: true, extname: ".js") # => "/foo.js"
182
+ # asset_path("foo.css", skip_pipeline: true, extname: ".js") # => "/foo.css.js"
183
+ def asset_path(source, options = {})
184
+ raise ArgumentError, "nil is not a valid asset source" if source.nil?
185
+
186
+ source = source.to_s
187
+ return "" if source.blank?
188
+ return source if URI_REGEXP.match?(source)
189
+
190
+ tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, "".freeze)
191
+
192
+ if extname = compute_asset_extname(source, options)
193
+ source = "#{source}#{extname}"
194
+ end
195
+
196
+ if source[0] != ?/
197
+ if options[:skip_pipeline]
198
+ source = public_compute_asset_path(source, options)
199
+ else
200
+ source = compute_asset_path(source, options)
201
+ end
202
+ end
203
+
204
+ relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
205
+ if relative_url_root
206
+ source = File.join(relative_url_root, source) unless source.starts_with?("#{relative_url_root}/")
207
+ end
208
+
209
+ if host = compute_asset_host(source, options)
210
+ source = File.join(host, source)
211
+ end
212
+
213
+ "#{source}#{tail}"
214
+ end
215
+ alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with an asset_path named route
216
+
217
+ # Computes the full URL to an asset in the public directory. This
218
+ # will use +asset_path+ internally, so most of their behaviors
219
+ # will be the same. If :host options is set, it overwrites global
220
+ # +config.action_controller.asset_host+ setting.
221
+ #
222
+ # All other options provided are forwarded to +asset_path+ call.
223
+ #
224
+ # asset_url "application.js" # => http://example.com/assets/application.js
225
+ # asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js
226
+ #
227
+ def asset_url(source, options = {})
228
+ path_to_asset(source, options.merge(protocol: :request))
229
+ end
230
+ alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
231
+
232
+ ASSET_EXTENSIONS = {
233
+ javascript: ".js",
234
+ stylesheet: ".css"
235
+ }
236
+
237
+ # Compute extname to append to asset path. Returns +nil+ if
238
+ # nothing should be added.
239
+ def compute_asset_extname(source, options = {})
240
+ return if options[:extname] == false
241
+ extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
242
+ if extname && File.extname(source) != extname
243
+ extname
244
+ else
245
+ nil
246
+ end
247
+ end
248
+
249
+ # Maps asset types to public directory.
250
+ ASSET_PUBLIC_DIRECTORIES = {
251
+ audio: "/audios",
252
+ font: "/fonts",
253
+ image: "/images",
254
+ javascript: "/javascripts",
255
+ stylesheet: "/stylesheets",
256
+ video: "/videos"
257
+ }
258
+
259
+ # Computes asset path to public directory. Plugins and
260
+ # extensions can override this method to point to custom assets
261
+ # or generate digested paths or query strings.
262
+ def compute_asset_path(source, options = {})
263
+ dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
264
+ File.join(dir, source)
265
+ end
266
+ alias :public_compute_asset_path :compute_asset_path
267
+
268
+ # Pick an asset host for this source. Returns +nil+ if no host is set,
269
+ # the host if no wildcard is set, the host interpolated with the
270
+ # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
271
+ # or the value returned from invoking call on an object responding to call
272
+ # (proc or otherwise).
273
+ def compute_asset_host(source = "", options = {})
274
+ request = self.request if respond_to?(:request)
275
+ host = options[:host]
276
+ host ||= config.asset_host if defined? config.asset_host
277
+
278
+ if host
279
+ if host.respond_to?(:call)
280
+ arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
281
+ args = [source]
282
+ args << request if request && (arity > 1 || arity < 0)
283
+ host = host.call(*args)
284
+ elsif host.include?("%d")
285
+ host = host % (Zlib.crc32(source) % 4)
286
+ end
287
+ end
288
+
289
+ host ||= request.base_url if request && options[:protocol] == :request
290
+ return unless host
291
+
292
+ if URI_REGEXP.match?(host)
293
+ host
294
+ else
295
+ protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
296
+ case protocol
297
+ when :relative
298
+ "//#{host}"
299
+ when :request
300
+ "#{request.protocol}#{host}"
301
+ else
302
+ "#{protocol}://#{host}"
303
+ end
304
+ end
305
+ end
306
+
307
+ # Computes the path to a JavaScript asset in the public javascripts directory.
308
+ # If the +source+ filename has no extension, .js will be appended (except for explicit URIs)
309
+ # Full paths from the document root will be passed through.
310
+ # Used internally by +javascript_include_tag+ to build the script path.
311
+ #
312
+ # javascript_path "xmlhr" # => /assets/xmlhr.js
313
+ # javascript_path "dir/xmlhr.js" # => /assets/dir/xmlhr.js
314
+ # javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
315
+ # javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
316
+ # javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
317
+ def javascript_path(source, options = {})
318
+ path_to_asset(source, { type: :javascript }.merge!(options))
319
+ end
320
+ alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
321
+
322
+ # Computes the full URL to a JavaScript asset in the public javascripts directory.
323
+ # This will use +javascript_path+ internally, so most of their behaviors will be the same.
324
+ # Since +javascript_url+ is based on +asset_url+ method you can set :host options. If :host
325
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
326
+ #
327
+ # javascript_url "js/xmlhr.js", host: "http://stage.example.com" # => http://stage.example.com/assets/js/xmlhr.js
328
+ #
329
+ def javascript_url(source, options = {})
330
+ url_to_asset(source, { type: :javascript }.merge!(options))
331
+ end
332
+ alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
333
+
334
+ # Computes the path to a stylesheet asset in the public stylesheets directory.
335
+ # If the +source+ filename has no extension, .css will be appended (except for explicit URIs).
336
+ # Full paths from the document root will be passed through.
337
+ # Used internally by +stylesheet_link_tag+ to build the stylesheet path.
338
+ #
339
+ # stylesheet_path "style" # => /assets/style.css
340
+ # stylesheet_path "dir/style.css" # => /assets/dir/style.css
341
+ # stylesheet_path "/dir/style.css" # => /dir/style.css
342
+ # stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
343
+ # stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
344
+ def stylesheet_path(source, options = {})
345
+ path_to_asset(source, { type: :stylesheet }.merge!(options))
346
+ end
347
+ alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
348
+
349
+ # Computes the full URL to a stylesheet asset in the public stylesheets directory.
350
+ # This will use +stylesheet_path+ internally, so most of their behaviors will be the same.
351
+ # Since +stylesheet_url+ is based on +asset_url+ method you can set :host options. If :host
352
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
353
+ #
354
+ # stylesheet_url "css/style.css", host: "http://stage.example.com" # => http://stage.example.com/assets/css/style.css
355
+ #
356
+ def stylesheet_url(source, options = {})
357
+ url_to_asset(source, { type: :stylesheet }.merge!(options))
358
+ end
359
+ alias_method :url_to_stylesheet, :stylesheet_url # aliased to avoid conflicts with a stylesheet_url named route
360
+
361
+ # Computes the path to an image asset.
362
+ # Full paths from the document root will be passed through.
363
+ # Used internally by +image_tag+ to build the image path:
364
+ #
365
+ # image_path("edit") # => "/assets/edit"
366
+ # image_path("edit.png") # => "/assets/edit.png"
367
+ # image_path("icons/edit.png") # => "/assets/icons/edit.png"
368
+ # image_path("/icons/edit.png") # => "/icons/edit.png"
369
+ # image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
370
+ #
371
+ # If you have images as application resources this method may conflict with their named routes.
372
+ # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
373
+ # plugin authors are encouraged to do so.
374
+ def image_path(source, options = {})
375
+ path_to_asset(source, { type: :image }.merge!(options))
376
+ end
377
+ alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
378
+
379
+ # Computes the full URL to an image asset.
380
+ # This will use +image_path+ internally, so most of their behaviors will be the same.
381
+ # Since +image_url+ is based on +asset_url+ method you can set :host options. If :host
382
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
383
+ #
384
+ # image_url "edit.png", host: "http://stage.example.com" # => http://stage.example.com/assets/edit.png
385
+ #
386
+ def image_url(source, options = {})
387
+ url_to_asset(source, { type: :image }.merge!(options))
388
+ end
389
+ alias_method :url_to_image, :image_url # aliased to avoid conflicts with an image_url named route
390
+
391
+ # Computes the path to a video asset in the public videos directory.
392
+ # Full paths from the document root will be passed through.
393
+ # Used internally by +video_tag+ to build the video path.
394
+ #
395
+ # video_path("hd") # => /videos/hd
396
+ # video_path("hd.avi") # => /videos/hd.avi
397
+ # video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
398
+ # video_path("/trailers/hd.avi") # => /trailers/hd.avi
399
+ # video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
400
+ def video_path(source, options = {})
401
+ path_to_asset(source, { type: :video }.merge!(options))
402
+ end
403
+ alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
404
+
405
+ # Computes the full URL to a video asset in the public videos directory.
406
+ # This will use +video_path+ internally, so most of their behaviors will be the same.
407
+ # Since +video_url+ is based on +asset_url+ method you can set :host options. If :host
408
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
409
+ #
410
+ # video_url "hd.avi", host: "http://stage.example.com" # => http://stage.example.com/videos/hd.avi
411
+ #
412
+ def video_url(source, options = {})
413
+ url_to_asset(source, { type: :video }.merge!(options))
414
+ end
415
+ alias_method :url_to_video, :video_url # aliased to avoid conflicts with a video_url named route
416
+
417
+ # Computes the path to an audio asset in the public audios directory.
418
+ # Full paths from the document root will be passed through.
419
+ # Used internally by +audio_tag+ to build the audio path.
420
+ #
421
+ # audio_path("horse") # => /audios/horse
422
+ # audio_path("horse.wav") # => /audios/horse.wav
423
+ # audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
424
+ # audio_path("/sounds/horse.wav") # => /sounds/horse.wav
425
+ # audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
426
+ def audio_path(source, options = {})
427
+ path_to_asset(source, { type: :audio }.merge!(options))
428
+ end
429
+ alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
430
+
431
+ # Computes the full URL to an audio asset in the public audios directory.
432
+ # This will use +audio_path+ internally, so most of their behaviors will be the same.
433
+ # Since +audio_url+ is based on +asset_url+ method you can set :host options. If :host
434
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
435
+ #
436
+ # audio_url "horse.wav", host: "http://stage.example.com" # => http://stage.example.com/audios/horse.wav
437
+ #
438
+ def audio_url(source, options = {})
439
+ url_to_asset(source, { type: :audio }.merge!(options))
440
+ end
441
+ alias_method :url_to_audio, :audio_url # aliased to avoid conflicts with an audio_url named route
442
+
443
+ # Computes the path to a font asset.
444
+ # Full paths from the document root will be passed through.
445
+ #
446
+ # font_path("font") # => /fonts/font
447
+ # font_path("font.ttf") # => /fonts/font.ttf
448
+ # font_path("dir/font.ttf") # => /fonts/dir/font.ttf
449
+ # font_path("/dir/font.ttf") # => /dir/font.ttf
450
+ # font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
451
+ def font_path(source, options = {})
452
+ path_to_asset(source, { type: :font }.merge!(options))
453
+ end
454
+ alias_method :path_to_font, :font_path # aliased to avoid conflicts with a font_path named route
455
+
456
+ # Computes the full URL to a font asset.
457
+ # This will use +font_path+ internally, so most of their behaviors will be the same.
458
+ # Since +font_url+ is based on +asset_url+ method you can set :host options. If :host
459
+ # options is set, it overwrites global +config.action_controller.asset_host+ setting.
460
+ #
461
+ # font_url "font.ttf", host: "http://stage.example.com" # => http://stage.example.com/fonts/font.ttf
462
+ #
463
+ def font_url(source, options = {})
464
+ url_to_asset(source, { type: :font }.merge!(options))
465
+ end
466
+ alias_method :url_to_font, :font_url # aliased to avoid conflicts with a font_url named route
467
+ end
468
+ end
469
+ end