inline_svg 1.9.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: 9be789332e6a5c01a7cde946e537fe0cf1fb368fb1c1b102538298bb65791c21
4
- data.tar.gz: fbb837594c30b641df85c6d5919737d14a8fc4dc9fe9fcd522ef403af913a0aa
3
+ metadata.gz: 66214539304b60e87e9263afb26531212492ca77957e9ce8cf89d015cef86239
4
+ data.tar.gz: 6ab9cb3d75a9f268728600edb48bf27b3503145c80f1addabe8bc484c88af545
5
5
  SHA512:
6
- metadata.gz: d4181b4e48b2a5ef634dc80504e52bef5304bd7dc1c1cf44a710ed88653d175d7825640b557150033ce45c5d2bcf32f5c4fb906fffd14d9f41a62aedc2eb1254
7
- data.tar.gz: 9e79590cf289ec30fb7b773fddd676df83822cc174af6fc6cd0bc0e38536c760a6584937c7795509b8e924384e6da9e86e45742781106697e1808961683264ee
6
+ metadata.gz: 1f8d4642dff97eb5bfc358fd1ce2257d5113a6f232c02f4ecd847007ee861b2537748539c689e5e2e67297951fdd158594740a754d49469cbd8c13c72002c290
7
+ data.tar.gz: 1b5cb2dfd5e7067d64ec0cc3449c2aeeead3a39cab42f8d51db33609a296478511fa9a24a965e32b10d7f01c98e5cb4b2ef8a6268fb055a7ad968068499eccd6
data/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [Unreleased][unreleased]
6
+
7
+ Nothing.
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
6
19
  ### Added
7
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)
8
21
 
@@ -208,7 +221,7 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
208
221
 
209
222
  ## [0.5.1] - 2015-03-30
210
223
  ### Warning
211
- ** This version is NOT comaptible with Sprockets >= 3. **
224
+ ** This version is NOT compatible with Sprockets >= 3. **
212
225
 
213
226
  ### Fixed
214
227
  - Support for ActiveSupport (and hence, Rails) 4.2.x. Thanks, @jmarceli.
@@ -249,7 +262,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
249
262
  ### Added
250
263
  - Basic Railtie and view helper to inline SVG documents to Rails views.
251
264
 
252
- [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
253
267
  [1.8.0]: https://github.com/jamesmartin/inline_svg/compare/v1.7.2...v1.8.0
254
268
  [1.7.2]: https://github.com/jamesmartin/inline_svg/compare/v1.7.1...v1.7.2
255
269
  [1.7.1]: https://github.com/jamesmartin/inline_svg/compare/v1.7.0...v1.7.1
@@ -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.9.0"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -6,22 +6,31 @@ module InlineSvg
6
6
 
7
7
  def initialize(filename)
8
8
  @filename = filename
9
- manifest_lookup = Webpacker.manifest.lookup(@filename)
9
+ manifest_lookup = asset_helper.manifest.lookup(@filename)
10
10
  @asset_path = manifest_lookup.present? ? URI(manifest_lookup).path : ""
11
11
  end
12
12
 
13
13
  def pathname
14
14
  return if @asset_path.blank?
15
15
 
16
- if Webpacker.dev_server.running?
16
+ if asset_helper.dev_server.running?
17
17
  dev_server_asset(@asset_path)
18
- elsif Webpacker.config.public_path.present?
19
- 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)
20
20
  end
21
21
  end
22
22
 
23
23
  private
24
24
 
25
+ def asset_helper
26
+ @asset_helper ||=
27
+ if defined?(::Shakapacker)
28
+ ::Shakapacker
29
+ else
30
+ ::Webpacker
31
+ end
32
+ end
33
+
25
34
  def dev_server_asset(file_path)
26
35
  asset = fetch_from_dev_server(file_path)
27
36
 
@@ -38,8 +47,8 @@ module InlineSvg
38
47
  end
39
48
 
40
49
  def fetch_from_dev_server(file_path)
41
- http = Net::HTTP.new(Webpacker.dev_server.host, Webpacker.dev_server.port)
42
- 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"
43
52
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
53
 
45
54
  http.request(Net::HTTP::Get.new(file_path)).body
data/lib/inline_svg.rb CHANGED
@@ -11,6 +11,7 @@ require "inline_svg/io_resource"
11
11
 
12
12
  require "inline_svg/railtie" if defined?(Rails)
13
13
  require 'active_support'
14
+ require 'active_support/core_ext/object/blank'
14
15
  require 'active_support/core_ext/string'
15
16
  require 'nokogiri'
16
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
 
@@ -10,4 +10,14 @@ describe InlineSvg::WebpackAssetFinder do
10
10
  expect(described_class.find_asset('some-file').pathname).to be_nil
11
11
  end
12
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
13
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.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-29 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
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubygems_version: 3.3.26
225
+ rubygems_version: 3.1.6
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: Embeds an SVG document, inline.