Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added favicon_pack_tag to generate favicon links #2281

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/webpacker/helper.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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