1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update resolve_link_as to include SVG (#42892)

* Update resolve_link_as to include SVG

Preloading SVGs won't work without 'as: image' because of:

`Preload of /packs/media/images/81d035675e31079ea9da.svg was ignored due to unknown “as” or “type” values, or non-matching “media” attribute.`

Preloading SVGs can be useful, for instance when using sprites such as bootstrap-icons.

* Adds test case for asset_tag_helper

* Fix test case -- silly mistake

[xanderificnl + Rafael Mendonça França]
This commit is contained in:
Xander 2021-07-28 22:26:55 +02:00 committed by GitHub
parent 0c2a94c265
commit d9fda55594
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View file

@ -536,6 +536,8 @@ module ActionView
"style"
elsif extname == "vtt"
"track"
elsif extname == "svg"
"image"
elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font))
type
end

View file

@ -255,6 +255,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(preload_link_tag '//example.com/font.woff2', crossorigin: 'use-credentials') => %(<link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="use-credentials" />),
%(preload_link_tag '/media/audio.ogg', nopush: true) => %(<link rel="preload" href="/media/audio.ogg" as="audio" type="audio/ogg" />),
%(preload_link_tag '/style.css', integrity: 'sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs') => %(<link rel="preload" href="/style.css" as="style" type="text/css" integrity="sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs">),
%(preload_link_tag '/sprite.svg') => %(<link rel="preload" href="/sprite.svg" as="image" type="image/svg+xml">)
}
VideoPathToTag = {