Skip to content

Commit

Permalink
Added favicon_pack_tag to generate favicon links (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpumuk authored and gauravtiwari committed Sep 18, 2019
1 parent d0fa1d1 commit 3c117c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/webpacker/helper.rb
Expand Up @@ -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' %>
# <link href="/packs/mb-icon-k344a6d59eef8632c9d1.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.
Expand Down
18 changes: 18 additions & 0 deletions test/helper_test.rb
Expand Up @@ -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 \
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
end

def test_javascript_pack_tag
assert_equal \
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
Expand Down
2 changes: 2 additions & 0 deletions test/test_app/public/packs/manifest.json
Expand Up @@ -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": [
Expand Down

0 comments on commit 3c117c0

Please sign in to comment.