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

Drop legacy Ruby, Rails, and Webpacker support #163

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
test-branch: [rails6, rails7, rails7-shakapacker]
test-branch: [rails7, rails7-shakapacker]
timeout-minutes: 20
steps:
- name: Checkout
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2', '3.3']
channel: ['stable']

include:
- ruby-version: 'head'
channel: 'experimental'

continue-on-error: ${{ matrix.channel != 'stable' }}

steps:
- uses: actions/checkout@v4
- name: Set up Ruby 2.7
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.7
ruby-version: '3.3'
bundler-cache: true
- name: Test with Rake
run: |
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

Nothing.
- Drop Support for Webpacker, Legacy Ruby (< 3.0), and Legacy Rails (< 7.0). [#163](https://github.com/jamesmartin/inline_svg/pull/163). Thanks, [@tagliala](https://github.com/tagliala)

## [1.10.0] - 2024-09-03
### Added
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in inline_svg.gemspec
gemspec

gem "bundler"
gem "pry"
gem "rake"
gem "rspec"
gem "rubocop"
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ 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 5](http://weblog.rubyonrails.org/2016/6/30/Rails-5-0-final/) (from [v0.10.0](https://github.com/jamesmartin/inline_svg/releases/tag/v0.10.0))
- [Rails 6](https://weblog.rubyonrails.org/2019/4/24/Rails-6-0-rc1-released/) with Sprockets or Webpacker (from [v1.5.2](https://github.com/jamesmartin/inline_svg/releases/tag/v1.5.2)).
- [Rails 7](https://weblog.rubyonrails.org/2021/12/6/Rails-7-0-rc-1-released/)

Inline SVG no longer officially supports Rails 3 or Rails 4 (although they may still work). In order to reduce the maintenance cost of this project we now follow the [Rails Maintenance Policy](https://guides.rubyonrails.org/maintenance_policy.html).
Inline SVG supports Rails 7.x with Propshaft, Sprockets, or Shakapacker
Copy link
Contributor Author

@tagliala tagliala Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propshaft was missing I guess


## Changelog

Expand All @@ -43,7 +37,7 @@ Or install it yourself as:
# Sprockets
inline_svg_tag(file_name, options={})

# Webpacker
# Shakapacker
inline_svg_pack_tag(file_name, options={})
```

Expand Down
12 changes: 4 additions & 8 deletions inline_svg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.2"
spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
spec.add_development_dependency "pry"
spec.add_development_dependency "rubocop"
spec.metadata['rubygems_mfa_required'] = 'true'
spec.required_ruby_version = '>= 3.1'

spec.add_runtime_dependency "activesupport", ">= 3.0"
spec.add_runtime_dependency "nokogiri", ">= 1.6"
spec.add_dependency "activesupport", ">= 7.0"
spec.add_dependency "nokogiri", ">= 1.16"
Comment on lines +24 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason why I've removed development_dependency from here and renamed add_runtime_dependency to add_dependency is because they are known offences of rubocop packaging and will be clearer with future commits when this will be merged

end
11 changes: 1 addition & 10 deletions lib/inline_svg/action_view/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ def inline_svg(filename, transform_params={})

private

def backwards_compatible_html_escape(filename)
# html_escape_once was introduced in newer versions of Rails.
if ERB::Util.respond_to?(:html_escape_once)
ERB::Util.html_escape_once(filename)
else
ERB::Util.html_escape(filename)
end
end

def render_inline_svg(filename, transform_params={})
begin
svg_file = read_svg(filename)
Expand Down Expand Up @@ -60,7 +51,7 @@ def read_svg(filename)

def placeholder(filename)
css_class = InlineSvg.configuration.svg_not_found_css_class
not_found_message = "'#{backwards_compatible_html_escape(filename)}' #{extension_hint(filename)}"
not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}"

if css_class.nil?
return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
Expand Down
2 changes: 1 addition & 1 deletion lib/inline_svg/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module InlineSvg
VERSION = "1.10.0"
VERSION = "2.0.0"
end
7 changes: 1 addition & 6 deletions lib/inline_svg/webpack_asset_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions spec/finds_asset_paths_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
10 changes: 0 additions & 10 deletions spec/webpack_asset_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
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)
stub_const('Shakapacker', double('Shakapacker').as_null_object)
expect(::Shakapacker.manifest).to receive(:lookup).with('some-file').and_return(nil)
Expand Down