inline_svg 1.8.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23a2c45f1e25e4266196f0e2fc23a4384cb8513be840d2b676ae848b5be1d121
4
- data.tar.gz: 8fdb1090f9037ed6c732469ffda28023e200d758533223d4bd9c85b5a20cfb72
3
+ metadata.gz: 66214539304b60e87e9263afb26531212492ca77957e9ce8cf89d015cef86239
4
+ data.tar.gz: 6ab9cb3d75a9f268728600edb48bf27b3503145c80f1addabe8bc484c88af545
5
5
  SHA512:
6
- metadata.gz: c3d98f05ba0b9ea222d1b852f87f30584ba4b775d7b6848a2366341e5e85bb6c9912bc1f8441117d129db4d63506d54dcd8ef4d633a5140359e25f5a829a8a1c
7
- data.tar.gz: 45eb7d5c8a30f0814e9c775924690825ad3b3ee9c3ada3c9694bf3af46499ababaa1ba81f696514e08dc09aa5ae6520094820fc528ee34fbb307b856dc16b3f4
6
+ metadata.gz: 1f8d4642dff97eb5bfc358fd1ce2257d5113a6f232c02f4ecd847007ee861b2537748539c689e5e2e67297951fdd158594740a754d49469cbd8c13c72002c290
7
+ data.tar.gz: 1b5cb2dfd5e7067d64ec0cc3449c2aeeead3a39cab42f8d51db33609a296478511fa9a24a965e32b10d7f01c98e5cb4b2ef8a6268fb055a7ad968068499eccd6
@@ -4,11 +4,11 @@ on: [push]
4
4
 
5
5
  jobs:
6
6
  build:
7
-
8
7
  runs-on: ubuntu-latest
9
8
  strategy:
10
9
  matrix:
11
10
  test-branch: [rails5, rails6, rails7]
11
+ timeout-minutes: 20
12
12
  steps:
13
13
  - name: Checkout
14
14
  uses: actions/checkout@v2
@@ -19,9 +19,9 @@ jobs:
19
19
  ref: ${{ matrix.test-branch }}
20
20
  path: test_app
21
21
  - name: Set up Ruby 2.7
22
- uses: actions/setup-ruby@v1
22
+ uses: ruby/setup-ruby@v1
23
23
  with:
24
- ruby-version: 2.7.x
24
+ ruby-version: 2.7.7
25
25
  - name: Build local gem
26
26
  run: |
27
27
  gem install bundler
@@ -18,10 +18,10 @@ jobs:
18
18
  repository: jamesmartin/inline_svg_test_app
19
19
  ref: ${{ matrix.test-branch }}
20
20
  path: test_app
21
- - name: Set up Ruby 2.7
22
- uses: actions/setup-ruby@v1
21
+ - name: Set up Ruby 3.1
22
+ uses: ruby/setup-ruby@v1
23
23
  with:
24
- ruby-version: 2.7.x
24
+ ruby-version: 3.1
25
25
  - name: Build local gem
26
26
  run: |
27
27
  gem install bundler
@@ -46,10 +46,14 @@ jobs:
46
46
  with:
47
47
  node-version: 16
48
48
  if: matrix.test-branch == 'rails6-webpacker'
49
+ - name: Set up Python 2.7
50
+ uses: actions/setup-python@v4
51
+ with:
52
+ python-version: '2.7'
49
53
  - name: Generate Webpacker config
50
54
  run: |
51
55
  cd $GITHUB_WORKSPACE/test_app
52
- yarn install --check-files
56
+ CXXFLAGS="--std=c++17" yarn install --check-files
53
57
  bundle exec rake webpacker:compile
54
58
  if: matrix.test-branch == 'rails6-webpacker'
55
59
  - name: Test
@@ -9,10 +9,10 @@ jobs:
9
9
 
10
10
  steps:
11
11
  - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6
13
- uses: actions/setup-ruby@v1
12
+ - name: Set up Ruby 2.7
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
15
+ ruby-version: 2.7.7
16
16
  - name: Build and test with Rake
17
17
  run: |
18
18
  gem install bundler
data/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  Nothing.
8
8
 
9
+ ## [1.10.0] - 2024-09-03
10
+ ### Added
11
+ - Support for Shakapacker. [#158](https://github.com/jamesmartin/inline_svg/pull/158). Thanks, [@tagliala](https://github.com/tagliala)
12
+
13
+ ### Fixed
14
+ - Fixed documentation typos. [#157](https://github.com/jamesmartin/inline_svg/pull/157). Thanks, [@tagliala](https://github.com/tagliala)
15
+ - Fixed missing ActiveSupport require. [#152](https://github.com/jamesmartin/inline_svg/pull/152). Thanks, [@xymbol](https://github.com/xymbol)
16
+ - Remove wrapping whitespace from SVG tags. [#150](https://github.com/jamesmartin/inline_svg/pull/150). Thanks, [@fredboyle](https://github.com/fredboyle)
17
+
18
+ ## [1.9.0] - 2023-03-29
19
+ ### Added
20
+ - A new option: `view_box` adds a `viewBox` attribute to the SVG. [#142](https://github.com/jamesmartin/inline_svg/pull/142). Thanks [@sunny](https://github.com/sunny)
21
+
22
+ ### Fixed
23
+ - Allow Propshaft assets to use fallbacks. [#140](https://github.com/jamesmartin/inline_svg/pull/140). Thanks, [@ohrite](https://github.com/ohrite)
24
+ - Handling missing file when using static assets. [#141](https://github.com/jamesmartin/inline_svg/pull/141). Thanks, [@leighhalliday](https://github.com/leighhalliday)
25
+ - Handle missing file when using Webpacker assets.
26
+
9
27
  ## [1.8.0] - 2022-01-09
10
28
  ### Added
11
29
  - Remove deprecation warning for `inline_svg`, as we intend to keep it in 2.0. [#131](https://github.com/jamesmartin/inline_svg/pull/131). Thanks [@DanielJackson-Oslo](https://github.com/DanielJackson-Oslo)
@@ -203,7 +221,7 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
203
221
 
204
222
  ## [0.5.1] - 2015-03-30
205
223
  ### Warning
206
- ** This version is NOT comaptible with Sprockets >= 3. **
224
+ ** This version is NOT compatible with Sprockets >= 3. **
207
225
 
208
226
  ### Fixed
209
227
  - Support for ActiveSupport (and hence, Rails) 4.2.x. Thanks, @jmarceli.
@@ -244,7 +262,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
244
262
  ### Added
245
263
  - Basic Railtie and view helper to inline SVG documents to Rails views.
246
264
 
247
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.8.0...HEAD
265
+ [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.9.0...HEAD
266
+ [1.9.0]: https://github.com/jamesmartin/inline_svg/compare/v1.8.0...v1.9.0
248
267
  [1.8.0]: https://github.com/jamesmartin/inline_svg/compare/v1.7.2...v1.8.0
249
268
  [1.7.2]: https://github.com/jamesmartin/inline_svg/compare/v1.7.1...v1.7.2
250
269
  [1.7.1]: https://github.com/jamesmartin/inline_svg/compare/v1.7.0...v1.7.1
data/README.md CHANGED
@@ -14,7 +14,7 @@ Inline SVG supports:
14
14
 
15
15
  - [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))
16
16
  - [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)).
17
- - [Rails 7](https://weblog.rubyonrails.org/2021/12/6/Rails-7-0-rc-1-released/) (experimental)
17
+ - [Rails 7](https://weblog.rubyonrails.org/2021/12/6/Rails-7-0-rc-1-released/)
18
18
 
19
19
  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).
20
20
 
@@ -97,6 +97,7 @@ key | description
97
97
  `desc` | add a \<desc\> node inside the top level of the SVG document
98
98
  `nocomment` | remove comment tags from the SVG document
99
99
  `preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
100
+ `view_box` | adds a `viewBox` attribute to the SVG
100
101
  `aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
101
102
  `aria_hidden` | adds the `aria-hidden=true` attribute to the SVG
102
103
  `fallback` | set fallback SVG document
@@ -114,6 +115,7 @@ inline_svg_tag(
114
115
  desc: 'Some description',
115
116
  nocomment: true,
116
117
  preserve_aspect_ratio: 'xMaxYMax meet',
118
+ view_box: '0 0 100 100',
117
119
  aria: true,
118
120
  aria_hidden: true,
119
121
  fallback: 'fallback-document.svg'
@@ -9,7 +9,8 @@ module InlineSvg
9
9
  end
10
10
 
11
11
  def pathname
12
- ::Rails.application.assets.load_path.find(@filename).path
12
+ asset_path = ::Rails.application.assets.load_path.find(@filename)
13
+ asset_path.path unless asset_path.nil?
13
14
  end
14
15
  end
15
16
  end
@@ -16,7 +16,8 @@ module InlineSvg
16
16
 
17
17
  def pathname
18
18
  if ::Rails.application.config.assets.compile
19
- Pathname.new(::Rails.application.assets[@filename].filename)
19
+ asset = ::Rails.application.assets[@filename]
20
+ Pathname.new(asset.filename) if asset.present?
20
21
  else
21
22
  manifest = ::Rails.application.assets_manifest
22
23
  asset_path = manifest.assets[@filename]
@@ -0,0 +1,9 @@
1
+ module InlineSvg::TransformPipeline::Transformations
2
+ class ViewBox < Transformation
3
+ def transform(doc)
4
+ with_svg(doc) do |svg|
5
+ svg["viewBox"] = value
6
+ end
7
+ end
8
+ end
9
+ end
@@ -10,11 +10,12 @@ module InlineSvg::TransformPipeline::Transformations
10
10
  class: { transform: ClassAttribute },
11
11
  style: { transform: StyleAttribute },
12
12
  data: { transform: DataAttributes },
13
- height: { transform: Height },
14
13
  nocomment: { transform: NoComment },
15
14
  preserve_aspect_ratio: { transform: PreserveAspectRatio },
16
15
  size: { transform: Size },
17
16
  width: { transform: Width },
17
+ height: { transform: Height },
18
+ view_box: { transform: ViewBox },
18
19
  }
19
20
  end
20
21
 
@@ -83,8 +84,9 @@ require 'inline_svg/transform_pipeline/transformations/description'
83
84
  require 'inline_svg/transform_pipeline/transformations/size'
84
85
  require 'inline_svg/transform_pipeline/transformations/height'
85
86
  require 'inline_svg/transform_pipeline/transformations/width'
87
+ require 'inline_svg/transform_pipeline/transformations/view_box'
86
88
  require 'inline_svg/transform_pipeline/transformations/id_attribute'
87
89
  require 'inline_svg/transform_pipeline/transformations/data_attributes'
88
90
  require 'inline_svg/transform_pipeline/transformations/preserve_aspect_ratio'
89
91
  require 'inline_svg/transform_pipeline/transformations/aria_attributes'
90
- require "inline_svg/transform_pipeline/transformations/aria_hidden_attribute"
92
+ require "inline_svg/transform_pipeline/transformations/aria_hidden_attribute"
@@ -4,7 +4,7 @@ module InlineSvg
4
4
  document = Nokogiri::XML::Document.parse(svg_file)
5
5
  Transformations.lookup(transform_params).reduce(document) do |doc, transformer|
6
6
  transformer.transform(doc)
7
- end.to_html
7
+ end.to_html.strip
8
8
  end
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "1.8.0"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -6,21 +6,31 @@ module InlineSvg
6
6
 
7
7
  def initialize(filename)
8
8
  @filename = filename
9
- @asset_path = URI(Webpacker.manifest.lookup(@filename)).path
9
+ manifest_lookup = asset_helper.manifest.lookup(@filename)
10
+ @asset_path = manifest_lookup.present? ? URI(manifest_lookup).path : ""
10
11
  end
11
12
 
12
13
  def pathname
13
14
  return if @asset_path.blank?
14
15
 
15
- if Webpacker.dev_server.running?
16
+ if asset_helper.dev_server.running?
16
17
  dev_server_asset(@asset_path)
17
- elsif Webpacker.config.public_path.present?
18
- File.join(Webpacker.config.public_path, @asset_path)
18
+ elsif asset_helper.config.public_path.present?
19
+ File.join(asset_helper.config.public_path, @asset_path)
19
20
  end
20
21
  end
21
22
 
22
23
  private
23
24
 
25
+ def asset_helper
26
+ @asset_helper ||=
27
+ if defined?(::Shakapacker)
28
+ ::Shakapacker
29
+ else
30
+ ::Webpacker
31
+ end
32
+ end
33
+
24
34
  def dev_server_asset(file_path)
25
35
  asset = fetch_from_dev_server(file_path)
26
36
 
@@ -37,8 +47,8 @@ module InlineSvg
37
47
  end
38
48
 
39
49
  def fetch_from_dev_server(file_path)
40
- http = Net::HTTP.new(Webpacker.dev_server.host, Webpacker.dev_server.port)
41
- http.use_ssl = Webpacker.dev_server.https?
50
+ http = Net::HTTP.new(asset_helper.dev_server.host, asset_helper.dev_server.port)
51
+ http.use_ssl = asset_helper.dev_server.protocol == "https"
42
52
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
53
 
44
54
  http.request(Net::HTTP::Get.new(file_path)).body
data/lib/inline_svg.rb CHANGED
@@ -10,6 +10,8 @@ require "inline_svg/transform_pipeline"
10
10
  require "inline_svg/io_resource"
11
11
 
12
12
  require "inline_svg/railtie" if defined?(Rails)
13
+ require 'active_support'
14
+ require 'active_support/core_ext/object/blank'
13
15
  require 'active_support/core_ext/string'
14
16
  require 'nokogiri'
15
17
 
@@ -86,9 +86,7 @@ describe InlineSvg::ActionView::Helpers do
86
86
  with('missing.svg').
87
87
  and_raise(InlineSvg::AssetFile::FileNotFound.new)
88
88
 
89
- fallback_file = <<-SVG
90
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
91
- SVG
89
+ fallback_file = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
92
90
  allow(InlineSvg::AssetFile).to receive(:named).with('fallback.svg').and_return(fallback_file)
93
91
  expect(helper.send(helper_method, 'missing.svg', fallback: 'fallback.svg')).to eq fallback_file
94
92
  end
@@ -99,9 +97,7 @@ SVG
99
97
 
100
98
  context "and no options" do
101
99
  it "returns a html safe version of the file's contents" do
102
- example_file = <<-SVG
103
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
104
- SVG
100
+ example_file = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
105
101
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(example_file)
106
102
  expect(helper.send(helper_method, 'some-file')).to eq example_file
107
103
  end
@@ -109,12 +105,8 @@ SVG
109
105
 
110
106
  context "and the 'title' option" do
111
107
  it "adds the title node to the SVG output" do
112
- input_svg = <<-SVG
113
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>
114
- SVG
115
- expected_output = <<-SVG
116
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title></svg>
117
- SVG
108
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>'
109
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title></svg>'
118
110
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
119
111
  expect(helper.send(helper_method, 'some-file', title: 'A title')).to eq expected_output
120
112
  end
@@ -122,12 +114,8 @@ SVG
122
114
 
123
115
  context "and the 'desc' option" do
124
116
  it "adds the description node to the SVG output" do
125
- input_svg = <<-SVG
126
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>
127
- SVG
128
- expected_output = <<-SVG
129
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><desc>A description</desc></svg>
130
- SVG
117
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>'
118
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><desc>A description</desc></svg>'
131
119
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
132
120
  expect(helper.send(helper_method, 'some-file', desc: 'A description')).to eq expected_output
133
121
  end
@@ -135,12 +123,8 @@ SVG
135
123
 
136
124
  context "and the 'nocomment' option" do
137
125
  it "strips comments and other unknown/unsafe nodes from the output" do
138
- input_svg = <<-SVG
139
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
140
- SVG
141
- expected_output = <<-SVG
142
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
143
- SVG
126
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
127
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>'
144
128
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
145
129
  expect(helper.send(helper_method, 'some-file', nocomment: true)).to eq expected_output
146
130
  end
@@ -148,12 +132,8 @@ SVG
148
132
 
149
133
  context "and the 'aria_hidden' option" do
150
134
  it "sets 'aria-hidden=true' in the output" do
151
- input_svg = <<-SVG
152
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
153
- SVG
154
- expected_output = <<-SVG
155
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>
156
- SVG
135
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>'
136
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>'
157
137
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
158
138
  expect(helper.send(helper_method, 'some-file', aria_hidden: true)).to eq expected_output
159
139
  end
@@ -161,12 +141,8 @@ SVG
161
141
 
162
142
  context "and all options" do
163
143
  it "applies all expected transformations to the output" do
164
- input_svg = <<-SVG
165
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
166
- SVG
167
- expected_output = <<-SVG
168
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><title>A title</title><desc>A description</desc></svg>
169
- SVG
144
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
145
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><title>A title</title><desc>A description</desc></svg>'
170
146
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
171
147
  expect(helper.send(helper_method, 'some-file', title: 'A title', desc: 'A description', nocomment: true)).to eq expected_output
172
148
  end
@@ -184,12 +160,8 @@ SVG
184
160
  end
185
161
 
186
162
  it "applies custm transformations to the output" do
187
- input_svg = <<-SVG
188
- <svg></svg>
189
- SVG
190
- expected_output = <<-SVG
191
- <svg custom="some value"></svg>
192
- SVG
163
+ input_svg = '<svg></svg>'
164
+ expected_output = '<svg custom="some value"></svg>'
193
165
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
194
166
  expect(helper.send(helper_method, 'some-file', custom: 'some value')).to eq expected_output
195
167
  end
@@ -212,7 +184,7 @@ SVG
212
184
 
213
185
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
214
186
 
215
- expect(helper.send(helper_method, 'some-file')).to eq "<svg custom=\"default value\"></svg>\n"
187
+ expect(helper.send(helper_method, 'some-file')).to eq "<svg custom=\"default value\"></svg>"
216
188
  end
217
189
  end
218
190
 
@@ -222,7 +194,7 @@ SVG
222
194
 
223
195
  allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
224
196
 
225
- expect(helper.send(helper_method, 'some-file', custom: 'some value')).to eq "<svg custom=\"some value\"></svg>\n"
197
+ expect(helper.send(helper_method, 'some-file', custom: 'some value')).to eq "<svg custom=\"some value\"></svg>"
226
198
  end
227
199
  end
228
200
  end
@@ -251,17 +223,27 @@ SVG
251
223
  expect(InlineSvg::IOResource).to receive(:===).with(io_object).and_return(true)
252
224
  expect(InlineSvg::IOResource).to receive(:read).with(io_object).and_return("<svg><!-- Test IO --></svg>")
253
225
  output = helper.send(helper_method, io_object)
254
- expect(output).to eq "<svg><!-- Test IO --></svg>\n"
226
+ expect(output).to eq "<svg><!-- Test IO --></svg>"
255
227
  expect(output).to be_html_safe
256
228
  end
257
229
 
258
230
  it 'return valid svg for file' do
259
231
  output = helper.send(helper_method, File.new(file_path))
260
- expect(output).to eq "<svg xmlns=\"http://www.w3.org/2000/svg\" xml:lang=\"en\" role=\"presentation\"><!-- This is a test comment --></svg>\n"
232
+ expect(output).to eq "<svg xmlns=\"http://www.w3.org/2000/svg\" xml:lang=\"en\" role=\"presentation\"><!-- This is a test comment --></svg>"
261
233
  expect(output).to be_html_safe
262
234
  end
263
235
 
264
236
  end
237
+
238
+ context 'default output' do
239
+ it "returns an SVG tag without any pre or post whitespace characters" do
240
+ input_svg = '<svg></svg>'
241
+
242
+ allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
243
+
244
+ expect(helper.send(helper_method, 'some-file')).to eq "<svg></svg>"
245
+ end
246
+ end
265
247
  end
266
248
 
267
249
  describe '#inline_svg' do
@@ -47,7 +47,7 @@ describe InlineSvg do
47
47
  end
48
48
 
49
49
  context "configuring a custom asset file" do
50
- it "falls back to the built-in asset file implementation by deafult" do
50
+ it "falls back to the built-in asset file implementation by default" do
51
51
  expect(InlineSvg.configuration.asset_file).to eq(InlineSvg::AssetFile)
52
52
  end
53
53
 
@@ -0,0 +1,23 @@
1
+ require_relative '../lib/inline_svg'
2
+
3
+ describe InlineSvg::PropshaftAssetFinder do
4
+ context "when the file is not found" do
5
+ it "returns nil" do
6
+ stub_const('Rails', double('Rails').as_null_object)
7
+ expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(nil)
8
+
9
+ expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to be_nil
10
+ end
11
+ end
12
+
13
+ context "when the file is found" do
14
+ it "returns fully qualified file paths from Propshaft" do
15
+ stub_const('Rails', double('Rails').as_null_object)
16
+ asset = double('Asset')
17
+ expect(asset).to receive(:path).and_return(Pathname.new('/full/path/to/some-file'))
18
+ expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(asset)
19
+
20
+ expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to eq Pathname('/full/path/to/some-file')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/inline_svg'
2
+
3
+ describe InlineSvg::StaticAssetFinder do
4
+ context "when the file is not found" do
5
+ it "returns nil" do
6
+ stub_const('Rails', double('Rails').as_null_object)
7
+ expect(::Rails.application.config.assets).to receive(:compile).and_return(true)
8
+
9
+ expect(described_class.find_asset('some-file').pathname).to be_nil
10
+ end
11
+ end
12
+
13
+ context "when the file is found" do
14
+ it "returns fully qualified file path from Sprockets" do
15
+ stub_const('Rails', double('Rails').as_null_object)
16
+ expect(::Rails.application.config.assets).to receive(:compile).and_return(true)
17
+ pathname = Pathname.new('/full/path/to/some-file')
18
+ asset = double('Asset')
19
+ expect(asset).to receive(:filename).and_return(pathname)
20
+ expect(::Rails.application.assets).to receive(:[]).with('some-file').and_return(asset)
21
+
22
+ expect(described_class.find_asset('some-file').pathname).to eq(pathname)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'inline_svg/transform_pipeline'
2
+
3
+ describe InlineSvg::TransformPipeline::Transformations::ViewBox do
4
+ it "adds viewBox attribute to a SVG document" do
5
+ document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
6
+ transformation =
7
+ InlineSvg::TransformPipeline::Transformations::ViewBox
8
+ .create_with_value("0 0 100 100")
9
+ expect(transformation.transform(document).to_html).to eq(
10
+ "<svg viewBox=\"0 0 100 100\">Some document</svg>\n"
11
+ )
12
+ end
13
+ end
@@ -21,6 +21,7 @@ describe InlineSvg::TransformPipeline::Transformations do
21
21
  size: 'irrelevant',
22
22
  height: 'irrelevant',
23
23
  width: 'irrelevant',
24
+ view_box: 'irrelevant',
24
25
  id: 'irrelevant',
25
26
  data: 'irrelevant',
26
27
  preserve_aspect_ratio: 'irrelevant',
@@ -37,6 +38,7 @@ describe InlineSvg::TransformPipeline::Transformations do
37
38
  InlineSvg::TransformPipeline::Transformations::Size,
38
39
  InlineSvg::TransformPipeline::Transformations::Height,
39
40
  InlineSvg::TransformPipeline::Transformations::Width,
41
+ InlineSvg::TransformPipeline::Transformations::ViewBox,
40
42
  InlineSvg::TransformPipeline::Transformations::IdAttribute,
41
43
  InlineSvg::TransformPipeline::Transformations::DataAttributes,
42
44
  InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio,
@@ -0,0 +1,23 @@
1
+ require_relative '../lib/inline_svg'
2
+
3
+ describe InlineSvg::WebpackAssetFinder do
4
+ context "when the file is not found" do
5
+ it "returns nil" do
6
+ stub_const('Rails', double('Rails').as_null_object)
7
+ stub_const('Webpacker', double('Webpacker').as_null_object)
8
+ expect(::Webpacker.manifest).to receive(:lookup).with('some-file').and_return(nil)
9
+
10
+ expect(described_class.find_asset('some-file').pathname).to be_nil
11
+ end
12
+ end
13
+
14
+ context "when Shakapacker is defined" do
15
+ it "uses the new spelling" do
16
+ stub_const('Rails', double('Rails').as_null_object)
17
+ stub_const('Shakapacker', double('Shakapacker').as_null_object)
18
+ expect(::Shakapacker.manifest).to receive(:lookup).with('some-file').and_return(nil)
19
+
20
+ expect(described_class.find_asset('some-file').pathname).to be_nil
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,6 +167,7 @@ files:
167
167
  - lib/inline_svg/transform_pipeline/transformations/style_attribute.rb
168
168
  - lib/inline_svg/transform_pipeline/transformations/title.rb
169
169
  - lib/inline_svg/transform_pipeline/transformations/transformation.rb
170
+ - lib/inline_svg/transform_pipeline/transformations/view_box.rb
170
171
  - lib/inline_svg/transform_pipeline/transformations/width.rb
171
172
  - lib/inline_svg/version.rb
172
173
  - lib/inline_svg/webpack_asset_finder.rb
@@ -184,6 +185,8 @@ files:
184
185
  - spec/id_generator_spec.rb
185
186
  - spec/inline_svg_spec.rb
186
187
  - spec/io_resource_spec.rb
188
+ - spec/propshaft_asset_finder_spec.rb
189
+ - spec/static_asset_finder_spec.rb
187
190
  - spec/transformation_pipeline/transformations/aria_attributes_spec.rb
188
191
  - spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb
189
192
  - spec/transformation_pipeline/transformations/class_attribute_spec.rb
@@ -196,13 +199,15 @@ files:
196
199
  - spec/transformation_pipeline/transformations/style_attribute_spec.rb
197
200
  - spec/transformation_pipeline/transformations/title_spec.rb
198
201
  - spec/transformation_pipeline/transformations/transformation_spec.rb
202
+ - spec/transformation_pipeline/transformations/view_box_spec.rb
199
203
  - spec/transformation_pipeline/transformations/width_spec.rb
200
204
  - spec/transformation_pipeline/transformations_spec.rb
205
+ - spec/webpack_asset_finder_spec.rb
201
206
  homepage: https://github.com/jamesmartin/inline_svg
202
207
  licenses:
203
208
  - MIT
204
209
  metadata: {}
205
- post_install_message:
210
+ post_install_message:
206
211
  rdoc_options: []
207
212
  require_paths:
208
213
  - lib
@@ -217,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
222
  - !ruby/object:Gem::Version
218
223
  version: '0'
219
224
  requirements: []
220
- rubygems_version: 3.1.2
221
- signing_key:
225
+ rubygems_version: 3.1.6
226
+ signing_key:
222
227
  specification_version: 4
223
228
  summary: Embeds an SVG document, inline.
224
229
  test_files:
@@ -236,6 +241,8 @@ test_files:
236
241
  - spec/id_generator_spec.rb
237
242
  - spec/inline_svg_spec.rb
238
243
  - spec/io_resource_spec.rb
244
+ - spec/propshaft_asset_finder_spec.rb
245
+ - spec/static_asset_finder_spec.rb
239
246
  - spec/transformation_pipeline/transformations/aria_attributes_spec.rb
240
247
  - spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb
241
248
  - spec/transformation_pipeline/transformations/class_attribute_spec.rb
@@ -248,5 +255,7 @@ test_files:
248
255
  - spec/transformation_pipeline/transformations/style_attribute_spec.rb
249
256
  - spec/transformation_pipeline/transformations/title_spec.rb
250
257
  - spec/transformation_pipeline/transformations/transformation_spec.rb
258
+ - spec/transformation_pipeline/transformations/view_box_spec.rb
251
259
  - spec/transformation_pipeline/transformations/width_spec.rb
252
260
  - spec/transformation_pipeline/transformations_spec.rb
261
+ - spec/webpack_asset_finder_spec.rb