dragonfly_svg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE +21 -0
- data/README.md +103 -0
- data/Rakefile +9 -0
- data/dragonfly_svg.gemspec +29 -0
- data/lib/dragonfly_svg.rb +7 -0
- data/lib/dragonfly_svg/analysers/svg_properties.rb +26 -0
- data/lib/dragonfly_svg/plugin.rb +50 -0
- data/lib/dragonfly_svg/processors/extend_ids.rb +27 -0
- data/lib/dragonfly_svg/processors/remove_namespaces.rb +16 -0
- data/lib/dragonfly_svg/processors/set_dimensions.rb +20 -0
- data/lib/dragonfly_svg/processors/set_namespace.rb +22 -0
- data/lib/dragonfly_svg/processors/set_preserve_aspect_ratio.rb +19 -0
- data/lib/dragonfly_svg/processors/set_view_box.rb +21 -0
- data/lib/dragonfly_svg/version.rb +3 -0
- data/samples/sample.svg +4 -0
- data/test/dragonfly_svg/analysers/svg_properties_test.rb +34 -0
- data/test/dragonfly_svg/plugin_test.rb +62 -0
- data/test/dragonfly_svg/processors/extend_ids_test.rb +28 -0
- data/test/dragonfly_svg/processors/remove_namespaces_test.rb +18 -0
- data/test/dragonfly_svg/processors/set_dimensions_test.rb +26 -0
- data/test/dragonfly_svg/processors/set_namespace_test.rb +23 -0
- data/test/dragonfly_svg/processors/set_preserve_aspect_ratio_test.rb +32 -0
- data/test/dragonfly_svg/processors/set_view_box_test.rb +21 -0
- data/test/test_helper.rb +21 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 754145800a50f897cbdabb6c51531f83833a98ed
|
4
|
+
data.tar.gz: 80400fe7189ba5608c5b73ff79ebe510ec8b1ae2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2660e6fb120ff18fb68068b4f6447efdb18013c3db5466ae8c6b582ee8e08b1a72ad7a448eb995de0148a44fc4ab4c5dc40cb9ccdc2b87df4f65c8c05602c33
|
7
|
+
data.tar.gz: 86dd6e99b529254c743c065475810380e5cbddc76607f0efd8a5a11e48a24d7d16348e9465173284137689ebe33ee7316d7ae87c547425dd925a5d2e70f1e92a
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tomas Celizna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# Dragonfly SVG
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/dragonfly_svg.svg)](https://travis-ci.org/tomasc/dragonfly_svg) [![Gem Version](https://badge.fury.io/rb/dragonfly_svg.svg)](http://badge.fury.io/rb/dragonfly_svg) [![Coverage Status](https://img.shields.io/coveralls/tomasc/dragonfly_svg.svg)](https://coveralls.io/r/tomasc/dragonfly_svg)
|
4
|
+
|
5
|
+
[Dragonfly](https://github.com/markevans/dragonfly) analyser and processors for SVGs.
|
6
|
+
|
7
|
+
Uses the [nokogiri](http://nokogiri.org) gem for SVG parsing.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'dragonfly_svg'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dragonfly_svg
|
22
|
+
|
23
|
+
## Plugin
|
24
|
+
The analyser and processors are added by configuring the plugin
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Dragonfly.app.configure do
|
28
|
+
plugin :svg
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Analyser
|
33
|
+
The analyser supplies the following methods:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
svg.width
|
37
|
+
svg.height
|
38
|
+
svg.aspect_ratio
|
39
|
+
svg.id
|
40
|
+
svg.portrait?
|
41
|
+
svg.landscape?
|
42
|
+
```
|
43
|
+
|
44
|
+
## Processors
|
45
|
+
|
46
|
+
### ExtendIds
|
47
|
+
|
48
|
+
Adds a random string to the `id`. Helpful when embedding SVGs, in which case the `id` should be unique. You can also supply your own String.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
svg.extend_ids
|
52
|
+
svg.extend_ids('foo')
|
53
|
+
```
|
54
|
+
|
55
|
+
### RemoveNamespaces
|
56
|
+
|
57
|
+
Removes the `xmlns` namespace from the SVG.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
svg.remove_namespaces
|
61
|
+
```
|
62
|
+
|
63
|
+
### SetDimensions
|
64
|
+
|
65
|
+
Sets the dimensions of the SVG. Takes two parameters: `width` and `height`
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
svg.set_dimensions(210, 297)
|
69
|
+
```
|
70
|
+
|
71
|
+
### SetNamespace
|
72
|
+
|
73
|
+
Sets the `xmlns` namespace of the SVG. Default is `http://www.w3.org/2000/svg` unless something is supplied.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
svg.set_namespace # xmlns="http://www.w3.org/2000/svg"
|
77
|
+
svg.set_namespace('foo') # xmlns="foo"
|
78
|
+
```
|
79
|
+
|
80
|
+
### SetPreserveAspectRatio
|
81
|
+
|
82
|
+
Sets the `preserveAspectRatio` attribute of the SVG. Default is `xMinYMin meet` unless something is supplied.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
svg.set_preserve_aspect_ratio # preserveAspectRatio="xMinYMin meet"
|
86
|
+
svg.set_preserve_aspect_ratio('foo') # preserveAspectRatio="foo"
|
87
|
+
```
|
88
|
+
|
89
|
+
### SetViewBox
|
90
|
+
|
91
|
+
Sets the `viewBox` attribute of the SVG. Takes four parameters: `min_x`, `min_y`, `width` and `height`.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
svg.set_viewbox(0, 0, 400, 600) # viewBox="0 0 400 600"
|
95
|
+
```
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
1. Fork it ( https://github.com/tomasc/dragonfly_svg/fork )
|
100
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
101
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
102
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dragonfly_svg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dragonfly_svg"
|
8
|
+
spec.version = DragonflySvg::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.summary = %q{Dragonfly analyser and processor for SVGs.}
|
12
|
+
spec.description = %q{Dragonfly analyser and processor for SVGs.}
|
13
|
+
spec.homepage = "https://github.com/tomasc/dragonfly_svg"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "dragonfly", "~> 1.0"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.2.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-minitest"
|
28
|
+
spec.add_development_dependency "minitest"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Analysers
|
5
|
+
class SvgProperties
|
6
|
+
|
7
|
+
def call content
|
8
|
+
node = svg_node(content)
|
9
|
+
|
10
|
+
{
|
11
|
+
width: node.get_attribute('width').to_f,
|
12
|
+
height: node.get_attribute('height').to_f,
|
13
|
+
id: node.get_attribute('id'),
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
private # =============================================================
|
18
|
+
|
19
|
+
def svg_node content
|
20
|
+
return unless doc = Nokogiri::XML(content.data)
|
21
|
+
doc.xpath("//*[name()='svg']").first
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'dragonfly_svg/analysers/svg_properties'
|
2
|
+
require 'dragonfly_svg/processors/extend_ids'
|
3
|
+
require 'dragonfly_svg/processors/remove_namespaces'
|
4
|
+
require 'dragonfly_svg/processors/set_dimensions'
|
5
|
+
require 'dragonfly_svg/processors/set_namespace'
|
6
|
+
require 'dragonfly_svg/processors/set_preserve_aspect_ratio'
|
7
|
+
require 'dragonfly_svg/processors/set_view_box'
|
8
|
+
|
9
|
+
module DragonflySvg
|
10
|
+
class Plugin
|
11
|
+
|
12
|
+
def call app, opts={}
|
13
|
+
app.add_analyser :svg_properties, DragonflySvg::Analysers::SvgProperties.new
|
14
|
+
app.add_analyser :width do |content|
|
15
|
+
content.analyse(:svg_properties)[:width]
|
16
|
+
end
|
17
|
+
app.add_analyser :height do |content|
|
18
|
+
content.analyse(:svg_properties)[:height]
|
19
|
+
end
|
20
|
+
app.add_analyser :aspect_ratio do |content|
|
21
|
+
attrs = content.analyse(:svg_properties)
|
22
|
+
attrs[:width].to_f / attrs[:height].to_f
|
23
|
+
end
|
24
|
+
app.add_analyser :portrait do |content|
|
25
|
+
attrs = content.analyse(:svg_properties)
|
26
|
+
attrs[:width] <= attrs[:height]
|
27
|
+
end
|
28
|
+
app.add_analyser :landscape do |content|
|
29
|
+
!content.analyse(:portrait)
|
30
|
+
end
|
31
|
+
app.add_analyser :id do |content|
|
32
|
+
content.analyse(:svg_properties)[:id]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Aliases
|
36
|
+
app.define(:portrait?) { portrait }
|
37
|
+
app.define(:landscape?) { landscape }
|
38
|
+
|
39
|
+
app.add_processor :extend_ids, DragonflySvg::Processors::ExtendIds.new
|
40
|
+
app.add_processor :remove_namespaces, DragonflySvg::Processors::RemoveNamespaces.new
|
41
|
+
app.add_processor :set_dimensions, DragonflySvg::Processors::SetDimensions.new
|
42
|
+
app.add_processor :set_namespace, DragonflySvg::Processors::SetNamespace.new
|
43
|
+
app.add_processor :set_preserve_aspect_ratio, DragonflySvg::Processors::SetPreserveAspectRatio.new
|
44
|
+
app.add_processor :set_view_box, DragonflySvg::Processors::SetViewBox.new
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Dragonfly::App.register_plugin(:svg) { DragonflySvg::Plugin.new }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
class ExtendIds
|
6
|
+
|
7
|
+
def call content, append_str=SecureRandom.urlsafe_base64(8)
|
8
|
+
doc = Nokogiri::XML(content.data)
|
9
|
+
|
10
|
+
# nodes with id attributes
|
11
|
+
doc.xpath("//*[@id]").each do |node|
|
12
|
+
node_id = node.get_attribute 'id'
|
13
|
+
node.set_attribute 'id', [node_id, append_str].join('-')
|
14
|
+
end
|
15
|
+
|
16
|
+
# nodes with id references
|
17
|
+
doc.xpath("//*[@href]").each do |node|
|
18
|
+
node_href = node.get_attribute 'href'
|
19
|
+
node.set_attribute 'href', [node_href, append_str].join('-')
|
20
|
+
end
|
21
|
+
|
22
|
+
content.update(doc.to_xml)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
class SetDimensions
|
6
|
+
|
7
|
+
def call content, width, height
|
8
|
+
doc = Nokogiri::XML(content.data)
|
9
|
+
|
10
|
+
if svg_node = doc.xpath("//*[name()='svg']").first
|
11
|
+
svg_node.set_attribute 'width', width unless width.nil?
|
12
|
+
svg_node.set_attribute 'height', height unless height.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
content.update(doc.to_xml)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
class SetNamespace
|
6
|
+
|
7
|
+
def call content, namespace="http://www.w3.org/2000/svg"
|
8
|
+
doc = Nokogiri::XML(content.data)
|
9
|
+
|
10
|
+
if svg_node = doc.xpath("//*[name()='svg']").first
|
11
|
+
unless svg_node.namespace.href == namespace
|
12
|
+
doc.remove_namespaces!
|
13
|
+
svg_node.add_namespace(nil, namespace)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
content.update(doc.to_xml)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
class SetPreserveAspectRatio
|
6
|
+
|
7
|
+
def call content, value='xMinYMin meet'
|
8
|
+
doc = Nokogiri::XML(content.data)
|
9
|
+
|
10
|
+
if svg_node = doc.xpath("//*[name()='svg']").first
|
11
|
+
svg_node.set_attribute 'preserveAspectRatio', value
|
12
|
+
end
|
13
|
+
|
14
|
+
content.update(doc.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
class SetViewBox
|
6
|
+
|
7
|
+
def call content, min_x, min_y, width, height
|
8
|
+
doc = Nokogiri::XML(content.data)
|
9
|
+
|
10
|
+
value = [min_x, min_y, width, height].map(&:to_s).join(' ')
|
11
|
+
|
12
|
+
if svg_node = doc.xpath("//*[name()='svg']").first
|
13
|
+
svg_node.set_attribute 'viewBox', value
|
14
|
+
end
|
15
|
+
|
16
|
+
content.update(doc.to_xml)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/samples/sample.svg
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Analysers
|
5
|
+
describe SvgProperties do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
|
9
|
+
let(:svg) { app.fetch_file(SAMPLES_DIR.join('sample.svg')) }
|
10
|
+
|
11
|
+
describe 'call' do
|
12
|
+
let(:svg_properties) { analyser.call(svg) }
|
13
|
+
let(:ratio) { 200.0 / 300.0 }
|
14
|
+
|
15
|
+
it 'returns Hash' do
|
16
|
+
svg_properties.must_be_kind_of Hash
|
17
|
+
end
|
18
|
+
|
19
|
+
it ':width' do
|
20
|
+
svg_properties[:width].must_equal 200
|
21
|
+
end
|
22
|
+
|
23
|
+
it ':height' do
|
24
|
+
svg_properties[:height].must_equal 300
|
25
|
+
end
|
26
|
+
|
27
|
+
it ':id' do
|
28
|
+
svg_properties[:id].must_equal 'sample_id'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
describe Plugin do
|
5
|
+
|
6
|
+
let(:app) { test_app.configure_with(:svg) }
|
7
|
+
let(:svg) { app.fetch_file(SAMPLES_DIR.join('sample.svg')) }
|
8
|
+
|
9
|
+
# ---------------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'analysers' do
|
12
|
+
it 'adds #svg_properties' do
|
13
|
+
svg.must_respond_to :svg_properties
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'adds #width' do
|
17
|
+
svg.must_respond_to :width
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'adds #height' do
|
21
|
+
svg.must_respond_to :height
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'adds #aspect_ratio' do
|
25
|
+
svg.must_respond_to :aspect_ratio
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'adds #id' do
|
29
|
+
svg.must_respond_to :id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# ---------------------------------------------------------------------
|
34
|
+
|
35
|
+
describe 'processors' do
|
36
|
+
it 'adds #extend_ids' do
|
37
|
+
svg.must_respond_to :extend_ids
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'adds #remove_namespaces' do
|
41
|
+
svg.must_respond_to :remove_namespaces
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'adds #set_dimensions' do
|
45
|
+
svg.must_respond_to :set_dimensions
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'adds #set_namespace' do
|
49
|
+
svg.must_respond_to :set_namespace
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'adds #set_preserve_aspect_ratio' do
|
53
|
+
svg.must_respond_to :set_preserve_aspect_ratio
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'adds #set_view_box' do
|
57
|
+
svg.must_respond_to :set_view_box
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe ExtendIds do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::ExtendIds.new }
|
9
|
+
let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
|
10
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
@orig_id = analyser.call(svg)[:id]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'adds unique ID' do
|
17
|
+
processor.call(svg)
|
18
|
+
analyser.call(svg)[:id].wont_equal @orig_id
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'adds supplied string to ID' do
|
22
|
+
processor.call(svg, 'foo')
|
23
|
+
analyser.call(svg)[:id].must_equal "#{@orig_id}-foo"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe RemoveNamespaces do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::RemoveNamespaces.new }
|
9
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
10
|
+
|
11
|
+
it 'removes namespaces' do
|
12
|
+
processor.call(svg)
|
13
|
+
svg.data.wont_include 'xmlns='
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe SetDimensions do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::SetDimensions.new }
|
9
|
+
let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
|
10
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
processor.call(svg, 400, 600)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets width' do
|
17
|
+
analyser.call(svg)[:width].must_equal 400
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets height' do
|
21
|
+
analyser.call(svg)[:height].must_equal 600
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe SetNamespace do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::SetNamespace.new }
|
9
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
10
|
+
|
11
|
+
it 'sets default namespace' do
|
12
|
+
processor.call(svg)
|
13
|
+
svg.data.must_include 'http://www.w3.org/2000/svg'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets custom namespace' do
|
17
|
+
processor.call(svg, 'custom_namespace')
|
18
|
+
svg.data.must_include 'custom_namespace'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe SetPreserveAspectRatio do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::SetPreserveAspectRatio.new }
|
9
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
10
|
+
|
11
|
+
describe 'with default value' do
|
12
|
+
it 'adds preserveAspectRatio attribute' do
|
13
|
+
processor.call(svg)
|
14
|
+
svg.data.must_include "preserveAspectRatio"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets default value' do
|
18
|
+
processor.call(svg)
|
19
|
+
svg.data.must_include "xMinYMin meet"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'with specified value' do
|
24
|
+
it 'adds preserveAspectRatio with specified value' do
|
25
|
+
processor.call(svg, 'xMidYMid meet')
|
26
|
+
svg.data.must_include "xMidYMid meet"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module DragonflySvg
|
4
|
+
module Processors
|
5
|
+
describe SetViewBox do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:svg) }
|
8
|
+
let(:processor) { DragonflySvg::Processors::SetViewBox.new }
|
9
|
+
let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
processor.call(svg, 0, 0, 400, 600)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets view box' do
|
16
|
+
svg.data.must_include '0 0 400 600'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/spec'
|
6
|
+
|
7
|
+
require 'dragonfly'
|
8
|
+
require 'dragonfly_svg'
|
9
|
+
|
10
|
+
# ---------------------------------------------------------------------
|
11
|
+
|
12
|
+
SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
def test_app name=nil
|
17
|
+
app = Dragonfly::App.instance(name)
|
18
|
+
app.datastore = Dragonfly::MemoryDataStore.new
|
19
|
+
app.secret = "test secret"
|
20
|
+
app
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragonfly_svg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dragonfly
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Dragonfly analyser and processor for SVGs.
|
112
|
+
email:
|
113
|
+
- tomas.celizna@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- dragonfly_svg.gemspec
|
127
|
+
- lib/dragonfly_svg.rb
|
128
|
+
- lib/dragonfly_svg/analysers/svg_properties.rb
|
129
|
+
- lib/dragonfly_svg/plugin.rb
|
130
|
+
- lib/dragonfly_svg/processors/extend_ids.rb
|
131
|
+
- lib/dragonfly_svg/processors/remove_namespaces.rb
|
132
|
+
- lib/dragonfly_svg/processors/set_dimensions.rb
|
133
|
+
- lib/dragonfly_svg/processors/set_namespace.rb
|
134
|
+
- lib/dragonfly_svg/processors/set_preserve_aspect_ratio.rb
|
135
|
+
- lib/dragonfly_svg/processors/set_view_box.rb
|
136
|
+
- lib/dragonfly_svg/version.rb
|
137
|
+
- samples/sample.svg
|
138
|
+
- test/dragonfly_svg/analysers/svg_properties_test.rb
|
139
|
+
- test/dragonfly_svg/plugin_test.rb
|
140
|
+
- test/dragonfly_svg/processors/extend_ids_test.rb
|
141
|
+
- test/dragonfly_svg/processors/remove_namespaces_test.rb
|
142
|
+
- test/dragonfly_svg/processors/set_dimensions_test.rb
|
143
|
+
- test/dragonfly_svg/processors/set_namespace_test.rb
|
144
|
+
- test/dragonfly_svg/processors/set_preserve_aspect_ratio_test.rb
|
145
|
+
- test/dragonfly_svg/processors/set_view_box_test.rb
|
146
|
+
- test/test_helper.rb
|
147
|
+
homepage: https://github.com/tomasc/dragonfly_svg
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.2.2
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Dragonfly analyser and processor for SVGs.
|
171
|
+
test_files:
|
172
|
+
- test/dragonfly_svg/analysers/svg_properties_test.rb
|
173
|
+
- test/dragonfly_svg/plugin_test.rb
|
174
|
+
- test/dragonfly_svg/processors/extend_ids_test.rb
|
175
|
+
- test/dragonfly_svg/processors/remove_namespaces_test.rb
|
176
|
+
- test/dragonfly_svg/processors/set_dimensions_test.rb
|
177
|
+
- test/dragonfly_svg/processors/set_namespace_test.rb
|
178
|
+
- test/dragonfly_svg/processors/set_preserve_aspect_ratio_test.rb
|
179
|
+
- test/dragonfly_svg/processors/set_view_box_test.rb
|
180
|
+
- test/test_helper.rb
|