inline_svg 0.4.0 → 0.5.0
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 +6 -2
- data/lib/inline_svg/transform_pipeline/transformations/data_attributes.rb +16 -0
- data/lib/inline_svg/transform_pipeline/transformations/height.rb +10 -0
- data/lib/inline_svg/transform_pipeline/transformations/id_attribute.rb +10 -0
- data/lib/inline_svg/transform_pipeline/transformations/width.rb +10 -0
- data/lib/inline_svg/transform_pipeline/transformations.rb +15 -1
- data/lib/inline_svg/version.rb +1 -1
- data/spec/transformation_pipeline/transformations/data_attributes_spec.rb +36 -0
- data/spec/transformation_pipeline/transformations/height_spec.rb +12 -0
- data/spec/transformation_pipeline/transformations/id_attribute_spec.rb +12 -0
- data/spec/transformation_pipeline/transformations/width_spec.rb +12 -0
- data/spec/transformation_pipeline/transformations_spec.rb +10 -2
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eda36369f830ee60216241e8152c2a92be18f4f
|
4
|
+
data.tar.gz: 4a2c84a1379d7341aa74623b132b5d36ee68ea90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c9c902e2ae6574cab4ab8a3bf69edb5a69232c190112ae645f9a1f402edf5bcb434c2b149620af12290dd1bcdb285c259d815c3220a92f0b2b8c7e753a163a7
|
7
|
+
data.tar.gz: a593f1d06649736a8772efd8b38f51ce476be53b62f252dbe45a1ccf35e46a0266fd3d693bd0b8b45284218697cc84a779562c00a3b1355ba1fb6151f4183652
|
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
|
+
## [0.5.0] - 2015-03-29
|
9
|
+
### Added
|
10
|
+
- A new option: `id` adds an id attribute to the SVG.
|
11
|
+
- A new option: `data` adds data attributes to the SVG.
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- New options: `height` and `width` override `size` and can be set independently.
|
15
|
+
|
8
16
|
## [0.4.0] - 2015-03-22
|
9
17
|
### Added
|
10
18
|
- A new option: `size` adds width and height attributes to an SVG. Thanks, @2metres.
|
@@ -33,7 +41,8 @@ Nothing.
|
|
33
41
|
### Added
|
34
42
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
35
43
|
|
36
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.
|
44
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.5.0...HEAD
|
45
|
+
[0.5.0]: https://github.com/jamesmartin/inline_svg/compare/v0.4.0...v0.5.0
|
37
46
|
[0.4.0]: https://github.com/jamesmartin/inline_svg/compare/v0.3.0...v0.4.0
|
38
47
|
[0.3.0]: https://github.com/jamesmartin/inline_svg/compare/v0.2.0...v0.3.0
|
39
48
|
[0.2.0]: https://github.com/jamesmartin/inline_svg/compare/v0.1.0...v0.2.0
|
data/README.md
CHANGED
@@ -65,8 +65,12 @@ blue:
|
|
65
65
|
```
|
66
66
|
|
67
67
|
## Options
|
68
|
+
* `id`: set a ID attribute on the SVG
|
68
69
|
* `class`: set a CSS class attribute on the SVG
|
70
|
+
* `data`: add data attributes to the SVG (supply as a hash)
|
69
71
|
* `size`: set width and height attributes on the SVG
|
72
|
+
* Can also be set using `height` and/or `width` attributes, which take
|
73
|
+
precedence over `size`
|
70
74
|
* Supplied as "{Width} * {Height}" or "{Number}", so "30px*45px" becomes `width="30px"`
|
71
75
|
and `height="45px"`, and "50%" becomes `width="50%"` and `height="50%"`
|
72
76
|
* `title`: add a \<title\> node inside the top level of the SVG document
|
@@ -77,8 +81,8 @@ blue:
|
|
77
81
|
Example:
|
78
82
|
|
79
83
|
```
|
80
|
-
inline_svg("some-document.svg", class: 'some-class', size: '30% * 20%', title: 'Some Title', desc:
|
81
|
-
'Some
|
84
|
+
inline_svg("some-document.svg", id: 'some-id', class: 'some-class', data: {some: "value"}, size: '30% * 20%', title: 'Some Title', desc:
|
85
|
+
'Some description', nocomment: true)
|
82
86
|
```
|
83
87
|
|
84
88
|
## Contributing
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module InlineSvg::TransformPipeline::Transformations
|
2
|
+
class DataAttributes < Transformation
|
3
|
+
def transform(doc)
|
4
|
+
doc = Nokogiri::XML::Document.parse(doc.to_html)
|
5
|
+
svg = doc.at_css 'svg'
|
6
|
+
with_valid_hash_from(self.value).each_pair do |name, data|
|
7
|
+
svg["data-#{name}"] = data
|
8
|
+
end
|
9
|
+
doc
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_valid_hash_from(hash)
|
13
|
+
Hash.try_convert(hash) || {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,6 +1,16 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
def self.all_transformations
|
3
|
-
{
|
3
|
+
{
|
4
|
+
nocomment: NoComment,
|
5
|
+
class: ClassAttribute,
|
6
|
+
title: Title,
|
7
|
+
desc: Description,
|
8
|
+
size: Size,
|
9
|
+
height: Height,
|
10
|
+
width: Width,
|
11
|
+
id: IdAttribute,
|
12
|
+
data: DataAttributes
|
13
|
+
}
|
4
14
|
end
|
5
15
|
|
6
16
|
def self.lookup(transform_params)
|
@@ -20,3 +30,7 @@ require 'inline_svg/transform_pipeline/transformations/class_attribute'
|
|
20
30
|
require 'inline_svg/transform_pipeline/transformations/title'
|
21
31
|
require 'inline_svg/transform_pipeline/transformations/description'
|
22
32
|
require 'inline_svg/transform_pipeline/transformations/size'
|
33
|
+
require 'inline_svg/transform_pipeline/transformations/height'
|
34
|
+
require 'inline_svg/transform_pipeline/transformations/width'
|
35
|
+
require 'inline_svg/transform_pipeline/transformations/id_attribute'
|
36
|
+
require 'inline_svg/transform_pipeline/transformations/data_attributes'
|
data/lib/inline_svg/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'inline_svg/transform_pipeline'
|
2
|
+
|
3
|
+
describe InlineSvg::TransformPipeline::Transformations::DataAttributes do
|
4
|
+
it "adds a data attribute to a SVG document" do
|
5
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
6
|
+
transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes.create_with_value({some: "value"})
|
7
|
+
|
8
|
+
expect(transformation.transform(document).to_html).to eq(
|
9
|
+
"<svg data-some=\"value\">Some document</svg>\n"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when multiple data attributes are supplied" do
|
14
|
+
it "adds data attributes to the SVG for each supplied value" do
|
15
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
16
|
+
transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes.
|
17
|
+
create_with_value({some: "value", other: "thing"})
|
18
|
+
|
19
|
+
expect(transformation.transform(document).to_html).to eq(
|
20
|
+
"<svg data-some=\"value\" data-other=\"thing\">Some document</svg>\n"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when a non-hash is supplied" do
|
26
|
+
it "does not update the SVG document" do
|
27
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
28
|
+
transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes.
|
29
|
+
create_with_value("some non-hash")
|
30
|
+
|
31
|
+
expect(transformation.transform(document).to_html).to eq(
|
32
|
+
"<svg>Some document</svg>\n"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'inline_svg/transform_pipeline'
|
2
|
+
|
3
|
+
describe InlineSvg::TransformPipeline::Transformations::Height do
|
4
|
+
it "adds height attribute to a SVG document" do
|
5
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
6
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Height.create_with_value("5%")
|
7
|
+
|
8
|
+
expect(transformation.transform(document).to_html).to eq(
|
9
|
+
"<svg height=\"5%\">Some document</svg>\n"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'inline_svg/transform_pipeline'
|
2
|
+
|
3
|
+
describe InlineSvg::TransformPipeline::Transformations::IdAttribute do
|
4
|
+
it "adds an id attribute to a SVG document" do
|
5
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
6
|
+
transformation = InlineSvg::TransformPipeline::Transformations::IdAttribute.create_with_value("some-id")
|
7
|
+
|
8
|
+
expect(transformation.transform(document).to_html).to eq(
|
9
|
+
"<svg id=\"some-id\">Some document</svg>\n"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'inline_svg/transform_pipeline'
|
2
|
+
|
3
|
+
describe InlineSvg::TransformPipeline::Transformations::Width do
|
4
|
+
it "adds width attribute to a SVG document" do
|
5
|
+
document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
|
6
|
+
transformation = InlineSvg::TransformPipeline::Transformations::Width.create_with_value("5%")
|
7
|
+
|
8
|
+
expect(transformation.transform(document).to_html).to eq(
|
9
|
+
"<svg width=\"5%\">Some document</svg>\n"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
@@ -8,7 +8,11 @@ describe InlineSvg::TransformPipeline::Transformations do
|
|
8
8
|
class: 'irrelevant',
|
9
9
|
title: 'irrelevant',
|
10
10
|
desc: 'irrelevant',
|
11
|
-
size: 'irrelevant'
|
11
|
+
size: 'irrelevant',
|
12
|
+
height: 'irrelevant',
|
13
|
+
width: 'irrelevant',
|
14
|
+
id: 'irrelevant',
|
15
|
+
data: 'irrelevant'
|
12
16
|
)
|
13
17
|
|
14
18
|
expect(transformations.map(&:class)).to match_array([
|
@@ -16,7 +20,11 @@ describe InlineSvg::TransformPipeline::Transformations do
|
|
16
20
|
InlineSvg::TransformPipeline::Transformations::ClassAttribute,
|
17
21
|
InlineSvg::TransformPipeline::Transformations::Title,
|
18
22
|
InlineSvg::TransformPipeline::Transformations::Description,
|
19
|
-
InlineSvg::TransformPipeline::Transformations::Size
|
23
|
+
InlineSvg::TransformPipeline::Transformations::Size,
|
24
|
+
InlineSvg::TransformPipeline::Transformations::Height,
|
25
|
+
InlineSvg::TransformPipeline::Transformations::Width,
|
26
|
+
InlineSvg::TransformPipeline::Transformations::IdAttribute,
|
27
|
+
InlineSvg::TransformPipeline::Transformations::DataAttributes
|
20
28
|
])
|
21
29
|
end
|
22
30
|
|
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.
|
4
|
+
version: 0.5.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: 2015-03-
|
11
|
+
date: 2015-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,18 +116,26 @@ files:
|
|
116
116
|
- lib/inline_svg/transform_pipeline.rb
|
117
117
|
- lib/inline_svg/transform_pipeline/transformations.rb
|
118
118
|
- lib/inline_svg/transform_pipeline/transformations/class_attribute.rb
|
119
|
+
- lib/inline_svg/transform_pipeline/transformations/data_attributes.rb
|
119
120
|
- lib/inline_svg/transform_pipeline/transformations/description.rb
|
121
|
+
- lib/inline_svg/transform_pipeline/transformations/height.rb
|
122
|
+
- lib/inline_svg/transform_pipeline/transformations/id_attribute.rb
|
120
123
|
- lib/inline_svg/transform_pipeline/transformations/no_comment.rb
|
121
124
|
- lib/inline_svg/transform_pipeline/transformations/size.rb
|
122
125
|
- lib/inline_svg/transform_pipeline/transformations/title.rb
|
123
126
|
- lib/inline_svg/transform_pipeline/transformations/transformation.rb
|
127
|
+
- lib/inline_svg/transform_pipeline/transformations/width.rb
|
124
128
|
- lib/inline_svg/version.rb
|
125
129
|
- spec/asset_file_spec.rb
|
126
130
|
- spec/files/example.svg
|
127
131
|
- spec/finds_asset_paths_spec.rb
|
128
132
|
- spec/helpers/inline_svg_spec.rb
|
129
133
|
- spec/inline_svg_spec.rb
|
134
|
+
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
135
|
+
- spec/transformation_pipeline/transformations/height_spec.rb
|
136
|
+
- spec/transformation_pipeline/transformations/id_attribute_spec.rb
|
130
137
|
- spec/transformation_pipeline/transformations/size_spec.rb
|
138
|
+
- spec/transformation_pipeline/transformations/width_spec.rb
|
131
139
|
- spec/transformation_pipeline/transformations_spec.rb
|
132
140
|
homepage: ''
|
133
141
|
licenses:
|
@@ -159,5 +167,9 @@ test_files:
|
|
159
167
|
- spec/finds_asset_paths_spec.rb
|
160
168
|
- spec/helpers/inline_svg_spec.rb
|
161
169
|
- spec/inline_svg_spec.rb
|
170
|
+
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
171
|
+
- spec/transformation_pipeline/transformations/height_spec.rb
|
172
|
+
- spec/transformation_pipeline/transformations/id_attribute_spec.rb
|
162
173
|
- spec/transformation_pipeline/transformations/size_spec.rb
|
174
|
+
- spec/transformation_pipeline/transformations/width_spec.rb
|
163
175
|
- spec/transformation_pipeline/transformations_spec.rb
|