inline_svg 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of inline_svg might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f130c4a553b022e11c90d79588f9b7047db3cf1
4
- data.tar.gz: bedb58bb1f1533cf9df734190fff189ea66d60d5
3
+ metadata.gz: 531cbb7571d96241484ed757b76633654f153f41
4
+ data.tar.gz: 0266d52dd58d93a2f10ce83b13ccdb74ae638292
5
5
  SHA512:
6
- metadata.gz: 9f33f0e86a12858fcac918aeb5ebd10fbc1639062db98beece15fa778942383ec07febefe67276d726311fd13c8c82e8905958f0b07fb96cd38da148c2bf596f
7
- data.tar.gz: b3706ac43d6532d07a62b9acdd857dbe08c53dfc352ebcf7a93932fab30faef3a8e378c06e4ca8fc74ae366856a4ab009d6de43ad8b40674be51e3c48dd257fa
6
+ metadata.gz: 0fda6e949182512f4cf42d7301511b056d9db7ce22b0ac56f44e22d74c0ebbc2c2d6c291b1b0e01a407f307105bcf4be0f6a4b60d84714875ddc4ddce6c166f0
7
+ data.tar.gz: 97343026ab606662d7010e53695156b555c339362ecde1f1d4d35c07c8fff271141f8236fe465b93684110cd7da7acd86538a33ada8070b0f33640c2a03adb83
@@ -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.0...HEAD
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
- ```haml
105
- = inline_svg('iconmonstr-glasses-12-icon.svg', class: 'medium-blue', title: 'An SVG', desc: 'This is my SVG. There are many like it. You get the picture', aria: true)
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" version="1.1" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve" data-default-transform="some-default" class="medium-blue" role="img" aria-labelledby="bx6wix4t9pxpwxnohrhrmms3wexsw2o m439lk7mopdzmouktv2o689pl59wmd2"><title id="bx6wix4t9pxpwxnohrhrmms3wexsw2o">An SVG</title>
110
- <path id="glasses-12" d="M358.045,135.833c-19.531,0-40.788,2.213-58.256,8.433c-39.195,14.216-47.93,14.393-87.594,0 c-17.452-6.22-38.742-8.433-58.256-8.433c-33.831,0-71.584,6.639-103.939,15.071v30.704c14.535,4.384,18.34,10.763,20.654,25.624 c6.538,41.953,21.542,83.102,87.007,83.102c52.137,0,69.538-38.785,81.055-74.594c5.851-18.189,28.55-18.658,34.484-0.251 c11.551,35.858,28.868,74.845,81.106,74.845c65.48,0,80.502-41.148,87.023-83.102c2.312-14.861,6.119-21.24,20.67-25.624v-30.704 C429.611,142.472,391.875,135.833,358.045,135.833z M226.16,201.307c-8.885,37.317-23.336,71.859-68.499,71.859 c-56.664,0-68.214-32.665-73.395-85.363c-1.24-12.816,1.576-17.846,3.789-20.512c16.261-19.472,102.178-18.691,130.661-1.584 C226.864,170.603,232.161,176.018,226.16,201.307z M427.7,187.803c-5.163,52.698-16.731,85.363-73.394,85.363 c-45.131,0-59.598-34.542-68.482-71.859c-6.02-25.289-0.721-30.704,7.443-35.6c28.582-17.167,114.449-17.812,130.66,1.584 C426.158,169.957,428.975,174.986,427.7,187.803z M344.65,168.557c26.42-4.023,56.965-0.52,65.078,9.213 c1.777,2.129,4.023,6.152,3.018,16.403c-0.536,5.432-1.156,10.578-1.928,15.457C403.795,184.114,385.822,170.435,344.65,168.557z M101.165,209.63c-0.771-4.879-1.408-10.025-1.944-15.457c-1.006-10.251,1.257-14.274,3.034-16.403 c8.131-9.732,38.675-13.236,65.096-9.213C126.177,170.435,108.206,184.114,101.165,209.63z M376.166,342.923 C356.418,392.177,272.631,380.106,256,349.26c-16.647,30.847-100.418,42.917-120.167-6.337c9.924,8.685,26.873,11.483,39.798,9.589 c38.105-5.582,35.054-41.592,61.693-41.592c7.292,0,13.897,3.034,18.675,7.963c4.777-4.929,11.366-7.963,18.658-7.963 c26.639,0,23.604,36.01,61.693,41.592C349.277,354.406,366.226,351.607,376.166,342.923z"></path>
111
- <desc id="m439lk7mopdzmouktv2o689pl59wmd2">This is my SVG. There are many like it. You get the picture</desc></svg>
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.
@@ -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", ">= 4.0.4"
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
@@ -1,5 +1,5 @@
1
1
  module InlineSvg
2
- class RandomIdGenerator
2
+ class IdGenerator
3
3
  def self.generate(base, salt)
4
4
  bytes = Digest::SHA1.digest("#{base}-#{salt}")
5
5
  Digest.hexencode(bytes).to_i(16).to_s(36)
@@ -11,5 +11,5 @@ end
11
11
 
12
12
  require 'nokogiri'
13
13
  require 'loofah'
14
- require 'inline_svg/random_id_generator'
14
+ require 'inline_svg/id_generator'
15
15
  require 'inline_svg/transform_pipeline/transformations'
@@ -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::RandomIdGenerator.generate(base, value)
29
+ InlineSvg::IdGenerator.generate(base, value)
30
30
  else
31
- InlineSvg::RandomIdGenerator.generate(element['id'], value)
31
+ InlineSvg::IdGenerator.generate(element['id'], value)
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -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).with('some-missing-file').and_raise(InlineSvg::AssetFile::FileNotFound.new)
21
- output = helper.inline_svg('some-missing-file')
22
- expect(output).to eq "<svg><!-- SVG file not found: 'some-missing-file' --></svg>"
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
@@ -0,0 +1,8 @@
1
+ require_relative '../lib/inline_svg/id_generator'
2
+
3
+ describe InlineSvg::IdGenerator do
4
+ it "generates a hexencoded ID based on a salt" do
5
+ expect(InlineSvg::IdGenerator.generate("some-base", "some-salt")).
6
+ to eq("ksiuuy1jduycacqpoj5smn2kyt9iv02")
7
+ end
8
+ end
@@ -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::RandomIdGenerator).to receive(:generate).with("title", "some-salt").
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::RandomIdGenerator).to receive(:generate).with("desc", "some-salt").
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::RandomIdGenerator).to receive(:generate).with("title", "some-salt").
42
+ expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "some-salt").
43
43
  and_return("some-id")
44
- expect(InlineSvg::RandomIdGenerator).to receive(:generate).with("desc", "some-salt").
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::RandomIdGenerator).to receive(:generate).with("my-title", "some-salt").
56
+ expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "some-salt").
57
57
  and_return("some-id")
58
- expect(InlineSvg::RandomIdGenerator).to receive(:generate).with("my-desc", "some-salt").
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.0
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-06-30 00:00:00.000000000 Z
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.4
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.4
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