From cc190e143d8004c8965d947cf97784b2d601d73b Mon Sep 17 00:00:00 2001 From: Max Schwenk Date: Mon, 2 Apr 2018 15:21:36 -0700 Subject: [PATCH] Add image_pack_tag helper --- lib/webpacker/helper.rb | 10 ++++++++++ test/helper_test.rb | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 54e106dc2..38858da12 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -33,6 +33,16 @@ def asset_pack_url(name, **options) end end + # Creates a image tag that references the named pack file. + # + # Example: + # + # <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %> + # Edit Entry + def image_pack_tag(name, **options) + image_tag(asset_path(Webpacker.manifest.lookup!(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 85d7a789d..9f4e59576 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -31,6 +31,12 @@ def test_asset_pack_url assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css") end + def test_image_pack_tag + assert_equal \ + "\"Edit", + image_pack_tag("application.png", size: "16x10", alt: "Edit Entry") + end + def test_javascript_pack_tag assert_equal \ %(),