inline_svg 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of inline_svg might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +13 -5
- data/inline_svg.gemspec +1 -1
- data/lib/inline_svg/action_view/helpers.rb +7 -1
- data/lib/inline_svg/{random_id_generator.rb → id_generator.rb} +1 -1
- data/lib/inline_svg/transform_pipeline.rb +1 -1
- data/lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb +2 -2
- data/lib/inline_svg/version.rb +1 -1
- data/spec/helpers/inline_svg_spec.rb +15 -3
- data/spec/id_generator_spec.rb +8 -0
- data/spec/transformation_pipeline/transformations/aria_attributes_spec.rb +6 -6
- metadata +9 -9
- data/spec/random_id_generator_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 531cbb7571d96241484ed757b76633654f153f41
|
4
|
+
data.tar.gz: 0266d52dd58d93a2f10ce83b13ccdb74ae638292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fda6e949182512f4cf42d7301511b056d9db7ce22b0ac56f44e22d74c0ebbc2c2d6c291b1b0e01a407f307105bcf4be0f6a4b60d84714875ddc4ddce6c166f0
|
7
|
+
data.tar.gz: 97343026ab606662d7010e53695156b555c339362ecde1f1d4d35c07c8fff271141f8236fe465b93684110cd7da7acd86538a33ada8070b0f33640c2a03adb83
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
## [Unreleased][unreleased]
|
6
6
|
- Nothing
|
7
7
|
|
8
|
+
## [0.9.1] - 2016-07-18
|
9
|
+
### Fixed
|
10
|
+
- Provide a hint when the .svg extension is omitted from the filename
|
11
|
+
[#41](https://github.com/jamesmartin/inline_svg/issues/41)
|
12
|
+
|
8
13
|
## [0.9.0] - 2016-06-30
|
9
14
|
### Fixed
|
10
15
|
- Hashed IDs for desc and title elements in aria-labeled-by attribute
|
@@ -96,7 +101,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
96
101
|
### Added
|
97
102
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
98
103
|
|
99
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.9.
|
104
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.9.1...HEAD
|
105
|
+
[0.9.1]: https://github.com/jamesmartin/inline_svg/compare/v0.8.0...v0.9.1
|
100
106
|
[0.9.0]: https://github.com/jamesmartin/inline_svg/compare/v0.8.0...v0.9.0
|
101
107
|
[0.8.0]: https://github.com/jamesmartin/inline_svg/compare/v0.7.0...v0.8.0
|
102
108
|
[0.7.0]: https://github.com/jamesmartin/inline_svg/compare/v0.6.4...v0.7.0
|
data/README.md
CHANGED
@@ -101,16 +101,24 @@ accessibility (a11y) attributes to your embedded SVG:
|
|
101
101
|
|
102
102
|
Here's an example:
|
103
103
|
|
104
|
-
```
|
105
|
-
|
104
|
+
```erb
|
105
|
+
<%=
|
106
|
+
inline_svg('iconmonstr-glasses-12-icon.svg',
|
107
|
+
aria: true, title: 'An SVG',
|
108
|
+
desc: 'This is my SVG. There are many like it. You get the picture')
|
109
|
+
%>
|
106
110
|
```
|
107
111
|
|
108
112
|
```xml
|
109
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
110
|
-
|
111
|
-
|
113
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \
|
114
|
+
role="img" aria-labelledby="bx6wix4t9pxpwxnohrhrmms3wexsw2o m439lk7mopdzmouktv2o689pl59wmd2">
|
115
|
+
<title id="bx6wix4t9pxpwxnohrhrmms3wexsw2o">An SVG</title>
|
116
|
+
<desc id="m439lk7mopdzmouktv2o689pl59wmd2">This is my SVG. There are many like it. You get the picture</desc>
|
117
|
+
</svg>
|
112
118
|
```
|
113
119
|
|
120
|
+
***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` embedding elements inside the SVG with `id` attributes that clash with other elements elsewhere on the page.
|
121
|
+
|
114
122
|
## Custom Transformations
|
115
123
|
|
116
124
|
The transformation behavior of `inline_svg` can be customized by creating custom transformation classes.
|
data/inline_svg.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.2"
|
24
24
|
spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
|
25
25
|
|
26
|
-
spec.add_runtime_dependency "activesupport", "
|
26
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0"
|
27
27
|
spec.add_runtime_dependency "nokogiri", "~> 1.6", '~> 1.6'
|
28
28
|
spec.add_runtime_dependency "loofah", ">= 2.0"
|
29
29
|
end
|
@@ -12,11 +12,17 @@ module InlineSvg
|
|
12
12
|
InlineSvg::AssetFile.named filename
|
13
13
|
end
|
14
14
|
rescue InlineSvg::AssetFile::FileNotFound
|
15
|
-
return "<svg><!-- SVG file not found: '#{filename}' --></svg>".html_safe
|
15
|
+
return "<svg><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
|
16
16
|
end
|
17
17
|
|
18
18
|
InlineSvg::TransformPipeline.generate_html_from(svg_file, transform_params).html_safe
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def extension_hint(filename)
|
24
|
+
filename.ends_with?(".svg") ? "" : "(Try adding .svg to your filename) "
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -26,9 +26,9 @@ module InlineSvg::TransformPipeline::Transformations
|
|
26
26
|
|
27
27
|
def element_id_for(base, element)
|
28
28
|
if element['id'].nil?
|
29
|
-
InlineSvg::
|
29
|
+
InlineSvg::IdGenerator.generate(base, value)
|
30
30
|
else
|
31
|
-
InlineSvg::
|
31
|
+
InlineSvg::IdGenerator.generate(element['id'], value)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/inline_svg/version.rb
CHANGED
@@ -17,11 +17,23 @@ describe InlineSvg::ActionView::Helpers do
|
|
17
17
|
|
18
18
|
context "when passed the name of an SVG that does not exist" do
|
19
19
|
it "returns an empty, html safe, SVG document as a placeholder" do
|
20
|
-
allow(InlineSvg::AssetFile).to receive(:named).
|
21
|
-
|
22
|
-
|
20
|
+
allow(InlineSvg::AssetFile).to receive(:named).
|
21
|
+
with('some-missing-file.svg').
|
22
|
+
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
23
|
+
|
24
|
+
output = helper.inline_svg('some-missing-file.svg')
|
25
|
+
expect(output).to eq "<svg><!-- SVG file not found: 'some-missing-file.svg' --></svg>"
|
23
26
|
expect(output).to be_html_safe
|
24
27
|
end
|
28
|
+
|
29
|
+
it "gives a helpful hint when no .svg extension is provided in the filename" do
|
30
|
+
allow(InlineSvg::AssetFile).to receive(:named).
|
31
|
+
with('missing-file-with-no-extension').
|
32
|
+
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
33
|
+
|
34
|
+
output = helper.inline_svg('missing-file-with-no-extension')
|
35
|
+
expect(output).to eq "<svg><!-- SVG file not found: 'missing-file-with-no-extension' (Try adding .svg to your filename) --></svg>"
|
36
|
+
end
|
25
37
|
end
|
26
38
|
|
27
39
|
context "when passed an existing SVG file" do
|
@@ -15,7 +15,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
15
15
|
document = Nokogiri::XML::Document.parse('<svg><title>Some title</title>Some document</svg>')
|
16
16
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
|
17
17
|
|
18
|
-
expect(InlineSvg::
|
18
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "some-salt").
|
19
19
|
and_return("some-id")
|
20
20
|
|
21
21
|
expect(transformation.transform(document).to_html).to eq(
|
@@ -27,7 +27,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
27
27
|
document = Nokogiri::XML::Document.parse('<svg><desc>Some description</desc>Some document</svg>')
|
28
28
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
|
29
29
|
|
30
|
-
expect(InlineSvg::
|
30
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "some-salt").
|
31
31
|
and_return("some-id")
|
32
32
|
|
33
33
|
expect(transformation.transform(document).to_html).to eq(
|
@@ -39,9 +39,9 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
39
39
|
document = Nokogiri::XML::Document.parse('<svg><title>Some title</title><desc>Some description</desc>Some document</svg>')
|
40
40
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
|
41
41
|
|
42
|
-
expect(InlineSvg::
|
42
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "some-salt").
|
43
43
|
and_return("some-id")
|
44
|
-
expect(InlineSvg::
|
44
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "some-salt").
|
45
45
|
and_return("some-other-id")
|
46
46
|
|
47
47
|
expect(transformation.transform(document).to_html).to eq(
|
@@ -53,9 +53,9 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
53
53
|
document = Nokogiri::XML::Document.parse('<svg><title id="my-title">Some title</title><desc id="my-desc">Some description</desc>Some document</svg>')
|
54
54
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
|
55
55
|
|
56
|
-
expect(InlineSvg::
|
56
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "some-salt").
|
57
57
|
and_return("some-id")
|
58
|
-
expect(InlineSvg::
|
58
|
+
expect(InlineSvg::IdGenerator).to receive(:generate).with("my-desc", "some-salt").
|
59
59
|
and_return("some-other-id")
|
60
60
|
|
61
61
|
expect(transformation.transform(document).to_html).to eq(
|
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: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.0
|
75
|
+
version: '4.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 4.0
|
82
|
+
version: '4.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: nokogiri
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,9 +126,9 @@ files:
|
|
126
126
|
- lib/inline_svg/action_view/helpers.rb
|
127
127
|
- lib/inline_svg/asset_file.rb
|
128
128
|
- lib/inline_svg/finds_asset_paths.rb
|
129
|
+
- lib/inline_svg/id_generator.rb
|
129
130
|
- lib/inline_svg/io_resource.rb
|
130
131
|
- lib/inline_svg/railtie.rb
|
131
|
-
- lib/inline_svg/random_id_generator.rb
|
132
132
|
- lib/inline_svg/static_asset_finder.rb
|
133
133
|
- lib/inline_svg/transform_pipeline.rb
|
134
134
|
- lib/inline_svg/transform_pipeline/transformations.rb
|
@@ -149,9 +149,9 @@ files:
|
|
149
149
|
- spec/files/example.svg
|
150
150
|
- spec/finds_asset_paths_spec.rb
|
151
151
|
- spec/helpers/inline_svg_spec.rb
|
152
|
+
- spec/id_generator_spec.rb
|
152
153
|
- spec/inline_svg_spec.rb
|
153
154
|
- spec/io_resource_spec.rb
|
154
|
-
- spec/random_id_generator_spec.rb
|
155
155
|
- spec/transformation_pipeline/transformations/aria_attributes_spec.rb
|
156
156
|
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
157
157
|
- spec/transformation_pipeline/transformations/height_spec.rb
|
@@ -190,9 +190,9 @@ test_files:
|
|
190
190
|
- spec/files/example.svg
|
191
191
|
- spec/finds_asset_paths_spec.rb
|
192
192
|
- spec/helpers/inline_svg_spec.rb
|
193
|
+
- spec/id_generator_spec.rb
|
193
194
|
- spec/inline_svg_spec.rb
|
194
195
|
- spec/io_resource_spec.rb
|
195
|
-
- spec/random_id_generator_spec.rb
|
196
196
|
- spec/transformation_pipeline/transformations/aria_attributes_spec.rb
|
197
197
|
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
198
198
|
- spec/transformation_pipeline/transformations/height_spec.rb
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require_relative '../lib/inline_svg/random_id_generator'
|
2
|
-
|
3
|
-
describe InlineSvg::RandomIdGenerator do
|
4
|
-
it "generates a hexencoded ID based on a salt" do
|
5
|
-
expect(InlineSvg::RandomIdGenerator.generate("some-base", "some-salt")).
|
6
|
-
to eq("ksiuuy1jduycacqpoj5smn2kyt9iv02")
|
7
|
-
end
|
8
|
-
end
|