inline_svg 1.2.1 → 1.2.2
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 +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +31 -7
- data/Rakefile +7 -0
- data/lib/inline_svg.rb +8 -1
- data/lib/inline_svg/action_view/helpers.rb +5 -1
- data/lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb +16 -19
- data/lib/inline_svg/transform_pipeline/transformations/class_attribute.rb +5 -6
- data/lib/inline_svg/transform_pipeline/transformations/data_attributes.rb +4 -5
- data/lib/inline_svg/transform_pipeline/transformations/description.rb +7 -6
- data/lib/inline_svg/transform_pipeline/transformations/height.rb +3 -4
- data/lib/inline_svg/transform_pipeline/transformations/id_attribute.rb +3 -4
- data/lib/inline_svg/transform_pipeline/transformations/no_comment.rb +4 -4
- data/lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb +3 -4
- data/lib/inline_svg/transform_pipeline/transformations/size.rb +4 -5
- data/lib/inline_svg/transform_pipeline/transformations/title.rb +7 -6
- data/lib/inline_svg/transform_pipeline/transformations/transformation.rb +11 -0
- data/lib/inline_svg/transform_pipeline/transformations/width.rb +3 -4
- data/lib/inline_svg/version.rb +1 -1
- data/spec/helpers/inline_svg_spec.rb +19 -1
- data/spec/inline_svg_spec.rb +10 -0
- data/spec/transformation_pipeline/transformations/aria_attributes_spec.rb +6 -6
- data/spec/transformation_pipeline/transformations/height_spec.rb +9 -0
- data/spec/transformation_pipeline/transformations/transformation_spec.rb +39 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57995dd216d10c2510f21c3dd8c4901eddf3e3e3
|
4
|
+
data.tar.gz: 8a7bde8b778843e483350f3d0ee26ddb8d6d624a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfc12998a8e3e64a8a1a338905673259118aaa84c6d67cd0a94ed11d4372102838a92dd4fb7f3d7a0c7e4c1b4475d627df7feb1b84090816a0ffef1fa6b424c
|
7
|
+
data.tar.gz: 90940b65ec989da35c2ccf3e25aaacd5d0cced3f175bb99ce55b6b5d091797a1e78d7c498011cd98427d31f10af54d12e635ed6ba55a983ef0f1529c2945cd74
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
## [Unreleased][unreleased]
|
6
6
|
- Nothing
|
7
7
|
|
8
|
+
## [1.2.2] - 2017-07-06
|
9
|
+
### Fixed
|
10
|
+
- Handle malformed documents that don't contain a root SVG element
|
11
|
+
[#60](https://github.com/jamesmartin/inline_svg/pull/65)
|
12
|
+
### Added
|
13
|
+
- Add configurable CSS class to empty SVG document
|
14
|
+
[#67](https://github.com/jamesmartin/inline_svg/pull/67)
|
15
|
+
|
8
16
|
## [1.2.1] - 2017-05-02
|
9
17
|
### Fixed
|
10
18
|
- Select most exactly matching cached asset file when multiple files match
|
@@ -159,7 +167,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
159
167
|
### Added
|
160
168
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
161
169
|
|
162
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.
|
170
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.2...HEAD
|
171
|
+
[1.2.2]: https://github.com/jamesmartin/inline_svg/compare/v1.2.1...v1.2.2
|
163
172
|
[1.2.1]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...v1.2.1
|
164
173
|
[1.2.0]: https://github.com/jamesmartin/inline_svg/compare/v1.1.0...v1.2.0
|
165
174
|
[1.1.0]: https://github.com/jamesmartin/inline_svg/compare/v1.0.1...v1.1.0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Inline SVG
|
2
2
|
|
3
|
-
[](https://travis-ci.org/jamesmartin/inline_svg)
|
4
4
|
|
5
5
|
Styling a SVG document with CSS for use on the web is most reliably achieved by
|
6
6
|
[adding classes to the document and
|
@@ -71,10 +71,10 @@ blue:
|
|
71
71
|
}
|
72
72
|
```
|
73
73
|
|
74
|
-
## Options
|
74
|
+
## Options
|
75
75
|
|
76
76
|
key | description
|
77
|
-
:---------------------- | :----------
|
77
|
+
:---------------------- | :----------
|
78
78
|
`id` | set a ID attribute on the SVG
|
79
79
|
`class` | set a CSS class attribute on the SVG
|
80
80
|
`data` | add data attributes to the SVG (supply as a hash)
|
@@ -133,10 +133,9 @@ For example, inherit from `InlineSvg::CustomTransformation` and implement the `#
|
|
133
133
|
|
134
134
|
class MyCustomTransform < InlineSvg::CustomTransformation
|
135
135
|
def transform(doc)
|
136
|
-
doc
|
137
|
-
|
138
|
-
|
139
|
-
doc
|
136
|
+
with_svg(doc) do |svg|
|
137
|
+
svg["custom"] = value
|
138
|
+
end
|
140
139
|
end
|
141
140
|
end
|
142
141
|
```
|
@@ -257,6 +256,31 @@ end
|
|
257
256
|
restricted to as few paths as possible, and using the filter option to further
|
258
257
|
restrict assets to only those likely to be used by `inline_svg`.
|
259
258
|
|
259
|
+
## Missing SVG Files
|
260
|
+
|
261
|
+
If the specified SVG file cannot be found a helpful, empty SVG document is
|
262
|
+
embedded into the page instead. The embedded document contains a single comment
|
263
|
+
displaying the filename of the SVG image the helper tried to render:
|
264
|
+
|
265
|
+
```html
|
266
|
+
<svg><!-- SVG file not found: 'some-missing-file.svg' --></svg>
|
267
|
+
```
|
268
|
+
|
269
|
+
You may apply a class to this empty SVG document by specifying the following
|
270
|
+
configuration:
|
271
|
+
|
272
|
+
```rb
|
273
|
+
InlineSvg.configure do |config|
|
274
|
+
config.svg_not_found_css_class = 'svg-not-found'
|
275
|
+
end
|
276
|
+
```
|
277
|
+
|
278
|
+
Which would instead render:
|
279
|
+
|
280
|
+
```html
|
281
|
+
<svg class='svg-not-found'><!-- SVG file not found: 'some-missing-file.svg' --></svg>
|
282
|
+
```
|
283
|
+
|
260
284
|
## Contributing
|
261
285
|
|
262
286
|
1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) )
|
data/Rakefile
CHANGED
data/lib/inline_svg.rb
CHANGED
@@ -15,11 +15,12 @@ module InlineSvg
|
|
15
15
|
class Configuration
|
16
16
|
class Invalid < ArgumentError; end
|
17
17
|
|
18
|
-
attr_reader :asset_file, :asset_finder, :custom_transformations
|
18
|
+
attr_reader :asset_file, :asset_finder, :custom_transformations, :svg_not_found_css_class
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
@custom_transformations = {}
|
22
22
|
@asset_file = InlineSvg::AssetFile
|
23
|
+
@svg_not_found_css_class = nil
|
23
24
|
end
|
24
25
|
|
25
26
|
def asset_file=(custom_asset_file)
|
@@ -47,6 +48,12 @@ module InlineSvg
|
|
47
48
|
asset_finder
|
48
49
|
end
|
49
50
|
|
51
|
+
def svg_not_found_css_class=(css_class)
|
52
|
+
if css_class.present? && css_class.is_a?(String)
|
53
|
+
@svg_not_found_css_class = css_class
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
50
57
|
def add_custom_transformation(options)
|
51
58
|
if incompatible_transformation?(options.fetch(:transform))
|
52
59
|
raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods")
|
@@ -12,7 +12,11 @@ module InlineSvg
|
|
12
12
|
configured_asset_file.named filename
|
13
13
|
end
|
14
14
|
rescue InlineSvg::AssetFile::FileNotFound
|
15
|
-
|
15
|
+
if InlineSvg.configuration.svg_not_found_css_class.nil?
|
16
|
+
return "<svg><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
|
17
|
+
else
|
18
|
+
return "<svg class='#{InlineSvg.configuration.svg_not_found_css_class}'><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
InlineSvg::TransformPipeline.generate_html_from(svg_file, transform_params).html_safe
|
@@ -1,34 +1,31 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class AriaAttributes < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
# Add role
|
6
|
+
svg["role"] = "img"
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# Build aria-labelledby string
|
9
|
+
aria_elements = []
|
10
|
+
svg.search("title").each do |element|
|
11
|
+
aria_elements << element["id"] = element_id_for("title", element)
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
aria_elements << element['id'] = element_id_for("title", element)
|
14
|
-
end
|
15
|
-
|
16
|
-
doc.search("svg desc").each do |element|
|
17
|
-
aria_elements << element['id'] = element_id_for("desc", element)
|
18
|
-
end
|
14
|
+
svg.search("desc").each do |element|
|
15
|
+
aria_elements << element["id"] = element_id_for("desc", element)
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
if aria_elements.any?
|
19
|
+
svg["aria-labelledby"] = aria_elements.join(" ")
|
20
|
+
end
|
22
21
|
end
|
23
|
-
|
24
|
-
doc
|
25
22
|
end
|
26
23
|
|
27
24
|
def element_id_for(base, element)
|
28
|
-
if element[
|
25
|
+
if element["id"].nil?
|
29
26
|
InlineSvg::IdGenerator.generate(base, element.text)
|
30
27
|
else
|
31
|
-
InlineSvg::IdGenerator.generate(element[
|
28
|
+
InlineSvg::IdGenerator.generate(element["id"], element.text)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class ClassAttribute < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
classes = (svg["class"] || "").split(" ")
|
6
|
+
classes << value
|
7
|
+
svg["class"] = classes.join(" ")
|
8
|
+
end
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class DataAttributes < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
with_valid_hash_from(self.value).each_pair do |name, data|
|
6
|
+
svg["data-#{dasherize(name)}"] = data
|
7
|
+
end
|
8
8
|
end
|
9
|
-
doc
|
10
9
|
end
|
11
10
|
|
12
11
|
private
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class Description < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
node = Nokogiri::XML::Node.new("desc", doc)
|
6
|
+
node.content = value
|
7
|
+
|
8
|
+
svg.search("desc").each { |node| node.remove }
|
9
|
+
svg.prepend_child(node)
|
10
|
+
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class Height < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
svg["height"] = self.value
|
6
|
+
end
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class IdAttribute < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
svg["id"] = self.value
|
6
|
+
end
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -2,11 +2,11 @@ module InlineSvg::TransformPipeline
|
|
2
2
|
module Transformations
|
3
3
|
class NoComment < Transformation
|
4
4
|
def transform(doc)
|
5
|
-
doc
|
6
|
-
|
7
|
-
|
5
|
+
with_svg(doc) do |svg|
|
6
|
+
svg.xpath("//comment()").each do |comment|
|
7
|
+
comment.remove
|
8
|
+
end
|
8
9
|
end
|
9
|
-
doc
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class PreserveAspectRatio < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
svg["preserveAspectRatio"] = self.value
|
6
|
+
end
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class Size < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
svg["width"] = width_of(self.value)
|
6
|
+
svg["height"] = height_of(self.value)
|
7
|
+
end
|
9
8
|
end
|
10
9
|
|
11
10
|
def width_of(value)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class Title < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
node = Nokogiri::XML::Node.new("title", doc)
|
6
|
+
node.content = value
|
7
|
+
|
8
|
+
svg.search("title").each { |node| node.remove }
|
9
|
+
svg.prepend_child(node)
|
10
|
+
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -13,6 +13,17 @@ module InlineSvg::TransformPipeline::Transformations
|
|
13
13
|
def transform(*)
|
14
14
|
raise "#transform should be implemented by subclasses of Transformation"
|
15
15
|
end
|
16
|
+
|
17
|
+
# Parses a document and yields the contained SVG nodeset to the given block
|
18
|
+
# if it exists.
|
19
|
+
#
|
20
|
+
# Returns a Nokogiri::XML::Document.
|
21
|
+
def with_svg(doc)
|
22
|
+
doc = Nokogiri::XML::Document.parse(doc.to_html)
|
23
|
+
svg = doc.at_css "svg"
|
24
|
+
yield svg if svg && block_given?
|
25
|
+
doc
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
29
|
class NullTransformation < Transformation
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
class Width < Transformation
|
3
3
|
def transform(doc)
|
4
|
-
doc
|
5
|
-
|
6
|
-
|
7
|
-
doc
|
4
|
+
with_svg(doc) do |svg|
|
5
|
+
svg["width"] = self.value
|
6
|
+
end
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
data/lib/inline_svg/version.rb
CHANGED
@@ -14,8 +14,12 @@ describe InlineSvg::ActionView::Helpers do
|
|
14
14
|
let(:helper) { ( Class.new { include InlineSvg::ActionView::Helpers } ).new }
|
15
15
|
|
16
16
|
describe "#inline_svg" do
|
17
|
-
|
17
|
+
|
18
18
|
context "when passed the name of an SVG that does not exist" do
|
19
|
+
after(:each) do
|
20
|
+
InlineSvg.reset_configuration!
|
21
|
+
end
|
22
|
+
|
19
23
|
it "returns an empty, html safe, SVG document as a placeholder" do
|
20
24
|
allow(InlineSvg::AssetFile).to receive(:named).
|
21
25
|
with('some-missing-file.svg').
|
@@ -34,6 +38,20 @@ describe InlineSvg::ActionView::Helpers do
|
|
34
38
|
output = helper.inline_svg('missing-file-with-no-extension')
|
35
39
|
expect(output).to eq "<svg><!-- SVG file not found: 'missing-file-with-no-extension' (Try adding .svg to your filename) --></svg>"
|
36
40
|
end
|
41
|
+
|
42
|
+
it "allows the CSS class on the empty SVG document to be changed" do
|
43
|
+
InlineSvg.configure do |config|
|
44
|
+
config.svg_not_found_css_class = 'missing-svg'
|
45
|
+
end
|
46
|
+
|
47
|
+
allow(InlineSvg::AssetFile).to receive(:named).
|
48
|
+
with('some-other-missing-file.svg').
|
49
|
+
and_raise(InlineSvg::AssetFile::FileNotFound.new)
|
50
|
+
|
51
|
+
output = helper.inline_svg('some-other-missing-file.svg')
|
52
|
+
expect(output).to eq "<svg class='missing-svg'><!-- SVG file not found: 'some-other-missing-file.svg' --></svg>"
|
53
|
+
expect(output).to be_html_safe
|
54
|
+
end
|
37
55
|
end
|
38
56
|
|
39
57
|
context "when passed an existing SVG file" do
|
data/spec/inline_svg_spec.rb
CHANGED
@@ -80,6 +80,16 @@ describe InlineSvg do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
context "configuring the default svg-not-found class" do
|
84
|
+
it "sets the class name" do
|
85
|
+
InlineSvg.configure do |config|
|
86
|
+
config.svg_not_found_css_class = 'missing-svg'
|
87
|
+
end
|
88
|
+
|
89
|
+
expect(InlineSvg.configuration.svg_not_found_css_class).to eq 'missing-svg'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
83
93
|
context "configuring custom transformation" do
|
84
94
|
it "allows a custom transformation to be added" do
|
85
95
|
InlineSvg.configure do |config|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "inline_svg/transform_pipeline"
|
2
2
|
|
3
3
|
describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
4
4
|
it "adds a role attribute to the SVG document" do
|
5
|
-
document = Nokogiri::XML::Document.parse(
|
5
|
+
document = Nokogiri::XML::Document.parse("<svg>Some document</svg>")
|
6
6
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
|
7
7
|
|
8
8
|
expect(transformation.transform(document).to_html).to eq(
|
@@ -12,7 +12,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
12
12
|
|
13
13
|
context "aria-labelledby attribute" do
|
14
14
|
it "adds 'title' when a title element is present" do
|
15
|
-
document = Nokogiri::XML::Document.parse(
|
15
|
+
document = Nokogiri::XML::Document.parse("<svg><title>Some title</title>Some document</svg>")
|
16
16
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true)
|
17
17
|
|
18
18
|
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title").
|
@@ -24,7 +24,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "adds 'desc' when a description element is present" do
|
27
|
-
document = Nokogiri::XML::Document.parse(
|
27
|
+
document = Nokogiri::XML::Document.parse("<svg><desc>Some description</desc>Some document</svg>")
|
28
28
|
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true)
|
29
29
|
|
30
30
|
expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "Some description").
|
@@ -36,7 +36,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "adds both 'desc' and 'title' when title and description elements are present" do
|
39
|
-
document = Nokogiri::XML::Document.parse(
|
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(true)
|
41
41
|
|
42
42
|
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title").
|
@@ -50,7 +50,7 @@ describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "uses existing IDs when they exist" do
|
53
|
-
document = Nokogiri::XML::Document.parse(
|
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(true)
|
55
55
|
|
56
56
|
expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "Some title").
|
@@ -9,4 +9,13 @@ describe InlineSvg::TransformPipeline::Transformations::Height do
|
|
9
9
|
"<svg height=\"5%\">Some document</svg>\n"
|
10
10
|
)
|
11
11
|
end
|
12
|
+
|
13
|
+
it "handles documents without SVG root elements" do
|
14
|
+
document = Nokogiri::XML::Document.parse("<foo>bar</foo><svg>Some document</svg>")
|
15
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Height.create_with_value("5%")
|
16
|
+
|
17
|
+
expect(transformation.transform(document).to_html).to eq(
|
18
|
+
"<foo>bar</foo>\n"
|
19
|
+
)
|
20
|
+
end
|
12
21
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'inline_svg'
|
2
|
+
require 'inline_svg/transform_pipeline'
|
3
|
+
|
4
|
+
describe InlineSvg::TransformPipeline::Transformations::Transformation do
|
5
|
+
context "#with_svg" do
|
6
|
+
it "returns a Nokogiri::XML::Document representing the parsed document fragment" do
|
7
|
+
document = Nokogiri::XML::Document.parse("<svg>Some document</svg>")
|
8
|
+
|
9
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)
|
10
|
+
expect(transformation.with_svg(document).to_html).to eq(
|
11
|
+
"<svg>Some document</svg>\n"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "yields to the block when the document contains an SVG element" do
|
16
|
+
document = Nokogiri::XML::Document.parse("<svg>Some document</svg>")
|
17
|
+
svg = document.at_css("svg")
|
18
|
+
|
19
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)
|
20
|
+
|
21
|
+
returned_document = nil
|
22
|
+
expect do |b|
|
23
|
+
returned_document = transformation.with_svg(document, &b)
|
24
|
+
end.to yield_control
|
25
|
+
|
26
|
+
expect(returned_document.to_s).to match(/<svg>Some document<\/svg>/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not yield if the document does not contain an SVG element at the root" do
|
30
|
+
document = Nokogiri::XML::Document.parse("<foo>bar</foo><svg>Some document</svg>")
|
31
|
+
|
32
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)
|
33
|
+
|
34
|
+
expect do |b|
|
35
|
+
transformation.with_svg(document, &b)
|
36
|
+
end.not_to yield_control
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- spec/transformation_pipeline/transformations/preserve_aspect_ratio_spec.rb
|
171
171
|
- spec/transformation_pipeline/transformations/size_spec.rb
|
172
172
|
- spec/transformation_pipeline/transformations/title_spec.rb
|
173
|
+
- spec/transformation_pipeline/transformations/transformation_spec.rb
|
173
174
|
- spec/transformation_pipeline/transformations/width_spec.rb
|
174
175
|
- spec/transformation_pipeline/transformations_spec.rb
|
175
176
|
homepage: https://github.com/jamesmartin/inline_svg
|
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
193
|
version: '0'
|
193
194
|
requirements: []
|
194
195
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.
|
196
|
+
rubygems_version: 2.6.11
|
196
197
|
signing_key:
|
197
198
|
specification_version: 4
|
198
199
|
summary: Embeds an SVG document, inline.
|
@@ -220,5 +221,6 @@ test_files:
|
|
220
221
|
- spec/transformation_pipeline/transformations/preserve_aspect_ratio_spec.rb
|
221
222
|
- spec/transformation_pipeline/transformations/size_spec.rb
|
222
223
|
- spec/transformation_pipeline/transformations/title_spec.rb
|
224
|
+
- spec/transformation_pipeline/transformations/transformation_spec.rb
|
223
225
|
- spec/transformation_pipeline/transformations/width_spec.rb
|
224
226
|
- spec/transformation_pipeline/transformations_spec.rb
|