Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 323 lines (302 sloc) 15.181 kB
08e5104 @lest allow to pass multiple sources to audio/video tags without using array
lest authored
1 require 'active_support/core_ext/array/extract_options'
2 require 'active_support/core_ext/hash/keys'
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
3 require 'action_view/helpers/asset_url_helper'
0ac79d0 @spohlenz Include TagHelper within AssetTagHelper
spohlenz authored
4 require 'action_view/helpers/tag_helper'
2a5fc27 @dhh Added AssetTagHelper that provides methods for linking a HTML page to…
dhh authored
5
6 module ActionView
5a0bc2c @rizwanreza Adds title and description where needed.
rizwanreza authored
7 # = Action View Asset Tag Helpers
6c914d9 @technoweenie Add more extensive documentation to the AssetTagHelper. Closes #6452…
technoweenie authored
8 module Helpers #:nodoc:
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
9 # This module provides methods for generating HTML that links views to assets such
7359597 @josh Wrap AssetTagHelper's computed public path cache in a threadsafe store
josh authored
10 # as images, javascripts, stylesheets, and feeds. These methods do not verify
39e1ac6 @lifo Merge docrails
lifo authored
11 # the assets exist before linking to them:
12 #
13 # image_tag("rails.png")
8a9e031 @vijaydev update some examples in asset tag helper docs [ci skip]
vijaydev authored
14 # # => <img alt="Rails" src="/assets/rails.png" />
39e1ac6 @lifo Merge docrails
lifo authored
15 # stylesheet_link_tag("application")
8a9e031 @vijaydev update some examples in asset tag helper docs [ci skip]
vijaydev authored
16 # # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
2a5fc27 @dhh Added AssetTagHelper that provides methods for linking a HTML page to…
dhh authored
17 module AssetTagHelper
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
18 extend ActiveSupport::Concern
19
20 include AssetUrlHelper
0ac79d0 @spohlenz Include TagHelper within AssetTagHelper
spohlenz authored
21 include TagHelper
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
22
23 # Returns an HTML script tag for each of the +sources+ provided.
24 #
25 # Sources may be paths to JavaScript files. Relative paths are assumed to be relative
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
26 # to <tt>assets/javascripts</tt>, full paths are assumed to be relative to the document
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
27 # root. Relative paths are idiomatic, use absolute paths only when needed.
28 #
0855f04 @nathanstitt Add "extname" option to javascript_include_tag
nathanstitt authored
29 # When passing paths, the ".js" extension is optional. If you do not want ".js"
30 # appended to the path <tt>extname: false</tt> can be set on the options.
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
31 #
32 # You can modify the HTML attributes of the script tag by passing a hash as the
33 # last argument.
34 #
2a6cfce @hpneo Update documentation for javascript_include_tag [ci skip]
hpneo authored
35 # When the Asset Pipeline is enabled, you can pass the name of your manifest as
36 # source, and include other JavaScript or CoffeeScript files inside the manifest.
37 #
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
38 # javascript_include_tag "xmlhr"
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
39 # # => <script src="/assets/xmlhr.js?1284139606"></script>
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
40 #
0855f04 @nathanstitt Add "extname" option to javascript_include_tag
nathanstitt authored
41 # javascript_include_tag "template.jst", extname: false
42 # # => <script src="/assets/template.jst?1284139606"></script>
43 #
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
44 # javascript_include_tag "xmlhr.js"
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
45 # # => <script src="/assets/xmlhr.js?1284139606"></script>
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
46 #
47 # javascript_include_tag "common.javascript", "/elsewhere/cools"
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
48 # # => <script src="/assets/common.javascript?1284139606"></script>
40b0cec @ccarruitero fix error in AssertTagHelper documentation [ci skip]
ccarruitero authored
49 # # <script src="/elsewhere/cools.js?1423139606"></script>
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
50 #
51 # javascript_include_tag "http://www.example.com/xmlhr"
52 # # => <script src="http://www.example.com/xmlhr"></script>
53 #
54 # javascript_include_tag "http://www.example.com/xmlhr.js"
55 # # => <script src="http://www.example.com/xmlhr.js"></script>
56 def javascript_include_tag(*sources)
57 options = sources.extract_options!.stringify_keys
0855f04 @nathanstitt Add "extname" option to javascript_include_tag
nathanstitt authored
58 path_options = options.extract!('protocol', 'extname').symbolize_keys
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
59 sources.uniq.map { |source|
60 tag_options = {
0a6d8fb @nashby handle protocol option in stylesheet_link_tag and javascript_include_tag
nashby authored
61 "src" => path_to_javascript(source, path_options)
defea35 @vipulnsward change some more merge to merge! on new hashes
vipulnsward authored
62 }.merge!(options)
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
63 content_tag(:script, "", tag_options)
64 }.join("\n").html_safe
65 end
66
67 # Returns a stylesheet link tag for the sources specified as arguments. If
68 # you don't specify an extension, <tt>.css</tt> will be appended automatically.
69 # You can modify the link attributes by passing a hash as the last argument.
70 # For historical reasons, the 'media' attribute will always be present and defaults
75afe19 @carsonmcdonald Fix typo
carsonmcdonald authored
71 # to "screen", so you must explicitly set it to "all" for the stylesheet(s) to
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
72 # apply to all media types.
73 #
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
74 # stylesheet_link_tag "style"
75 # # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
76 #
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
77 # stylesheet_link_tag "style.css"
78 # # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
79 #
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
80 # stylesheet_link_tag "http://www.example.com/style.css"
81 # # => <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
82 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored
83 # stylesheet_link_tag "style", media: "all"
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
84 # # => <link href="/assets/style.css" media="all" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
85 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored
86 # stylesheet_link_tag "style", media: "print"
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
87 # # => <link href="/assets/style.css" media="print" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
88 #
0ce7ea6 @ccarruitero update AssetTagHelper documentation [ci skip]
ccarruitero authored
89 # stylesheet_link_tag "random.styles", "/css/stylish"
90 # # => <link href="/assets/random.styles" media="screen" rel="stylesheet" />
40b0cec @ccarruitero fix error in AssertTagHelper documentation [ci skip]
ccarruitero authored
91 # # <link href="/css/stylish.css" media="screen" rel="stylesheet" />
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
92 def stylesheet_link_tag(*sources)
93 options = sources.extract_options!.stringify_keys
0a6d8fb @nashby handle protocol option in stylesheet_link_tag and javascript_include_tag
nashby authored
94 path_options = options.extract!('protocol').symbolize_keys
95
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
96 sources.uniq.map { |source|
97 tag_options = {
98 "rel" => "stylesheet",
99 "media" => "screen",
0a6d8fb @nashby handle protocol option in stylesheet_link_tag and javascript_include_tag
nashby authored
100 "href" => path_to_stylesheet(source, path_options)
defea35 @vipulnsward change some more merge to merge! on new hashes
vipulnsward authored
101 }.merge!(options)
9fa1a54 @josh Split asset url helpers into seperate AssetUrlHelper
josh authored
102 tag(:link, tag_options)
103 }.join("\n").html_safe
104 end
105
6a609db @joshk incorporated most of the feedback from José
joshk authored
106 # Returns a link tag that browsers and news readers can use to auto-detect
7f8f05f @tomstuart Stop referring to Atom as "ATOM"
tomstuart authored
107 # an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
6a609db @joshk incorporated most of the feedback from José
joshk authored
108 # <tt>:atom</tt>. Control the link options in url_for format using the
109 # +url_options+. You can modify the LINK tag itself in +tag_options+.
110 #
111 # ==== Options
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
112 #
6a609db @joshk incorporated most of the feedback from José
joshk authored
113 # * <tt>:rel</tt> - Specify the relation of this link, defaults to "alternate"
114 # * <tt>:type</tt> - Override the auto-generated mime type
115 # * <tt>:title</tt> - Specify the title of the link, defaults to the +type+
116 #
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
117 # ==== Examples
118 #
33f6209 @alvaropereyra Removes unneeded 'Example' tags and whitespaces [ci skip]
alvaropereyra authored
119 # auto_discovery_link_tag
120 # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
121 # auto_discovery_link_tag(:atom)
122 # # => <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
123 # auto_discovery_link_tag(:rss, {action: "feed"})
124 # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
125 # auto_discovery_link_tag(:rss, {action: "feed"}, {title: "My RSS"})
126 # # => <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.currenthost.com/controller/feed" />
127 # auto_discovery_link_tag(:rss, {controller: "news", action: "feed"})
128 # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/news/feed" />
129 # auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "Example RSS"})
130 # # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
6a609db @joshk incorporated most of the feedback from José
joshk authored
131 def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
7abc0c7 @drogus Deprecate mime types lookup in auto_discovery_link_tag
drogus authored
132 if !(type == :rss || type == :atom) && tag_options[:type].blank?
bc5314a @kennyj Raise ArgumentError to fix Rails 4.1 deprecation warn message.
kennyj authored
133 raise ArgumentError.new("You should pass :type tag_option key explicitly, because you have passed #{type} type other than :rss or :atom.")
7abc0c7 @drogus Deprecate mime types lookup in auto_discovery_link_tag
drogus authored
134 end
135
6a609db @joshk incorporated most of the feedback from José
joshk authored
136 tag(
137 "link",
138 "rel" => tag_options[:rel] || "alternate",
139 "type" => tag_options[:type] || Mime::Type.lookup_by_extension(type.to_s).to_s,
140 "title" => tag_options[:title] || type.to_s.upcase,
141 "href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options
142 )
143 end
144
e1c0aa4 @alvaropereyra Improves documentation on favicon_link_tag
alvaropereyra authored
145 # Returns a link loading a favicon file. You may specify a different file
146 # in the first argument. The helper accepts an additional options hash where
147 # you can override "rel" and "type".
6a609db @joshk incorporated most of the feedback from José
joshk authored
148 #
e1c0aa4 @alvaropereyra Improves documentation on favicon_link_tag
alvaropereyra authored
149 # ==== Options
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
150 #
2b847a0 @vijaydev copy edits [ci skip]
vijaydev authored
151 # * <tt>:rel</tt> - Specify the relation of this link, defaults to 'shortcut icon'
e1c0aa4 @alvaropereyra Improves documentation on favicon_link_tag
alvaropereyra authored
152 # * <tt>:type</tt> - Override the auto-generated mime type, defaults to 'image/vnd.microsoft.icon'
6a609db @joshk incorporated most of the feedback from José
joshk authored
153 #
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
154 # ==== Examples
155 #
256ae7d @rafaelfranca Merge pull request #12788 from kylefritz/patch-1
rafaelfranca authored
156 # favicon_link_tag 'myicon.ico'
47bf072 @juno Fix typo in documentation comment
juno authored
157 # # => <link href="/assets/myicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
6a609db @joshk incorporated most of the feedback from José
joshk authored
158 #
e1c0aa4 @alvaropereyra Improves documentation on favicon_link_tag
alvaropereyra authored
159 # Mobile Safari looks for a different <link> tag, pointing to an image that
6a609db @joshk incorporated most of the feedback from José
joshk authored
160 # will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
161 # The following call would generate such a tag:
162 #
256ae7d @rafaelfranca Merge pull request #12788 from kylefritz/patch-1
rafaelfranca authored
163 # favicon_link_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png'
e1c0aa4 @alvaropereyra Improves documentation on favicon_link_tag
alvaropereyra authored
164 # # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" />
3893979 @spastorino Revert "Revert "Merge pull request #4803 from lucascaton/master""
spastorino authored
165 def favicon_link_tag(source='favicon.ico', options={})
6a609db @joshk incorporated most of the feedback from José
joshk authored
166 tag('link', {
167 :rel => 'shortcut icon',
168 :type => 'image/vnd.microsoft.icon',
169 :href => path_to_image(source)
defea35 @vipulnsward change some more merge to merge! on new hashes
vipulnsward authored
170 }.merge!(options.symbolize_keys))
6a609db @joshk incorporated most of the feedback from José
joshk authored
171 end
172
2a6cfce @hpneo Update documentation for javascript_include_tag [ci skip]
hpneo authored
173 # Returns an HTML image tag for the +source+. The +source+ can be a full
65c3b12 @vijaydev update example outputs of some asset helpers
vijaydev authored
174 # path or a file.
6a609db @joshk incorporated most of the feedback from José
joshk authored
175 #
176 # ==== Options
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
177 #
6a609db @joshk incorporated most of the feedback from José
joshk authored
178 # You can add HTML attributes using the +options+. The +options+ supports
179 # three additional keys for convenience and conformance:
180 #
181 # * <tt>:alt</tt> - If no alt text is given, the file name part of the
182 # +source+ is used (capitalized and without the extension)
2b9bce8 @NARKOZ allow to pass numerical value to size option in image_tag
NARKOZ authored
183 # * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes
184 # width="30" and height="45", and "50" becomes width="50" and height="50".
185 # <tt>:size</tt> will be ignored if the value is not in the correct format.
6a609db @joshk incorporated most of the feedback from José
joshk authored
186 #
b8ef4f0 fix broken examples format in image_tag helper [ci skip]
Francesco Rodriguez authored
187 # ==== Examples
188 #
33f6209 @alvaropereyra Removes unneeded 'Example' tags and whitespaces [ci skip]
alvaropereyra authored
189 # image_tag("icon")
190 # # => <img alt="Icon" src="/assets/icon" />
191 # image_tag("icon.png")
192 # # => <img alt="Icon" src="/assets/icon.png" />
193 # image_tag("icon.png", size: "16x10", alt: "Edit Entry")
194 # # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
195 # image_tag("/icons/icon.gif", size: "16")
196 # # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
197 # image_tag("/icons/icon.gif", height: '32', width: '32')
198 # # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
199 # image_tag("/icons/icon.gif", class: "menu_icon")
200 # # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
fc54787 @lest do not modify options in image_tag
lest authored
201 def image_tag(source, options={})
f4d2695 @lest use `symbolize_keys` instead of `dup.symbolize_keys!`
lest authored
202 options = options.symbolize_keys
6a609db @joshk incorporated most of the feedback from José
joshk authored
203
204 src = options[:src] = path_to_image(source)
205
3e9ec24 @KL-7 Render img tag with empty src if empty string is passed to image_tag.
KL-7 authored
206 unless src =~ /^(?:cid|data):/ || src.blank?
a0960ec @fxn the generated ALT attribute for images no longer contains the digest,…
fxn authored
207 options[:alt] = options.fetch(:alt){ image_alt(src) }
6a609db @joshk incorporated most of the feedback from José
joshk authored
208 end
209
eab0520 @josevalim Revert "Merge pull request #6142 from spartan-developer/master"
josevalim authored
210 if size = options.delete(:size)
fff0309 @kuldeepaggarwal unnecessary checking of `size` with `second regex` if matched with fi…
kuldeepaggarwal authored
211 if size =~ %r{\A\d+x\d+\z}
212 options[:width], options[:height] = size.split('x')
213 elsif size =~ %r{\A\d+\z}
214 options[:width] = options[:height] = size
215 end
eab0520 @josevalim Revert "Merge pull request #6142 from spartan-developer/master"
josevalim authored
216 end
6a609db @joshk incorporated most of the feedback from José
joshk authored
217
218 tag("img", options)
219 end
220
fb39249 Add documentation to AssetTagHelper#image_alt [ci skip]
Florent Guilleux authored
221 # Returns a string suitable for an html image tag alt attribute.
dd9f8bc @thenickcox Improve img alt attribute for screen readers
thenickcox authored
222 # The +src+ argument is meant to be an image file path.
b1c72a3 @carlosantoniodasilva Improve changelog entry from #9221 [ci skip]
carlosantoniodasilva authored
223 # The method removes the basename of the file path and the digest,
dd9f8bc @thenickcox Improve img alt attribute for screen readers
thenickcox authored
224 # if any. It also removes hyphens and underscores from file names and
225 # replaces them with spaces, returning a space-separated, titleized
226 # string.
b1c72a3 @carlosantoniodasilva Improve changelog entry from #9221 [ci skip]
carlosantoniodasilva authored
227 #
dd9f8bc @thenickcox Improve img alt attribute for screen readers
thenickcox authored
228 # ==== Examples
229 #
58d64dd @josephzidell Fixed typo in documentation
josephzidell authored
230 # image_alt('rails.png')
bf49506 @josephzidell Fixed return strings in documentation
josephzidell authored
231 # # => Rails
dd9f8bc @thenickcox Improve img alt attribute for screen readers
thenickcox authored
232 #
58d64dd @josephzidell Fixed typo in documentation
josephzidell authored
233 # image_alt('hyphenated-file-name.png')
bf49506 @josephzidell Fixed return strings in documentation
josephzidell authored
234 # # => Hyphenated file name
b1c72a3 @carlosantoniodasilva Improve changelog entry from #9221 [ci skip]
carlosantoniodasilva authored
235 #
58d64dd @josephzidell Fixed typo in documentation
josephzidell authored
236 # image_alt('underscored_file_name.png')
bf49506 @josephzidell Fixed return strings in documentation
josephzidell authored
237 # # => Underscored file name
a0960ec @fxn the generated ALT attribute for images no longer contains the digest,…
fxn authored
238 def image_alt(src)
dd9f8bc @thenickcox Improve img alt attribute for screen readers
thenickcox authored
239 File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
a0960ec @fxn the generated ALT attribute for images no longer contains the digest,…
fxn authored
240 end
241
6a609db @joshk incorporated most of the feedback from José
joshk authored
242 # Returns an html video tag for the +sources+. If +sources+ is a string,
243 # a single video tag will be returned. If +sources+ is an array, a video
244 # tag with nested source tags for each source will be returned. The
245 # +sources+ can be full paths or files that exists in your public videos
246 # directory.
247 #
248 # ==== Options
249 # You can add HTML attributes using the +options+. The +options+ supports
250 # two additional keys for convenience and conformance:
251 #
252 # * <tt>:poster</tt> - Set an image (like a screenshot) to be shown
253 # before the video loads. The path is calculated like the +src+ of +image_tag+.
254 # * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes
255 # width="30" and height="45". <tt>:size</tt> will be ignored if the
256 # value is not in the correct format.
257 #
4997831 fix broken format in ActionView::Helpers::AssetTagHelper [ci skip]
Francesco Rodriguez authored
258 # ==== Examples
259 #
33f6209 @alvaropereyra Removes unneeded 'Example' tags and whitespaces [ci skip]
alvaropereyra authored
260 # video_tag("trailer")
261 # # => <video src="/videos/trailer" />
262 # video_tag("trailer.ogg")
263 # # => <video src="/videos/trailer.ogg" />
264 # video_tag("trailer.ogg", controls: true, autobuffer: true)
265 # # => <video autobuffer="autobuffer" controls="controls" src="/videos/trailer.ogg" />
266 # video_tag("trailer.m4v", size: "16x10", poster: "screenshot.png")
267 # # => <video src="/videos/trailer.m4v" width="16" height="10" poster="/assets/screenshot.png" />
268 # video_tag("/trailers/hd.avi", size: "16x16")
269 # # => <video src="/trailers/hd.avi" width="16" height="16" />
270 # video_tag("/trailers/hd.avi", height: '32', width: '32')
271 # # => <video height="32" src="/trailers/hd.avi" width="32" />
272 # video_tag("trailer.ogg", "trailer.flv")
273 # # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
274 # video_tag(["trailer.ogg", "trailer.flv"])
275 # # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
276 # video_tag(["trailer.ogg", "trailer.flv"], size: "160x120")
277 # # => <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
08e5104 @lest allow to pass multiple sources to audio/video tags without using array
lest authored
278 def video_tag(*sources)
858f464 @lest reuse common video/audio tags code and do not modify options
lest authored
279 multiple_sources_tag('video', sources) do |options|
280 options[:poster] = path_to_image(options[:poster]) if options[:poster]
6a609db @joshk incorporated most of the feedback from José
joshk authored
281
eab0520 @josevalim Revert "Merge pull request #6142 from spartan-developer/master"
josevalim authored
282 if size = options.delete(:size)
283 options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
284 end
6a609db @joshk incorporated most of the feedback from José
joshk authored
285 end
286 end
287
2a6cfce @hpneo Update documentation for javascript_include_tag [ci skip]
hpneo authored
288 # Returns an HTML audio tag for the +source+.
6a609db @joshk incorporated most of the feedback from José
joshk authored
289 # The +source+ can be full path or file that exists in
290 # your public audios directory.
291 #
2a6cfce @hpneo Update documentation for javascript_include_tag [ci skip]
hpneo authored
292 # audio_tag("sound")
293 # # => <audio src="/audios/sound" />
294 # audio_tag("sound.wav")
295 # # => <audio src="/audios/sound.wav" />
296 # audio_tag("sound.wav", autoplay: true, controls: true)
297 # # => <audio autoplay="autoplay" controls="controls" src="/audios/sound.wav" />
298 # audio_tag("sound.wav", "sound.mid")
299 # # => <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio>
08e5104 @lest allow to pass multiple sources to audio/video tags without using array
lest authored
300 def audio_tag(*sources)
858f464 @lest reuse common video/audio tags code and do not modify options
lest authored
301 multiple_sources_tag('audio', sources)
6a609db @joshk incorporated most of the feedback from José
joshk authored
302 end
303
0ff1c59 @joshk reorganised the the common asset helpers module into a class and have…
joshk authored
304 private
858f464 @lest reuse common video/audio tags code and do not modify options
lest authored
305 def multiple_sources_tag(type, sources)
f4d2695 @lest use `symbolize_keys` instead of `dup.symbolize_keys!`
lest authored
306 options = sources.extract_options!.symbolize_keys
858f464 @lest reuse common video/audio tags code and do not modify options
lest authored
307 sources.flatten!
308
309 yield options if block_given?
310
311 if sources.size > 1
312 content_tag(type, options) do
313 safe_join sources.map { |source| tag("source", :src => send("path_to_#{type}", source)) }
314 end
315 else
316 options[:src] = send("path_to_#{type}", sources.first)
e41425a @rafaelfranca Always use content_tag for audio/video tag
rafaelfranca authored
317 content_tag(type, nil, options)
858f464 @lest reuse common video/audio tags code and do not modify options
lest authored
318 end
319 end
2a5fc27 @dhh Added AssetTagHelper that provides methods for linking a HTML page to…
dhh authored
320 end
321 end
59c83af @akaspick allow absolute paths for the asset caches
akaspick authored
322 end
Something went wrong with that request. Please try again.