inline_svg 0.7.0 → 0.8.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 +4 -4
- data/CHANGELOG.md +10 -3
- data/README.md +28 -0
- data/lib/inline_svg.rb +1 -4
- data/lib/inline_svg/transform_pipeline/transformations.rb +26 -13
- data/lib/inline_svg/version.rb +1 -1
- data/spec/helpers/inline_svg_spec.rb +32 -0
- data/spec/inline_svg_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9be73c7539f050fff8b70b78686af612b47bce30
|
4
|
+
data.tar.gz: 03a319e6d961e16550a4fb20f7427586a4374850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d991a3f66c45f6b889f6533d093f3e20021ce97197adf61a174e653f6c26cebaa70013887650df56d9740e812eb460572d2c0656589db18cf4eccc6e5da11420
|
7
|
+
data.tar.gz: 4f99e93a2951dc4b3cb7424442aafa8858312076a3d45d39e60fd67116a2219829db8e3f57378172a8a563bb8774960ef6523a63e652146631528030cdd91cb1
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,13 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
5
|
## [Unreleased][unreleased]
|
6
|
-
- Nothing
|
6
|
+
- Nothing
|
7
|
+
|
8
|
+
## [0.8.0] - 2016-05-23
|
9
|
+
### Added
|
10
|
+
- Default values for custom transformations
|
11
|
+
[#36](https://github.com/jamesmartin/inline_svg/issues/36). Thanks,
|
12
|
+
[@andrewaguiar](https://github.com/andrewaguiar)
|
7
13
|
|
8
14
|
## [0.7.0] - 2016-05-03
|
9
15
|
### Added
|
@@ -85,8 +91,9 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
85
91
|
### Added
|
86
92
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
87
93
|
|
88
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.
|
89
|
-
[0.
|
94
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.8.0...HEAD
|
95
|
+
[0.8.0]: https://github.com/jamesmartin/inline_svg/compare/v0.7.0...v0.8.0
|
96
|
+
[0.7.0]: https://github.com/jamesmartin/inline_svg/compare/v0.6.4...v0.7.0
|
90
97
|
[0.6.4]: https://github.com/jamesmartin/inline_svg/compare/v0.6.3...v0.6.4
|
91
98
|
[0.6.3]: https://github.com/jamesmartin/inline_svg/compare/v0.6.2...v0.6.3
|
92
99
|
[0.6.2]: https://github.com/jamesmartin/inline_svg/compare/v0.6.1...v0.6.2
|
data/README.md
CHANGED
@@ -131,6 +131,34 @@ In this example, the following transformation would be applied to a SVG document
|
|
131
131
|
<svg custom="some value">...</svg>
|
132
132
|
```
|
133
133
|
|
134
|
+
You can also provide a default_value to the custom transformation, so even if you don't pass a value it will be triggered
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# Note that the named `attribute` will be used to pass a value to your custom transform
|
138
|
+
InlineSvg.configure do |config|
|
139
|
+
config.add_custom_transformation(attribute: :my_custom_attribute, transform: MyCustomTransform, default_value: 'default value')
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
The custom transformation will be triggered even if you don't pass any attribute value
|
144
|
+
```haml
|
145
|
+
%div
|
146
|
+
= inline_svg "some-document.svg"
|
147
|
+
= inline_svg "some-document.svg", my_custom_attribute: 'some value'
|
148
|
+
```
|
149
|
+
|
150
|
+
In this example, the following transformation would be applied to a SVG document:
|
151
|
+
|
152
|
+
```xml
|
153
|
+
<svg custom="default value">...</svg>
|
154
|
+
```
|
155
|
+
|
156
|
+
And
|
157
|
+
|
158
|
+
```xml
|
159
|
+
<svg custom="some value">...</svg>
|
160
|
+
```
|
161
|
+
|
134
162
|
## Contributing
|
135
163
|
|
136
164
|
1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) )
|
data/lib/inline_svg.rb
CHANGED
@@ -36,7 +36,7 @@ module InlineSvg
|
|
36
36
|
if incompatible_transformation?(options.fetch(:transform))
|
37
37
|
raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods")
|
38
38
|
end
|
39
|
-
@custom_transformations.merge!(Hash[ *[options.fetch(:attribute, :no_attribute), options
|
39
|
+
@custom_transformations.merge!(Hash[ *[options.fetch(:attribute, :no_attribute), options] ])
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -45,9 +45,6 @@ module InlineSvg
|
|
45
45
|
!klass.is_a?(Class) || !klass.respond_to?(:create_with_value) || !klass.instance_methods.include?(:transform)
|
46
46
|
end
|
47
47
|
|
48
|
-
def no_transform
|
49
|
-
InlineSvg::TransformPipeline::Transformations::NullTransformation
|
50
|
-
end
|
51
48
|
end
|
52
49
|
|
53
50
|
@configuration = InlineSvg::Configuration.new
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module InlineSvg::TransformPipeline::Transformations
|
2
2
|
def self.built_in_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
|
-
preserve_aspect_ratio: PreserveAspectRatio,
|
14
|
-
aria: AriaAttributes
|
4
|
+
nocomment: { transform: NoComment },
|
5
|
+
class: { transform: ClassAttribute },
|
6
|
+
title: { transform: Title },
|
7
|
+
desc: { transform: Description },
|
8
|
+
size: { transform: Size },
|
9
|
+
height: { transform: Height },
|
10
|
+
width: { transform: Width },
|
11
|
+
id: { transform: IdAttribute },
|
12
|
+
data: { transform: DataAttributes },
|
13
|
+
preserve_aspect_ratio: { transform: PreserveAspectRatio },
|
14
|
+
aria: { transform: AriaAttributes }
|
15
15
|
}
|
16
16
|
end
|
17
17
|
|
@@ -24,14 +24,27 @@ module InlineSvg::TransformPipeline::Transformations
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.lookup(transform_params)
|
27
|
-
without_empty_values(transform_params).map do |key, value|
|
28
|
-
all_transformations.fetch(key, NullTransformation)
|
27
|
+
all_default_values.merge(without_empty_values(transform_params)).map do |key, value|
|
28
|
+
options = all_transformations.fetch(key, { transform: NullTransformation })
|
29
|
+
options.fetch(:transform, no_transform).create_with_value(value)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.without_empty_values(params)
|
33
34
|
params.reject {|key, value| value.nil?}
|
34
35
|
end
|
36
|
+
|
37
|
+
def self.all_default_values
|
38
|
+
custom_transformations
|
39
|
+
.values
|
40
|
+
.select {|opt| opt[:default_value] != nil}
|
41
|
+
.map {|opt| [opt[:attribute], opt[:default_value]]}
|
42
|
+
.inject({}) {|hash, array| hash.merge!(array[0] => array[1])}
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.no_transform
|
46
|
+
InlineSvg::TransformPipeline::Transformations::NullTransformation
|
47
|
+
end
|
35
48
|
end
|
36
49
|
|
37
50
|
require 'inline_svg/transform_pipeline/transformations/transformation'
|
data/lib/inline_svg/version.rb
CHANGED
@@ -112,6 +112,38 @@ SVG
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
context "with custom transformations using a default value" do
|
116
|
+
before(:each) do
|
117
|
+
InlineSvg.configure do |config|
|
118
|
+
config.add_custom_transformation({attribute: :custom, transform: WorkingCustomTransform, default_value: 'default value'})
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
after(:each) do
|
123
|
+
InlineSvg.reset_configuration!
|
124
|
+
end
|
125
|
+
|
126
|
+
context "without passing the attribute value" do
|
127
|
+
it "applies custom transformations to the output using the default value" do
|
128
|
+
input_svg = '<svg></svg>'
|
129
|
+
|
130
|
+
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
131
|
+
|
132
|
+
expect(helper.inline_svg('some-file')).to eq "<svg custom=\"default value\"></svg>\n"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "passing the attribute value" do
|
137
|
+
it "applies custom transformations to the output" do
|
138
|
+
input_svg = '<svg></svg>'
|
139
|
+
|
140
|
+
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
|
141
|
+
|
142
|
+
expect(helper.inline_svg('some-file', custom: 'some value')).to eq "<svg custom=\"some value\"></svg>\n"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
115
147
|
end
|
116
148
|
context 'argument polimorphizm' do
|
117
149
|
let(:argument) { double('argument') }
|
data/spec/inline_svg_spec.rb
CHANGED
@@ -48,7 +48,7 @@ describe InlineSvg do
|
|
48
48
|
config.add_custom_transformation(attribute: :my_transform, transform: MyCustomTransform)
|
49
49
|
end
|
50
50
|
|
51
|
-
expect(InlineSvg.configuration.custom_transformations).to eq({my_transform: MyCustomTransform})
|
51
|
+
expect(InlineSvg.configuration.custom_transformations).to eq({my_transform: {attribute: :my_transform, transform: MyCustomTransform}})
|
52
52
|
end
|
53
53
|
|
54
54
|
it "rejects transformations that do not implement .create_with_value" do
|
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.8.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-05-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|