From 3c117c08207c5b923e162f965143e70439a6bb2d Mon Sep 17 00:00:00 2001 From: Dmytro Shteflyuk Date: Wed, 18 Sep 2019 04:27:15 -0400 Subject: [PATCH] Added favicon_pack_tag to generate favicon links (#2281) --- lib/webpacker/helper.rb | 10 ++++++++++ test/helper_test.rb | 18 ++++++++++++++++++ test/test_app/public/packs/manifest.json | 2 ++ 3 files changed, 30 insertions(+) diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 894b9a08d..677601d68 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -50,6 +50,16 @@ def image_pack_tag(name, **options) image_tag(resolve_path_to_image(name), **options) end + # Creates a link tag for a favicon that references the named pack file. + # + # Example: + # + # <%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %> + # + def favicon_pack_tag(name, **options) + favicon_link_tag(resolve_path_to_image(name), **options) + end + # Creates a script tag that references the named pack file, as compiled by webpack per the entries list # in config/webpack/shared.js. By default, this list is auto-generated to match everything in # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up. diff --git a/test/helper_test.rb b/test/helper_test.rb index 509afd3d0..6f742a14f 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -52,6 +52,24 @@ def test_image_pack_tag image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry") end + def test_favicon_pack_tag + assert_equal \ + "", + favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png") + assert_equal \ + "", + favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png") + assert_equal \ + "", + favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png") + assert_equal \ + "", + favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png") + assert_equal \ + "", + favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png") + end + def test_javascript_pack_tag assert_equal \ %(), diff --git a/test/test_app/public/packs/manifest.json b/test/test_app/public/packs/manifest.json index 783214316..a3d382429 100644 --- a/test/test_app/public/packs/manifest.json +++ b/test/test_app/public/packs/manifest.json @@ -7,6 +7,8 @@ "fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2", "media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg", "media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg", + "media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png", + "media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png", "entrypoints": { "application": { "js": [