inline_svg 0.6.4 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20cf938dedae16a9b3f2282f60666911ea31918d
4
- data.tar.gz: 3e85ceba1e9306512ce5b6c8bf5e362449da05fb
3
+ metadata.gz: 0c003e0cd953e58b743df9c836748124cac54bab
4
+ data.tar.gz: 58b09ffa5695e837d113957adeb339db0f0484dc
5
5
  SHA512:
6
- metadata.gz: 913ca48724b6e124be585023a910568f7f7d850521f0e8294832160b84cd7c6e063b51cd5ddc097a22c92078c32f2f29be48c81ef0b300ff37f07fecd54c1ea6
7
- data.tar.gz: ee22b302999f9bd020af932b4615a061cf3c8a14bb0a5bb5091f6f44edeb2f6fbd11e90fb82dba031d0161fe5e97a0fd368b6ed559246c0fd1b4e30fffe677be
6
+ metadata.gz: ba4074f8ae922fc6ef08a0e9ecbe66e334350e21be1374b6f72b20a9093f73652540cf248bc5392e41678233580135bf1609dab4a6e2ded08ae1b4f7c72b6541
7
+ data.tar.gz: ec749c7628ad273fb5605e70abe309aa74be1dec9c307ae1656de02d34294d81fd8a6244bd24293b03a17fff3558ec3a8c33706c22e5c7e3b9f2b25cd7169bb1
data/CHANGELOG.md CHANGED
@@ -5,11 +5,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## [Unreleased][unreleased]
6
6
  - Nothing.
7
7
 
8
+ ## [0.7.0] - 2016-05-03
9
+ ### Added
10
+ - Aria attributes transform (aria-labelledby / role etc.) Addresses issue
11
+ [#28](https://github.com/jamesmartin/inline_svg/issues/28)
12
+
8
13
  ## [0.6.4] - 2016-04-23
9
14
  ### Fixed
10
15
  - Don't duplicate the `title` element. Addresses issue
11
- [#31](https://github.com/jamesmartin/inline_svg/issues/31).
12
- - Make the `title` element the first child node of the SVG document.
16
+ [#31](https://github.com/jamesmartin/inline_svg/issues/31)
17
+ - Make the `title` element the first child node of the SVG document
13
18
 
14
19
  ## [0.6.3] - 2016-04-19
15
20
  ### Added
@@ -80,7 +85,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
80
85
  ### Added
81
86
  - Basic Railtie and view helper to inline SVG documents to Rails views.
82
87
 
83
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.6.4...HEAD
88
+ [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.7.0...HEAD
89
+ [0.7.0]: https://github.com/jamesmartin/inline_svg/compare/v0.6.3...v0.7.0
84
90
  [0.6.4]: https://github.com/jamesmartin/inline_svg/compare/v0.6.3...v0.6.4
85
91
  [0.6.3]: https://github.com/jamesmartin/inline_svg/compare/v0.6.2...v0.6.3
86
92
  [0.6.2]: https://github.com/jamesmartin/inline_svg/compare/v0.6.1...v0.6.2
data/README.md CHANGED
@@ -81,12 +81,13 @@ key | description
81
81
  `desc` | add a \<desc\> node inside the top level of the SVG document
82
82
  `nocomment` | remove comment tags (and other unsafe/unknown tags) from svg (uses the [Loofah](https://github.com/flavorjones/loofah) gem)
83
83
  `preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
84
+ `aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
84
85
 
85
86
  Example:
86
87
 
87
88
  ```ruby
88
89
  inline_svg("some-document.svg", id: 'some-id', class: 'some-class', data: {some: "value"}, size: '30% * 20%', title: 'Some Title', desc:
89
- 'Some description', nocomment: true, preserve_aspect_ratio: 'xMaxYMax meet')
90
+ 'Some description', nocomment: true, preserve_aspect_ratio: 'xMaxYMax meet', aria: true)
90
91
  ```
91
92
 
92
93
  ## Custom Transformations
@@ -0,0 +1,23 @@
1
+ module InlineSvg::TransformPipeline::Transformations
2
+ class AriaAttributes < Transformation
3
+ def transform(doc)
4
+ doc = Nokogiri::XML::Document.parse(doc.to_html)
5
+ svg = doc.at_css("svg")
6
+
7
+ # Add role
8
+ svg["role"] = "img"
9
+
10
+ # Build aria-labelledby string
11
+ aria_elements = []
12
+ doc.search("svg title").each { |_| aria_elements << "title" }
13
+ doc.search("svg desc").each { |_| aria_elements << "desc" }
14
+ aria_elements.uniq!
15
+
16
+ if aria_elements.any?
17
+ svg["aria-labelledby"] = aria_elements.join(" ")
18
+ end
19
+
20
+ doc
21
+ end
22
+ end
23
+ end
@@ -10,7 +10,8 @@ module InlineSvg::TransformPipeline::Transformations
10
10
  width: Width,
11
11
  id: IdAttribute,
12
12
  data: DataAttributes,
13
- preserve_aspect_ratio: PreserveAspectRatio
13
+ preserve_aspect_ratio: PreserveAspectRatio,
14
+ aria: AriaAttributes
14
15
  }
15
16
  end
16
17
 
@@ -44,3 +45,4 @@ require 'inline_svg/transform_pipeline/transformations/width'
44
45
  require 'inline_svg/transform_pipeline/transformations/id_attribute'
45
46
  require 'inline_svg/transform_pipeline/transformations/data_attributes'
46
47
  require 'inline_svg/transform_pipeline/transformations/preserve_aspect_ratio'
48
+ require 'inline_svg/transform_pipeline/transformations/aria_attributes'
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'inline_svg/transform_pipeline'
2
+
3
+ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
4
+ it "adds a role attribute to the SVG document" do
5
+ document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
6
+ transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
7
+
8
+ expect(transformation.transform(document).to_html).to eq(
9
+ "<svg role=\"img\">Some document</svg>\n"
10
+ )
11
+ end
12
+
13
+ context "aria-labelledby attribute" do
14
+ it "adds 'title' when a title element is present" do
15
+ document = Nokogiri::XML::Document.parse('<svg><title>Some title</title>Some document</svg>')
16
+ transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
17
+
18
+ expect(transformation.transform(document).to_html).to eq(
19
+ "<svg role=\"img\" aria-labelledby=\"title\"><title>Some title</title>Some document</svg>\n"
20
+ )
21
+ end
22
+
23
+ it "adds 'desc' when a description element is present" do
24
+ document = Nokogiri::XML::Document.parse('<svg><desc>Some description</desc>Some document</svg>')
25
+ transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
26
+
27
+ expect(transformation.transform(document).to_html).to eq(
28
+ "<svg role=\"img\" aria-labelledby=\"desc\"><desc>Some description</desc>Some document</svg>\n"
29
+ )
30
+ end
31
+
32
+ it "adds both 'desc' and 'title' when title and description elements are present" do
33
+ document = Nokogiri::XML::Document.parse('<svg><title>Some title</title><desc>Some description</desc>Some document</svg>')
34
+ transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
35
+
36
+ expect(transformation.transform(document).to_html).to eq(
37
+ "<svg role=\"img\" aria-labelledby=\"title desc\"><title>Some title</title>\n<desc>Some description</desc>Some document</svg>\n"
38
+ )
39
+ end
40
+ end
41
+ end
@@ -21,6 +21,7 @@ describe InlineSvg::TransformPipeline::Transformations do
21
21
  id: 'irrelevant',
22
22
  data: 'irrelevant',
23
23
  preserve_aspect_ratio: 'irrelevant',
24
+ aria: 'irrelevant',
24
25
  )
25
26
 
26
27
  expect(transformations.map(&:class)).to match_array([
@@ -33,7 +34,8 @@ describe InlineSvg::TransformPipeline::Transformations do
33
34
  InlineSvg::TransformPipeline::Transformations::Width,
34
35
  InlineSvg::TransformPipeline::Transformations::IdAttribute,
35
36
  InlineSvg::TransformPipeline::Transformations::DataAttributes,
36
- InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio
37
+ InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio,
38
+ InlineSvg::TransformPipeline::Transformations::AriaAttributes
37
39
  ])
38
40
  end
39
41
 
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.6.4
4
+ version: 0.7.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: 2016-04-22 00:00:00.000000000 Z
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/inline_svg/static_asset_finder.rb
132
132
  - lib/inline_svg/transform_pipeline.rb
133
133
  - lib/inline_svg/transform_pipeline/transformations.rb
134
+ - lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb
134
135
  - lib/inline_svg/transform_pipeline/transformations/class_attribute.rb
135
136
  - lib/inline_svg/transform_pipeline/transformations/data_attributes.rb
136
137
  - lib/inline_svg/transform_pipeline/transformations/description.rb
@@ -149,6 +150,7 @@ files:
149
150
  - spec/helpers/inline_svg_spec.rb
150
151
  - spec/inline_svg_spec.rb
151
152
  - spec/io_resource_spec.rb
153
+ - spec/transformation_pipeline/aria_attributes_spec.rb
152
154
  - spec/transformation_pipeline/transformations/data_attributes_spec.rb
153
155
  - spec/transformation_pipeline/transformations/height_spec.rb
154
156
  - spec/transformation_pipeline/transformations/id_attribute_spec.rb
@@ -188,6 +190,7 @@ test_files:
188
190
  - spec/helpers/inline_svg_spec.rb
189
191
  - spec/inline_svg_spec.rb
190
192
  - spec/io_resource_spec.rb
193
+ - spec/transformation_pipeline/aria_attributes_spec.rb
191
194
  - spec/transformation_pipeline/transformations/data_attributes_spec.rb
192
195
  - spec/transformation_pipeline/transformations/height_spec.rb
193
196
  - spec/transformation_pipeline/transformations/id_attribute_spec.rb