From 9680fb808872a1ec0f10e9fbf1d7047d34c3d7c6 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Tue, 3 Sep 2024 09:31:11 +0200 Subject: [PATCH] Drop Webpacker support Close #162 --- CHANGELOG.md | 2 +- README.md | 4 ++-- lib/inline_svg/webpack_asset_finder.rb | 7 +------ spec/finds_asset_paths_spec.rb | 12 ++++++------ spec/webpack_asset_finder_spec.rb | 10 ---------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c41bcf..43dd1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] -Nothing. +- Drop Support for Webpacker and Legacy Rails. [#163](https://github.com/jamesmartin/inline_svg/pull/163). ## [1.10.0] - 2024-09-03 ### Added diff --git a/README.md b/README.md index 74958a6..bcd0d72 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Styling a SVG document with CSS for use on the web is most reliably achieved by [adding classes to the document and embedding](http://css-tricks.com/using-svg/) it inline in the HTML. -This gem adds Rails helper methods (`inline_svg_tag` and `inline_svg_pack_tag`) that read an SVG document (via Sprockets or Webpacker, so works with the Rails Asset Pipeline), applies a CSS class attribute to the root of the document and +This gem adds Rails helper methods (`inline_svg_tag` and `inline_svg_pack_tag`) that read an SVG document (via Sprockets or Shakapacker, so works with the Rails Asset Pipeline), applies a CSS class attribute to the root of the document and then embeds it into a view. Inline SVG supports Rails 6.1/7.x with Sprockets or Shakapacker @@ -37,7 +37,7 @@ Or install it yourself as: # Sprockets inline_svg_tag(file_name, options={}) -# Webpacker +# Shakapacker inline_svg_pack_tag(file_name, options={}) ``` diff --git a/lib/inline_svg/webpack_asset_finder.rb b/lib/inline_svg/webpack_asset_finder.rb index e5364a4..b5e730e 100644 --- a/lib/inline_svg/webpack_asset_finder.rb +++ b/lib/inline_svg/webpack_asset_finder.rb @@ -23,12 +23,7 @@ def pathname private def asset_helper - @asset_helper ||= - if defined?(::Shakapacker) - ::Shakapacker - else - ::Webpacker - end + @asset_helper ||= ::Shakapacker end def dev_server_asset(file_path) diff --git a/spec/finds_asset_paths_spec.rb b/spec/finds_asset_paths_spec.rb index d208127..7c213ea 100644 --- a/spec/finds_asset_paths_spec.rb +++ b/spec/finds_asset_paths_spec.rb @@ -63,13 +63,13 @@ context "when webpack finder returns an object with a relative asset path" do it "returns the fully qualified file path" do - webpacker = double('WebpackerDouble') + shakapacker = double('ShakapackerDouble') - expect(webpacker).to receive(:find_asset).with('some-file'). + expect(shakapacker).to receive(:find_asset).with('some-file'). and_return(double(filename: Pathname('/full/path/to/some-file'))) InlineSvg.configure do |config| - config.asset_finder = webpacker + config.asset_finder = shakapacker end expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file') @@ -78,13 +78,13 @@ context "when webpack finder returns an object with an absolute http asset path" do it "returns the fully qualified file path" do - webpacker = double('WebpackerDouble') + shakapacker = double('ShakapackerDouble') - expect(webpacker).to receive(:find_asset).with('some-file'). + expect(shakapacker).to receive(:find_asset).with('some-file'). and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file'))) InlineSvg.configure do |config| - config.asset_finder = webpacker + config.asset_finder = shakapacker end expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('https://my-fancy-domain.test/full/path/to/some-file') diff --git a/spec/webpack_asset_finder_spec.rb b/spec/webpack_asset_finder_spec.rb index c574915..0b040d6 100644 --- a/spec/webpack_asset_finder_spec.rb +++ b/spec/webpack_asset_finder_spec.rb @@ -1,16 +1,6 @@ require_relative '../lib/inline_svg' describe InlineSvg::WebpackAssetFinder do - context "when the file is not found" do - it "returns nil" do - stub_const('Rails', double('Rails').as_null_object) - stub_const('Webpacker', double('Webpacker').as_null_object) - expect(::Webpacker.manifest).to receive(:lookup).with('some-file').and_return(nil) - - expect(described_class.find_asset('some-file').pathname).to be_nil - end - end - context "when Shakapacker is defined" do it "uses the new spelling" do stub_const('Rails', double('Rails').as_null_object)