inline_svg 1.3.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/integration_test.yml +47 -0
- data/.github/workflows/rails_6_webpacker_integration_tests.yaml +58 -0
- data/.github/workflows/ruby.yml +20 -0
- data/CHANGELOG.md +66 -2
- data/README.md +40 -16
- data/inline_svg.gemspec +1 -1
- data/lib/inline_svg/action_view/helpers.rb +38 -4
- data/lib/inline_svg/cached_asset_file.rb +2 -11
- data/lib/inline_svg/finds_asset_paths.rb +1 -1
- data/lib/inline_svg/id_generator.rb +3 -1
- data/lib/inline_svg/propshaft_asset_finder.rb +15 -0
- data/lib/inline_svg/railtie.rb +3 -2
- data/lib/inline_svg/static_asset_finder.rb +4 -2
- data/lib/inline_svg/transform_pipeline/transformations.rb +4 -1
- data/lib/inline_svg/version.rb +1 -1
- data/lib/inline_svg/webpack_asset_finder.rb +50 -0
- data/lib/inline_svg.rb +13 -0
- data/spec/finds_asset_paths_spec.rb +45 -0
- data/spec/helpers/inline_svg_spec.rb +57 -18
- data/spec/id_generator_spec.rb +1 -1
- metadata +10 -7
- data/circle.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23a2c45f1e25e4266196f0e2fc23a4384cb8513be840d2b676ae848b5be1d121
|
4
|
+
data.tar.gz: 8fdb1090f9037ed6c732469ffda28023e200d758533223d4bd9c85b5a20cfb72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3d98f05ba0b9ea222d1b852f87f30584ba4b775d7b6848a2366341e5e85bb6c9912bc1f8441117d129db4d63506d54dcd8ef4d633a5140359e25f5a829a8a1c
|
7
|
+
data.tar.gz: 45eb7d5c8a30f0814e9c775924690825ad3b3ee9c3ada3c9694bf3af46499ababaa1ba81f696514e08dc09aa5ae6520094820fc528ee34fbb307b856dc16b3f4
|
@@ -0,0 +1,47 @@
|
|
1
|
+
name: Integration Tests
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
test-branch: [rails5, rails6, rails7]
|
12
|
+
steps:
|
13
|
+
- name: Checkout
|
14
|
+
uses: actions/checkout@v2
|
15
|
+
- name: Checkout test app
|
16
|
+
uses: actions/checkout@v2
|
17
|
+
with:
|
18
|
+
repository: jamesmartin/inline_svg_test_app
|
19
|
+
ref: ${{ matrix.test-branch }}
|
20
|
+
path: test_app
|
21
|
+
- name: Set up Ruby 2.7
|
22
|
+
uses: actions/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: 2.7.x
|
25
|
+
- name: Build local gem
|
26
|
+
run: |
|
27
|
+
gem install bundler
|
28
|
+
bundle install --jobs 4 --retry 3
|
29
|
+
bundle exec rake build
|
30
|
+
- name: Use the local gem in the test App
|
31
|
+
id: uselocalgem
|
32
|
+
uses: jacobtomlinson/gha-find-replace@0.1.1
|
33
|
+
with:
|
34
|
+
find: "gem 'inline_svg'"
|
35
|
+
replace: "gem 'inline_svg', path: '${{github.workspace}}'"
|
36
|
+
- name: Check local gem in use
|
37
|
+
run: |
|
38
|
+
test "${{ steps.uselocalgem.outputs.modifiedFiles }}" != "0"
|
39
|
+
grep "inline_svg" $GITHUB_WORKSPACE/test_app/Gemfile
|
40
|
+
- name: Bundle
|
41
|
+
run: |
|
42
|
+
cd $GITHUB_WORKSPACE/test_app
|
43
|
+
bundle install --jobs 4 --retry 3
|
44
|
+
- name: Test
|
45
|
+
run: |
|
46
|
+
cd $GITHUB_WORKSPACE/test_app
|
47
|
+
bundle exec rake test
|
@@ -0,0 +1,58 @@
|
|
1
|
+
name: Rails 6 Webpacker Integration Tests (unreliable)
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
test-branch: [rails6-webpacker]
|
12
|
+
steps:
|
13
|
+
- name: Checkout
|
14
|
+
uses: actions/checkout@v2
|
15
|
+
- name: Checkout test app
|
16
|
+
uses: actions/checkout@v2
|
17
|
+
with:
|
18
|
+
repository: jamesmartin/inline_svg_test_app
|
19
|
+
ref: ${{ matrix.test-branch }}
|
20
|
+
path: test_app
|
21
|
+
- name: Set up Ruby 2.7
|
22
|
+
uses: actions/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: 2.7.x
|
25
|
+
- name: Build local gem
|
26
|
+
run: |
|
27
|
+
gem install bundler
|
28
|
+
bundle install --jobs 4 --retry 3
|
29
|
+
bundle exec rake build
|
30
|
+
- name: Use the local gem in the test App
|
31
|
+
id: uselocalgem
|
32
|
+
uses: jacobtomlinson/gha-find-replace@0.1.1
|
33
|
+
with:
|
34
|
+
find: "gem 'inline_svg'"
|
35
|
+
replace: "gem 'inline_svg', path: '${{github.workspace}}'"
|
36
|
+
- name: Check local gem in use
|
37
|
+
run: |
|
38
|
+
test "${{ steps.uselocalgem.outputs.modifiedFiles }}" != "0"
|
39
|
+
grep "inline_svg" $GITHUB_WORKSPACE/test_app/Gemfile
|
40
|
+
- name: Bundle
|
41
|
+
run: |
|
42
|
+
cd $GITHUB_WORKSPACE/test_app
|
43
|
+
bundle install --jobs 4 --retry 3
|
44
|
+
- name: Set up Node.js 16.x
|
45
|
+
uses: actions/setup-node@v2
|
46
|
+
with:
|
47
|
+
node-version: 16
|
48
|
+
if: matrix.test-branch == 'rails6-webpacker'
|
49
|
+
- name: Generate Webpacker config
|
50
|
+
run: |
|
51
|
+
cd $GITHUB_WORKSPACE/test_app
|
52
|
+
yarn install --check-files
|
53
|
+
bundle exec rake webpacker:compile
|
54
|
+
if: matrix.test-branch == 'rails6-webpacker'
|
55
|
+
- name: Test
|
56
|
+
run: |
|
57
|
+
cd $GITHUB_WORKSPACE/test_app
|
58
|
+
bundle exec rake test
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby 2.6
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,62 @@ 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
|
-
|
6
|
+
|
7
|
+
Nothing.
|
8
|
+
|
9
|
+
## [1.8.0] - 2022-01-09
|
10
|
+
### Added
|
11
|
+
- 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)
|
12
|
+
- Add support for Webpacker 6 beta. [#129](https://github.com/jamesmartin/inline_svg/pull/129). Thanks [@Intrepidd](https://github.com/Intrepidd) and [@tessi](https://github.com/tessi)
|
13
|
+
- Add support for Propshaft assets in Rails 7. [#134](https://github.com/jamesmartin/inline_svg/pull/134). Thanks, [@martinzamuner](https://github.com/martinzamuner)
|
14
|
+
|
15
|
+
## [1.7.2] - 2020-12-07
|
16
|
+
### Fixed
|
17
|
+
- Improve performance of `CachedAssetFile`. [#118](https://github.com/jamesmartin/inline_svg/pull/118). Thanks [@stevendaniels](https://github.com/stevendaniels)
|
18
|
+
- Avoid XSS by preventing malicious input of filenames. [#117](https://github.com/jamesmartin/inline_svg/pull/117). Thanks [@pbyrne](https://github.com/pbyrne).
|
19
|
+
|
20
|
+
## [1.7.1] - 2020-03-17
|
21
|
+
### Fixed
|
22
|
+
- Static Asset Finder uses pathname for compatibility with Sprockets 4+. [#106](https://github.com/jamesmartin/inline_svg/pull/106). Thanks [@subdigital](https://github.com/subdigital)
|
23
|
+
|
24
|
+
## [1.7.0] - 2020-02-13
|
25
|
+
### Added
|
26
|
+
- WebpackAssetFinder serves files from dev server if one is running. [#111](https://github.com/jamesmartin/inline_svg/pull/111). Thanks, [@connorshea](https://github.com/connorshea)
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
- Using Webpacker and Asset Pipeline in a single App could result in SVGs not being found because the wrong `AssetFinder` was used. [#114](https://github.com/jamesmartin/inline_svg/pull/114). Thanks, [@kylefox](https://github.com/kylefox)
|
30
|
+
- Prevent "EOFError error" when using webpack dev server over HTTPS [#113](https://github.com/jamesmartin/inline_svg/pull/113). Thanks, [@kylefox](https://github.com/kylefox)
|
31
|
+
|
32
|
+
## [1.6.0] - 2019-11-13
|
33
|
+
### Added
|
34
|
+
- Support Webpack via the new `inline_svg_pack_tag` helper and deprecate `inline_svg` helper in preparation for v2.0.
|
35
|
+
[#103](https://github.com/jamesmartin/inline_svg/pull/103)
|
36
|
+
Thanks, [@kylefox](https://github.com/kylefox)
|
37
|
+
|
38
|
+
## [1.5.2] - 2019-06-20
|
39
|
+
### Fixed
|
40
|
+
- Revert automatic Webpack asset finder behavior. Make Webpack "opt-in".
|
41
|
+
[#98](https://github.com/jamesmartin/inline_svg/issues/98)
|
42
|
+
|
43
|
+
## [1.5.1] - 2019-06-18
|
44
|
+
### Fixed
|
45
|
+
- Prevent nil asset finder when neither Sprockets or Webpacker are available
|
46
|
+
[#97](https://github.com/jamesmartin/inline_svg/issues/97)
|
47
|
+
|
48
|
+
## [1.5.0] - 2019-06-17
|
49
|
+
### Added
|
50
|
+
- Support for finding assets bundled by Webpacker
|
51
|
+
[#96](https://github.com/jamesmartin/inline_svg/pull/96)
|
52
|
+
|
53
|
+
## [1.4.0] - 2019-04-19
|
54
|
+
### Fixed
|
55
|
+
- Prevent invalid XML names being generated via IdGenerator
|
56
|
+
[#87](https://github.com/jamesmartin/inline_svg/issues/87)
|
57
|
+
Thanks, [@endorfin](https://github.com/endorfin)
|
58
|
+
|
59
|
+
### Added
|
60
|
+
- Raise error on file not found (if configured)
|
61
|
+
[#93](https://github.com/jamesmartin/inline_svg/issues/93)
|
7
62
|
|
8
63
|
## [1.3.1] - 2017-12-14
|
9
64
|
### Fixed
|
@@ -189,7 +244,16 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
189
244
|
### Added
|
190
245
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
191
246
|
|
192
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.
|
247
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.8.0...HEAD
|
248
|
+
[1.8.0]: https://github.com/jamesmartin/inline_svg/compare/v1.7.2...v1.8.0
|
249
|
+
[1.7.2]: https://github.com/jamesmartin/inline_svg/compare/v1.7.1...v1.7.2
|
250
|
+
[1.7.1]: https://github.com/jamesmartin/inline_svg/compare/v1.7.0...v1.7.1
|
251
|
+
[1.7.0]: https://github.com/jamesmartin/inline_svg/compare/v1.6.0...v1.7.0
|
252
|
+
[1.6.0]: https://github.com/jamesmartin/inline_svg/compare/v1.5.2...v1.6.0
|
253
|
+
[1.5.2]: https://github.com/jamesmartin/inline_svg/compare/v1.5.1...v1.5.2
|
254
|
+
[1.5.1]: https://github.com/jamesmartin/inline_svg/compare/v1.5.0...v1.5.1
|
255
|
+
[1.5.0]: https://github.com/jamesmartin/inline_svg/compare/v1.4.0...v1.5.0
|
256
|
+
[1.4.0]: https://github.com/jamesmartin/inline_svg/compare/v1.3.1...v1.4.0
|
193
257
|
[1.3.1]: https://github.com/jamesmartin/inline_svg/compare/v1.3.0...v1.3.1
|
194
258
|
[1.3.0]: https://github.com/jamesmartin/inline_svg/compare/v1.2.3...v1.3.0
|
195
259
|
[1.2.3]: https://github.com/jamesmartin/inline_svg/compare/v1.2.2...v1.2.3
|
data/README.md
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# Inline SVG
|
2
2
|
|
3
|
-
|
3
|
+
![Unit tests](https://github.com/jamesmartin/inline_svg/workflows/Ruby/badge.svg)
|
4
|
+
![Integration Tests](https://github.com/jamesmartin/inline_svg/workflows/Integration%20Tests/badge.svg)
|
4
5
|
|
5
6
|
Styling a SVG document with CSS for use on the web is most reliably achieved by
|
6
7
|
[adding classes to the document and
|
7
8
|
embedding](http://css-tricks.com/using-svg/) it inline in the HTML.
|
8
9
|
|
9
|
-
This gem adds
|
10
|
+
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
|
10
11
|
then embeds it into a view.
|
11
12
|
|
12
|
-
Inline SVG supports
|
13
|
+
Inline SVG supports:
|
14
|
+
|
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
|
+
- [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)
|
18
|
+
|
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).
|
13
20
|
|
14
21
|
## Changelog
|
15
22
|
|
@@ -32,9 +39,15 @@ Or install it yourself as:
|
|
32
39
|
|
33
40
|
## Usage
|
34
41
|
|
42
|
+
```ruby
|
43
|
+
# Sprockets
|
44
|
+
inline_svg_tag(file_name, options={})
|
45
|
+
|
46
|
+
# Webpacker
|
47
|
+
inline_svg_pack_tag(file_name, options={})
|
35
48
|
```
|
36
|
-
|
37
|
-
|
49
|
+
|
50
|
+
_**Note:** The remainder of this README uses `inline_svg_tag` for examples, but the exact same principles work for `inline_svg_pack_tag`._
|
38
51
|
|
39
52
|
The `file_name` can be a full path to a file, the file's basename or an `IO`
|
40
53
|
object. The
|
@@ -52,7 +65,7 @@ Here's an example of embedding an SVG document and applying a 'class' attribute:
|
|
52
65
|
<body>
|
53
66
|
<h1>Embedded SVG Documents</h1>
|
54
67
|
<div>
|
55
|
-
<%=
|
68
|
+
<%= inline_svg_tag "some-document.svg", class: 'some-class' %>
|
56
69
|
</div>
|
57
70
|
</body>
|
58
71
|
</html>
|
@@ -86,11 +99,12 @@ key | description
|
|
86
99
|
`preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
|
87
100
|
`aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
|
88
101
|
`aria_hidden` | adds the `aria-hidden=true` attribute to the SVG
|
102
|
+
`fallback` | set fallback SVG document
|
89
103
|
|
90
104
|
Example:
|
91
105
|
|
92
106
|
```ruby
|
93
|
-
|
107
|
+
inline_svg_tag(
|
94
108
|
"some-document.svg",
|
95
109
|
id: 'some-id',
|
96
110
|
class: 'some-class',
|
@@ -101,13 +115,14 @@ inline_svg(
|
|
101
115
|
nocomment: true,
|
102
116
|
preserve_aspect_ratio: 'xMaxYMax meet',
|
103
117
|
aria: true,
|
104
|
-
aria_hidden: true
|
118
|
+
aria_hidden: true,
|
119
|
+
fallback: 'fallback-document.svg'
|
105
120
|
)
|
106
121
|
```
|
107
122
|
|
108
123
|
## Accessibility
|
109
124
|
|
110
|
-
Use the `aria: true` option to make `
|
125
|
+
Use the `aria: true` option to make `inline_svg_tag` add the following
|
111
126
|
accessibility (a11y) attributes to your embedded SVG:
|
112
127
|
|
113
128
|
* Adds a `role="img"` attribute to the root SVG element
|
@@ -118,7 +133,7 @@ Here's an example:
|
|
118
133
|
|
119
134
|
```erb
|
120
135
|
<%=
|
121
|
-
|
136
|
+
inline_svg_tag('iconmonstr-glasses-12-icon.svg',
|
122
137
|
aria: true, title: 'An SVG',
|
123
138
|
desc: 'This is my SVG. There are many like it. You get the picture')
|
124
139
|
%>
|
@@ -132,11 +147,11 @@ Here's an example:
|
|
132
147
|
</svg>
|
133
148
|
```
|
134
149
|
|
135
|
-
***Note:*** The title and desc `id` attributes generated for, and referenced by, `aria-labelled-by` are one-way digests based on the value of the title and desc elements and an optional "salt" value using the SHA1 algorithm. This reduces the chance of `
|
150
|
+
***Note:*** The title and desc `id` attributes generated for, and referenced by, `aria-labelled-by` are one-way digests based on the value of the title and desc elements and an optional "salt" value using the SHA1 algorithm. This reduces the chance of `inline_svg_tag` embedding elements inside the SVG with `id` attributes that clash with other elements elsewhere on the page.
|
136
151
|
|
137
152
|
## Custom Transformations
|
138
153
|
|
139
|
-
The transformation behavior of `
|
154
|
+
The transformation behavior of `inline_svg_tag` can be customized by creating custom transformation classes.
|
140
155
|
|
141
156
|
For example, inherit from `InlineSvg::CustomTransformation` and implement the `#transform` method:
|
142
157
|
|
@@ -165,7 +180,7 @@ end
|
|
165
180
|
The custom transformation can then be called like so:
|
166
181
|
```haml
|
167
182
|
%div
|
168
|
-
=
|
183
|
+
= inline_svg_tag "some-document.svg", my_custom_attribute: 'some value'
|
169
184
|
```
|
170
185
|
|
171
186
|
In this example, the following transformation would be applied to a SVG document:
|
@@ -186,8 +201,8 @@ end
|
|
186
201
|
The custom transformation will be triggered even if you don't pass any attribute value
|
187
202
|
```haml
|
188
203
|
%div
|
189
|
-
=
|
190
|
-
=
|
204
|
+
= inline_svg_tag "some-document.svg"
|
205
|
+
= inline_svg_tag "some-document.svg", my_custom_attribute: 'some value'
|
191
206
|
```
|
192
207
|
|
193
208
|
In this example, the following transformation would be applied to a SVG document:
|
@@ -267,7 +282,7 @@ end
|
|
267
282
|
|
268
283
|
**Note:** Paths are read recursively, so think about keeping your SVG assets
|
269
284
|
restricted to as few paths as possible, and using the filter option to further
|
270
|
-
restrict assets to only those likely to be used by `
|
285
|
+
restrict assets to only those likely to be used by `inline_svg_tag`.
|
271
286
|
|
272
287
|
## Missing SVG Files
|
273
288
|
|
@@ -294,6 +309,15 @@ Which would instead render:
|
|
294
309
|
<svg class='svg-not-found'><!-- SVG file not found: 'some-missing-file.svg' --></svg>
|
295
310
|
```
|
296
311
|
|
312
|
+
Alternatively, `inline_svg_tag` can be configured to raise an exception when a file
|
313
|
+
is not found:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
InlineSvg.configure do |config|
|
317
|
+
config.raise_on_file_not_found = true
|
318
|
+
end
|
319
|
+
```
|
320
|
+
|
297
321
|
## Contributing
|
298
322
|
|
299
323
|
1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) )
|
data/inline_svg.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~>
|
21
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.2"
|
24
24
|
spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
|
@@ -4,10 +4,38 @@ require 'action_view/context' if defined?(Rails)
|
|
4
4
|
module InlineSvg
|
5
5
|
module ActionView
|
6
6
|
module Helpers
|
7
|
+
def inline_svg_tag(filename, transform_params={})
|
8
|
+
with_asset_finder(InlineSvg.configuration.asset_finder) do
|
9
|
+
render_inline_svg(filename, transform_params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def inline_svg_pack_tag(filename, transform_params={})
|
14
|
+
with_asset_finder(InlineSvg::WebpackAssetFinder) do
|
15
|
+
render_inline_svg(filename, transform_params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
7
19
|
def inline_svg(filename, transform_params={})
|
20
|
+
render_inline_svg(filename, transform_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def backwards_compatible_html_escape(filename)
|
26
|
+
# html_escape_once was introduced in newer versions of Rails.
|
27
|
+
if ERB::Util.respond_to?(:html_escape_once)
|
28
|
+
ERB::Util.html_escape_once(filename)
|
29
|
+
else
|
30
|
+
ERB::Util.html_escape(filename)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_inline_svg(filename, transform_params={})
|
8
35
|
begin
|
9
36
|
svg_file = read_svg(filename)
|
10
|
-
rescue InlineSvg::AssetFile::FileNotFound
|
37
|
+
rescue InlineSvg::AssetFile::FileNotFound => error
|
38
|
+
raise error if InlineSvg.configuration.raise_on_file_not_found?
|
11
39
|
return placeholder(filename) unless transform_params[:fallback].present?
|
12
40
|
|
13
41
|
if transform_params[:fallback].present?
|
@@ -22,8 +50,6 @@ module InlineSvg
|
|
22
50
|
InlineSvg::TransformPipeline.generate_html_from(svg_file, transform_params).html_safe
|
23
51
|
end
|
24
52
|
|
25
|
-
private
|
26
|
-
|
27
53
|
def read_svg(filename)
|
28
54
|
if InlineSvg::IOResource === filename
|
29
55
|
InlineSvg::IOResource.read filename
|
@@ -34,7 +60,7 @@ module InlineSvg
|
|
34
60
|
|
35
61
|
def placeholder(filename)
|
36
62
|
css_class = InlineSvg.configuration.svg_not_found_css_class
|
37
|
-
not_found_message = "'#{filename}' #{extension_hint(filename)}"
|
63
|
+
not_found_message = "'#{backwards_compatible_html_escape(filename)}' #{extension_hint(filename)}"
|
38
64
|
|
39
65
|
if css_class.nil?
|
40
66
|
return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
|
@@ -47,6 +73,14 @@ module InlineSvg
|
|
47
73
|
InlineSvg.configuration.asset_file
|
48
74
|
end
|
49
75
|
|
76
|
+
def with_asset_finder(asset_finder)
|
77
|
+
Thread.current[:inline_svg_asset_finder] = asset_finder
|
78
|
+
output = yield
|
79
|
+
Thread.current[:inline_svg_asset_finder] = nil
|
80
|
+
|
81
|
+
output
|
82
|
+
end
|
83
|
+
|
50
84
|
def extension_hint(filename)
|
51
85
|
filename.ends_with?(".svg") ? "" : "(Try adding .svg to your filename) "
|
52
86
|
end
|
@@ -18,6 +18,7 @@ module InlineSvg
|
|
18
18
|
@paths = Array(paths).compact.map { |p| Pathname.new(p) }
|
19
19
|
@filters = Array(filters).map { |f| Regexp.new(f) }
|
20
20
|
@assets = @paths.reduce({}) { |assets, p| assets.merge(read_assets(assets, p)) }
|
21
|
+
@sorted_asset_keys = assets.keys.sort { |a, b| a.size <=> b.size }
|
21
22
|
end
|
22
23
|
|
23
24
|
# Public: Finds the named asset and returns the contents as a string.
|
@@ -39,17 +40,7 @@ module InlineSvg
|
|
39
40
|
# Returns a String representing the key for the named asset or nil if there
|
40
41
|
# is no match.
|
41
42
|
def key_for_asset(asset_name)
|
42
|
-
|
43
|
-
a.string.size <=> b.string.size
|
44
|
-
end.first
|
45
|
-
match && match.string
|
46
|
-
end
|
47
|
-
|
48
|
-
# Internal: Find all potential asset keys matching the given asset name.
|
49
|
-
#
|
50
|
-
# Returns an array of MatchData objects for keys matching the asset name.
|
51
|
-
def all_keys_matching(asset_name)
|
52
|
-
assets.keys.map { |k| /(#{asset_name})/.match(k.to_s) }.compact
|
43
|
+
@sorted_asset_keys.find { |k| k.include?(asset_name) }
|
53
44
|
end
|
54
45
|
|
55
46
|
# Internal: Recursively descends through current_paths reading each file it
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
module InlineSvg
|
2
4
|
class IdGenerator
|
3
5
|
class Randomness
|
@@ -9,7 +11,7 @@ module InlineSvg
|
|
9
11
|
|
10
12
|
def self.generate(base, salt, randomness: Randomness)
|
11
13
|
bytes = Digest::SHA1.digest("#{base}-#{salt}-#{randomness.call}")
|
12
|
-
Digest.hexencode(bytes).to_i(16).to_s(36)
|
14
|
+
'a' + Digest.hexencode(bytes).to_i(16).to_s(36)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module InlineSvg
|
2
|
+
class PropshaftAssetFinder
|
3
|
+
def self.find_asset(filename)
|
4
|
+
new(filename)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@filename = filename
|
9
|
+
end
|
10
|
+
|
11
|
+
def pathname
|
12
|
+
::Rails.application.assets.load_path.find(@filename).path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/inline_svg/railtie.rb
CHANGED
@@ -10,11 +10,12 @@ module InlineSvg
|
|
10
10
|
|
11
11
|
config.after_initialize do |app|
|
12
12
|
InlineSvg.configure do |config|
|
13
|
-
#
|
14
|
-
# Sprockets::Environment instance
|
13
|
+
# Configure the asset_finder:
|
15
14
|
# Only set this when a user-configured asset finder has not been
|
16
15
|
# configured already.
|
17
16
|
if config.asset_finder.nil?
|
17
|
+
# In default Rails apps, this will be a fully operational
|
18
|
+
# Sprockets::Environment instance
|
18
19
|
config.asset_finder = app.instance_variable_get(:@assets)
|
19
20
|
end
|
20
21
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
# Naive fallback asset finder for when sprockets >= 3.0 &&
|
2
4
|
# config.assets.precompile = false
|
3
5
|
# Thanks to @ryanswood for the original code:
|
4
|
-
# https://github.com/
|
6
|
+
# https://github.com/jamesmartin/inline_svg/commit/661bbb3bef7d1b4bd6ccd63f5f018305797b9509
|
5
7
|
module InlineSvg
|
6
8
|
class StaticAssetFinder
|
7
9
|
def self.find_asset(filename)
|
@@ -14,7 +16,7 @@ module InlineSvg
|
|
14
16
|
|
15
17
|
def pathname
|
16
18
|
if ::Rails.application.config.assets.compile
|
17
|
-
::Rails.application.assets[@filename].
|
19
|
+
Pathname.new(::Rails.application.assets[@filename].filename)
|
18
20
|
else
|
19
21
|
manifest = ::Rails.application.assets_manifest
|
20
22
|
asset_path = manifest.assets[@filename]
|
@@ -40,8 +40,11 @@ module InlineSvg::TransformPipeline::Transformations
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.lookup(transform_params)
|
43
|
+
return [] unless transform_params.any? || custom_transformations.any?
|
44
|
+
|
45
|
+
transform_params_with_defaults = params_with_defaults(transform_params)
|
43
46
|
all_transformations.map { |name, definition|
|
44
|
-
value =
|
47
|
+
value = transform_params_with_defaults[name]
|
45
48
|
definition.fetch(:transform, no_transform).create_with_value(value) if value
|
46
49
|
}.compact
|
47
50
|
end
|
data/lib/inline_svg/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module InlineSvg
|
2
|
+
class WebpackAssetFinder
|
3
|
+
def self.find_asset(filename)
|
4
|
+
new(filename)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@filename = filename
|
9
|
+
@asset_path = URI(Webpacker.manifest.lookup(@filename)).path
|
10
|
+
end
|
11
|
+
|
12
|
+
def pathname
|
13
|
+
return if @asset_path.blank?
|
14
|
+
|
15
|
+
if Webpacker.dev_server.running?
|
16
|
+
dev_server_asset(@asset_path)
|
17
|
+
elsif Webpacker.config.public_path.present?
|
18
|
+
File.join(Webpacker.config.public_path, @asset_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def dev_server_asset(file_path)
|
25
|
+
asset = fetch_from_dev_server(file_path)
|
26
|
+
|
27
|
+
begin
|
28
|
+
Tempfile.new(file_path).tap do |file|
|
29
|
+
file.binmode
|
30
|
+
file.write(asset)
|
31
|
+
file.rewind
|
32
|
+
end
|
33
|
+
rescue StandardError => e
|
34
|
+
Rails.logger.error "[inline_svg] Error creating tempfile for #{@filename}: #{e}"
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
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?
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
|
44
|
+
http.request(Net::HTTP::Get.new(file_path)).body
|
45
|
+
rescue StandardError => e
|
46
|
+
Rails.logger.error "[inline_svg] Error fetching #{@filename} from webpack-dev-server: #{e}"
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/inline_svg.rb
CHANGED
@@ -3,7 +3,9 @@ require "inline_svg/action_view/helpers"
|
|
3
3
|
require "inline_svg/asset_file"
|
4
4
|
require "inline_svg/cached_asset_file"
|
5
5
|
require "inline_svg/finds_asset_paths"
|
6
|
+
require "inline_svg/propshaft_asset_finder"
|
6
7
|
require "inline_svg/static_asset_finder"
|
8
|
+
require "inline_svg/webpack_asset_finder"
|
7
9
|
require "inline_svg/transform_pipeline"
|
8
10
|
require "inline_svg/io_resource"
|
9
11
|
|
@@ -21,6 +23,7 @@ module InlineSvg
|
|
21
23
|
@custom_transformations = {}
|
22
24
|
@asset_file = InlineSvg::AssetFile
|
23
25
|
@svg_not_found_css_class = nil
|
26
|
+
@raise_on_file_not_found = false
|
24
27
|
end
|
25
28
|
|
26
29
|
def asset_file=(custom_asset_file)
|
@@ -39,6 +42,8 @@ module InlineSvg
|
|
39
42
|
def asset_finder=(finder)
|
40
43
|
@asset_finder = if finder.respond_to?(:find_asset)
|
41
44
|
finder
|
45
|
+
elsif finder.class.name == "Propshaft::Assembly"
|
46
|
+
InlineSvg::PropshaftAssetFinder
|
42
47
|
else
|
43
48
|
# fallback to a naive static asset finder
|
44
49
|
# (sprokects >= 3.0 && config.assets.precompile = false
|
@@ -61,6 +66,14 @@ module InlineSvg
|
|
61
66
|
@custom_transformations.merge!(Hash[ *[options.fetch(:attribute, :no_attribute), options] ])
|
62
67
|
end
|
63
68
|
|
69
|
+
def raise_on_file_not_found=(value)
|
70
|
+
@raise_on_file_not_found = value
|
71
|
+
end
|
72
|
+
|
73
|
+
def raise_on_file_not_found?
|
74
|
+
!!@raise_on_file_not_found
|
75
|
+
end
|
76
|
+
|
64
77
|
private
|
65
78
|
|
66
79
|
def incompatible_transformation?(klass)
|
@@ -45,4 +45,49 @@ describe InlineSvg::FindsAssetPaths do
|
|
45
45
|
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to be_nil
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
context "when propshaft finder returns an object which supports only the pathname method" do
|
50
|
+
it "returns fully qualified file paths from Propshaft" do
|
51
|
+
propshaft = double('PropshaftDouble')
|
52
|
+
|
53
|
+
expect(propshaft).to receive(:find_asset).with('some-file').
|
54
|
+
and_return(double(pathname: Pathname('/full/path/to/some-file')))
|
55
|
+
|
56
|
+
InlineSvg.configure do |config|
|
57
|
+
config.asset_finder = propshaft
|
58
|
+
end
|
59
|
+
|
60
|
+
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when webpack finder returns an object with a relative asset path" do
|
65
|
+
it "returns the fully qualified file path" do
|
66
|
+
webpacker = double('WebpackerDouble')
|
67
|
+
|
68
|
+
expect(webpacker).to receive(:find_asset).with('some-file').
|
69
|
+
and_return(double(filename: Pathname('/full/path/to/some-file')))
|
70
|
+
|
71
|
+
InlineSvg.configure do |config|
|
72
|
+
config.asset_finder = webpacker
|
73
|
+
end
|
74
|
+
|
75
|
+
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when webpack finder returns an object with an absolute http asset path" do
|
80
|
+
it "returns the fully qualified file path" do
|
81
|
+
webpacker = double('WebpackerDouble')
|
82
|
+
|
83
|
+
expect(webpacker).to receive(:find_asset).with('some-file').
|
84
|
+
and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file')))
|
85
|
+
|
86
|
+
InlineSvg.configure do |config|
|
87
|
+
config.asset_finder = webpacker
|
88
|
+
end
|
89
|
+
|
90
|
+
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('https://my-fancy-domain.test/full/path/to/some-file')
|
91
|
+
end
|
92
|
+
end
|
48
93
|
end
|
@@ -13,29 +13,56 @@ describe InlineSvg::ActionView::Helpers do
|
|
13
13
|
|
14
14
|
let(:helper) { ( Class.new { include InlineSvg::ActionView::Helpers } ).new }
|
15
15
|
|
16
|
-
|
16
|
+
shared_examples "inline_svg helper" do |helper_method:|
|
17
17
|
|
18
18
|
context "when passed the name of an SVG that does not exist" do
|
19
19
|
after(:each) do
|
20
20
|
InlineSvg.reset_configuration!
|
21
21
|
end
|
22
22
|
|
23
|
+
context "and configured to raise" do
|
24
|
+
it "raises an exception" do
|
25
|
+
InlineSvg.configure do |config|
|
26
|
+
config.raise_on_file_not_found = true
|
27
|
+
end
|
28
|
+
|
29
|
+
allow(InlineSvg::AssetFile).to receive(:named).
|
30
|
+
with('some-missing-file.svg').
|
31
|
+
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
32
|
+
|
33
|
+
expect {
|
34
|
+
helper.send(helper_method, 'some-missing-file.svg')
|
35
|
+
}.to raise_error(InlineSvg::AssetFile::FileNotFound)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
23
39
|
it "returns an empty, html safe, SVG document as a placeholder" do
|
24
40
|
allow(InlineSvg::AssetFile).to receive(:named).
|
25
41
|
with('some-missing-file.svg').
|
26
42
|
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
27
43
|
|
28
|
-
output = helper.
|
44
|
+
output = helper.send(helper_method, 'some-missing-file.svg')
|
29
45
|
expect(output).to eq "<svg><!-- SVG file not found: 'some-missing-file.svg' --></svg>"
|
30
46
|
expect(output).to be_html_safe
|
31
47
|
end
|
32
48
|
|
49
|
+
it "escapes malicious input" do
|
50
|
+
malicious = "--></svg><script>alert(1)</script><svg>.svg"
|
51
|
+
allow(InlineSvg::AssetFile).to receive(:named).
|
52
|
+
with(malicious).
|
53
|
+
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
54
|
+
|
55
|
+
output = helper.send(helper_method, malicious)
|
56
|
+
expect(output).to eq "<svg><!-- SVG file not found: '--></svg><script>alert(1)</script><svg>.svg' --></svg>"
|
57
|
+
expect(output).to be_html_safe
|
58
|
+
end
|
59
|
+
|
33
60
|
it "gives a helpful hint when no .svg extension is provided in the filename" do
|
34
61
|
allow(InlineSvg::AssetFile).to receive(:named).
|
35
62
|
with('missing-file-with-no-extension').
|
36
63
|
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
37
64
|
|
38
|
-
output = helper.
|
65
|
+
output = helper.send(helper_method, 'missing-file-with-no-extension')
|
39
66
|
expect(output).to eq "<svg><!-- SVG file not found: 'missing-file-with-no-extension' (Try adding .svg to your filename) --></svg>"
|
40
67
|
end
|
41
68
|
|
@@ -48,7 +75,7 @@ describe InlineSvg::ActionView::Helpers do
|
|
48
75
|
with('some-other-missing-file.svg').
|
49
76
|
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
50
77
|
|
51
|
-
output = helper.
|
78
|
+
output = helper.send(helper_method, 'some-other-missing-file.svg')
|
52
79
|
expect(output).to eq "<svg class='missing-svg'><!-- SVG file not found: 'some-other-missing-file.svg' --></svg>"
|
53
80
|
expect(output).to be_html_safe
|
54
81
|
end
|
@@ -63,7 +90,7 @@ describe InlineSvg::ActionView::Helpers do
|
|
63
90
|
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
|
64
91
|
SVG
|
65
92
|
allow(InlineSvg::AssetFile).to receive(:named).with('fallback.svg').and_return(fallback_file)
|
66
|
-
expect(helper.
|
93
|
+
expect(helper.send(helper_method, 'missing.svg', fallback: 'fallback.svg')).to eq fallback_file
|
67
94
|
end
|
68
95
|
end
|
69
96
|
end
|
@@ -76,7 +103,7 @@ SVG
|
|
76
103
|
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
|
77
104
|
SVG
|
78
105
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(example_file)
|
79
|
-
expect(helper.
|
106
|
+
expect(helper.send(helper_method, 'some-file')).to eq example_file
|
80
107
|
end
|
81
108
|
end
|
82
109
|
|
@@ -89,7 +116,7 @@ SVG
|
|
89
116
|
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title></svg>
|
90
117
|
SVG
|
91
118
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
92
|
-
expect(helper.
|
119
|
+
expect(helper.send(helper_method, 'some-file', title: 'A title')).to eq expected_output
|
93
120
|
end
|
94
121
|
end
|
95
122
|
|
@@ -102,7 +129,7 @@ SVG
|
|
102
129
|
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><desc>A description</desc></svg>
|
103
130
|
SVG
|
104
131
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
105
|
-
expect(helper.
|
132
|
+
expect(helper.send(helper_method, 'some-file', desc: 'A description')).to eq expected_output
|
106
133
|
end
|
107
134
|
end
|
108
135
|
|
@@ -115,7 +142,7 @@ SVG
|
|
115
142
|
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
|
116
143
|
SVG
|
117
144
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
118
|
-
expect(helper.
|
145
|
+
expect(helper.send(helper_method, 'some-file', nocomment: true)).to eq expected_output
|
119
146
|
end
|
120
147
|
end
|
121
148
|
|
@@ -128,7 +155,7 @@ SVG
|
|
128
155
|
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>
|
129
156
|
SVG
|
130
157
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
131
|
-
expect(helper.
|
158
|
+
expect(helper.send(helper_method, 'some-file', aria_hidden: true)).to eq expected_output
|
132
159
|
end
|
133
160
|
end
|
134
161
|
|
@@ -141,7 +168,7 @@ SVG
|
|
141
168
|
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><title>A title</title><desc>A description</desc></svg>
|
142
169
|
SVG
|
143
170
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
144
|
-
expect(helper.
|
171
|
+
expect(helper.send(helper_method, 'some-file', title: 'A title', desc: 'A description', nocomment: true)).to eq expected_output
|
145
172
|
end
|
146
173
|
end
|
147
174
|
|
@@ -164,7 +191,7 @@ SVG
|
|
164
191
|
<svg custom="some value"></svg>
|
165
192
|
SVG
|
166
193
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
167
|
-
expect(helper.
|
194
|
+
expect(helper.send(helper_method, 'some-file', custom: 'some value')).to eq expected_output
|
168
195
|
end
|
169
196
|
end
|
170
197
|
|
@@ -185,7 +212,7 @@ SVG
|
|
185
212
|
|
186
213
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
187
214
|
|
188
|
-
expect(helper.
|
215
|
+
expect(helper.send(helper_method, 'some-file')).to eq "<svg custom=\"default value\"></svg>\n"
|
189
216
|
end
|
190
217
|
end
|
191
218
|
|
@@ -195,7 +222,7 @@ SVG
|
|
195
222
|
|
196
223
|
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
197
224
|
|
198
|
-
expect(helper.
|
225
|
+
expect(helper.send(helper_method, 'some-file', custom: 'some value')).to eq "<svg custom=\"some value\"></svg>\n"
|
199
226
|
end
|
200
227
|
end
|
201
228
|
end
|
@@ -207,13 +234,13 @@ SVG
|
|
207
234
|
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(true)
|
208
235
|
expect(InlineSvg::IOResource).to receive(:read).with(argument)
|
209
236
|
expect(InlineSvg::AssetFile).to_not receive(:named)
|
210
|
-
helper.
|
237
|
+
helper.send(helper_method, argument)
|
211
238
|
end
|
212
239
|
it 'accept filename' do
|
213
240
|
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(false)
|
214
241
|
expect(InlineSvg::IOResource).to_not receive(:read)
|
215
242
|
expect(InlineSvg::AssetFile).to receive(:named).with(argument)
|
216
|
-
helper.
|
243
|
+
helper.send(helper_method, argument)
|
217
244
|
end
|
218
245
|
end
|
219
246
|
context 'when passed IO object argument' do
|
@@ -223,17 +250,29 @@ SVG
|
|
223
250
|
it 'return valid svg' do
|
224
251
|
expect(InlineSvg::IOResource).to receive(:===).with(io_object).and_return(true)
|
225
252
|
expect(InlineSvg::IOResource).to receive(:read).with(io_object).and_return("<svg><!-- Test IO --></svg>")
|
226
|
-
output = helper.
|
253
|
+
output = helper.send(helper_method, io_object)
|
227
254
|
expect(output).to eq "<svg><!-- Test IO --></svg>\n"
|
228
255
|
expect(output).to be_html_safe
|
229
256
|
end
|
230
257
|
|
231
258
|
it 'return valid svg for file' do
|
232
|
-
output = helper.
|
259
|
+
output = helper.send(helper_method, File.new(file_path))
|
233
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"
|
234
261
|
expect(output).to be_html_safe
|
235
262
|
end
|
236
263
|
|
237
264
|
end
|
238
265
|
end
|
266
|
+
|
267
|
+
describe '#inline_svg' do
|
268
|
+
it_behaves_like "inline_svg helper", helper_method: :inline_svg
|
269
|
+
end
|
270
|
+
|
271
|
+
describe '#inline_svg_tag' do
|
272
|
+
it_behaves_like "inline_svg helper", helper_method: :inline_svg_tag
|
273
|
+
end
|
274
|
+
|
275
|
+
describe '#inline_svg_tag' do
|
276
|
+
it_behaves_like "inline_svg helper", helper_method: :inline_svg_pack_tag
|
277
|
+
end
|
239
278
|
end
|
data/spec/id_generator_spec.rb
CHANGED
@@ -5,6 +5,6 @@ describe InlineSvg::IdGenerator do
|
|
5
5
|
randomizer = -> { "some-random-value" }
|
6
6
|
|
7
7
|
expect(InlineSvg::IdGenerator.generate("some-base", "some-salt", randomness: randomizer)).
|
8
|
-
to eq("
|
8
|
+
to eq("at2c17mkqnvopy36iccxspura7wnreqf")
|
9
9
|
end
|
10
10
|
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.
|
4
|
+
version: 1.8.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:
|
11
|
+
date: 2022-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +129,9 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/integration_test.yml"
|
133
|
+
- ".github/workflows/rails_6_webpacker_integration_tests.yaml"
|
134
|
+
- ".github/workflows/ruby.yml"
|
132
135
|
- ".gitignore"
|
133
136
|
- ".rubocop.yml"
|
134
137
|
- ".rubocop_todo.yml"
|
@@ -137,7 +140,6 @@ files:
|
|
137
140
|
- LICENSE.txt
|
138
141
|
- README.md
|
139
142
|
- Rakefile
|
140
|
-
- circle.yml
|
141
143
|
- inline_svg.gemspec
|
142
144
|
- lib/inline_svg.rb
|
143
145
|
- lib/inline_svg/action_view/helpers.rb
|
@@ -146,6 +148,7 @@ files:
|
|
146
148
|
- lib/inline_svg/finds_asset_paths.rb
|
147
149
|
- lib/inline_svg/id_generator.rb
|
148
150
|
- lib/inline_svg/io_resource.rb
|
151
|
+
- lib/inline_svg/propshaft_asset_finder.rb
|
149
152
|
- lib/inline_svg/railtie.rb
|
150
153
|
- lib/inline_svg/static_asset_finder.rb
|
151
154
|
- lib/inline_svg/transform_pipeline.rb
|
@@ -166,6 +169,7 @@ files:
|
|
166
169
|
- lib/inline_svg/transform_pipeline/transformations/transformation.rb
|
167
170
|
- lib/inline_svg/transform_pipeline/transformations/width.rb
|
168
171
|
- lib/inline_svg/version.rb
|
172
|
+
- lib/inline_svg/webpack_asset_finder.rb
|
169
173
|
- spec/asset_file_spec.rb
|
170
174
|
- spec/cached_asset_file_spec.rb
|
171
175
|
- spec/files/example.svg
|
@@ -213,8 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
217
|
- !ruby/object:Gem::Version
|
214
218
|
version: '0'
|
215
219
|
requirements: []
|
216
|
-
|
217
|
-
rubygems_version: 2.6.11
|
220
|
+
rubygems_version: 3.1.2
|
218
221
|
signing_key:
|
219
222
|
specification_version: 4
|
220
223
|
summary: Embeds an SVG document, inline.
|
data/circle.yml
DELETED