svgen 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/lib/svgen/element/base.rb +25 -0
- data/lib/svgen/element/circle.rb +17 -0
- data/lib/svgen/element/rect.rb +16 -0
- data/lib/svgen/element/text.rb +22 -0
- data/lib/svgen/svg.rb +33 -0
- data/lib/svgen/version.rb +0 -0
- data/lib/svgen.rb +8 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/circle.svg +5 -0
- data/spec/support/rect.svg +5 -0
- data/spec/support/sample.svg +4 -0
- data/spec/support/text.svg +5 -0
- data/spec/svgen/svg_spec.rb +36 -0
- data/svgen.gemspec +22 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ac4edd0774ebc4189f3b37d4bdcb2cfa1cc9d9b
|
4
|
+
data.tar.gz: 9241392aed9ead03e300d2a8dead528e111a52c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16975f7fd1044f56c0a1cb630175404f0c4b7b6455d2ea7b81e4a598e0554fe056ac0f97b3cfd3d48a0eb051567249a7c297aba47d26abff4f7f1580cd2d0f6a
|
7
|
+
data.tar.gz: 1ac64515a7a7d4765f96c3ca6568ec583e7bbfb69a050fd936d72149fda20d1eb16e391e110bc2d0fe55b3b09d06022227a17adb1b6a60a0a25c5c39643a3b78
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Naoto Kaneko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# SVGen
|
2
|
+
|
3
|
+
SVG generator
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```sh
|
8
|
+
$ gem install svgen
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```rb
|
14
|
+
require "svgen"
|
15
|
+
|
16
|
+
svg = SVGen::SVG.new(width: 600, height: 400) do |svg|
|
17
|
+
svg.rect(width: 300, height: 200, fill: "blue")
|
18
|
+
svg.circle(cx: 100, cy: 100, r: 50, fill: "red")
|
19
|
+
end
|
20
|
+
svg.generate
|
21
|
+
#=>
|
22
|
+
# <?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
23
|
+
# <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
24
|
+
# <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
|
25
|
+
# <rect width="300" height="200" fill="blue"/>
|
26
|
+
# <circle cx="100" cy="100" r="50" fill="red"/>
|
27
|
+
# </svg>
|
28
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SVGen
|
2
|
+
module Element
|
3
|
+
class Base
|
4
|
+
def initialize(attrs = {})
|
5
|
+
@x = attrs[:x] || 0
|
6
|
+
@y = attrs[:y] || 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(svg)
|
10
|
+
raise NotImplementedError.new("Subclass must override SVGen::Element::Base#generate")
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
attrs = {}
|
17
|
+
instance_variables.each do |instance_variable|
|
18
|
+
key = instance_variable.to_s.gsub(/@/) { "" }.to_sym
|
19
|
+
attrs[key] = instance_variable_get(instance_variable)
|
20
|
+
end
|
21
|
+
attrs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SVGen
|
2
|
+
module Element
|
3
|
+
class Circle < Base
|
4
|
+
def initialize(attrs = {})
|
5
|
+
super(attrs)
|
6
|
+
@cx = attrs[:cx] || 0
|
7
|
+
@cy = attrs[:cy] || 0
|
8
|
+
@r = attrs[:r] || 10
|
9
|
+
@fill = attrs[:fill] || "white"
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate(svg)
|
13
|
+
svg.circle(attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SVGen
|
2
|
+
module Element
|
3
|
+
class Rect < Base
|
4
|
+
def initialize(attrs = {})
|
5
|
+
super(attrs)
|
6
|
+
@width = attrs[:width] || 100
|
7
|
+
@height = attrs[:height] || 100
|
8
|
+
@fill = attrs[:fill] || "white"
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate(svg)
|
12
|
+
svg.rect(attributes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SVGen
|
2
|
+
module Element
|
3
|
+
class Text < Base
|
4
|
+
def initialize(text, attrs = {})
|
5
|
+
super(attrs)
|
6
|
+
@text = text
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(svg)
|
10
|
+
svg.text(@text, attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
attrs = super
|
17
|
+
attrs.delete(:text)
|
18
|
+
attrs
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/svgen/svg.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "builder"
|
2
|
+
|
3
|
+
module SVGen
|
4
|
+
class SVG
|
5
|
+
def initialize(attrs = {})
|
6
|
+
@children = []
|
7
|
+
@width = attrs[:width] || 400
|
8
|
+
@height = attrs[:height] || 300
|
9
|
+
yield(self) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def rect(attrs = {})
|
13
|
+
@children << Element::Rect.new(attrs)
|
14
|
+
end
|
15
|
+
|
16
|
+
def circle(attrs = {})
|
17
|
+
@children << Element::Circle.new(attrs)
|
18
|
+
end
|
19
|
+
|
20
|
+
def text(text, attrs = {})
|
21
|
+
@children << Element::Text.new(text, attrs)
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate
|
25
|
+
builder = Builder::XmlMarkup.new(indent: 2)
|
26
|
+
builder.instruct! :xml, version: "1.0", encoding: "UTF-8", standalone: "no"
|
27
|
+
builder.declare! :DOCTYPE, :svg, :PUBLIC, "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
|
28
|
+
builder.svg(width: @width, height: @height, xmlns: "http://www.w3.org/2000/svg") do |svg|
|
29
|
+
@children.each { |child| child.generate(svg) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
File without changes
|
data/lib/svgen.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path("../lib/svgen", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
+
config.run_all_when_everything_filtered = true
|
6
|
+
config.filter_run :focus
|
7
|
+
config.order = "random"
|
8
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<circle x="0" y="0" cx="100" cy="100" r="50" fill="red"/>
|
5
|
+
</svg>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<rect x="0" y="0" width="400" height="300" fill="red"/>
|
5
|
+
</svg>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<text x="20" y="20">Sample Text</text>
|
5
|
+
</svg>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SVGen::SVG do
|
4
|
+
describe "#generate" do
|
5
|
+
after do
|
6
|
+
data = @svg.generate
|
7
|
+
expect(data).to eq @sample.read
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns simple SVG data" do
|
11
|
+
@sample = Pathname.new("spec/support/sample.svg")
|
12
|
+
@svg = SVGen::SVG.new(width: 600, height: 300)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns SVG data with rect" do
|
16
|
+
@sample = Pathname.new("spec/support/rect.svg")
|
17
|
+
@svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
|
18
|
+
svg.rect(width: 400, height: 300, fill: "red")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns SVG data with circle" do
|
23
|
+
@sample = Pathname.new("spec/support/circle.svg")
|
24
|
+
@svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
|
25
|
+
svg.circle(cx: 100, cy: 100, r: 50, fill: "red")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns SVG data with text" do
|
30
|
+
@sample = Pathname.new("spec/support/text.svg")
|
31
|
+
@svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
|
32
|
+
svg.text("Sample Text", x: 20, y: 20)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/svgen.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "svgen"
|
6
|
+
spec.version = "0.0.1"
|
7
|
+
spec.authors = ["Naoto Kaneko"]
|
8
|
+
spec.email = ["naoty.k@gmail.com"]
|
9
|
+
spec.summary = %q{SVG generator}
|
10
|
+
spec.homepage = "http://github.com/naoty/svgen"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "builder", "~> 3.2.2"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoto Kaneko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: builder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- naoty.k@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/svgen.rb
|
82
|
+
- lib/svgen/element/base.rb
|
83
|
+
- lib/svgen/element/circle.rb
|
84
|
+
- lib/svgen/element/rect.rb
|
85
|
+
- lib/svgen/element/text.rb
|
86
|
+
- lib/svgen/svg.rb
|
87
|
+
- lib/svgen/version.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/support/circle.svg
|
90
|
+
- spec/support/rect.svg
|
91
|
+
- spec/support/sample.svg
|
92
|
+
- spec/support/text.svg
|
93
|
+
- spec/svgen/svg_spec.rb
|
94
|
+
- svgen.gemspec
|
95
|
+
homepage: http://github.com/naoty/svgen
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.2.0
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: SVG generator
|
119
|
+
test_files:
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/support/circle.svg
|
122
|
+
- spec/support/rect.svg
|
123
|
+
- spec/support/sample.svg
|
124
|
+
- spec/support/text.svg
|
125
|
+
- spec/svgen/svg_spec.rb
|