svgen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba2bf72e26dc27ef68324a6cc8ed88bdaa06327d
4
- data.tar.gz: 914b64c57e8d97d1082f19a09f298e2421542771
3
+ metadata.gz: bdc86f02b34189d954cf476880fa22bd083a2f1f
4
+ data.tar.gz: 2ec47b8e97adbe5447d5e41dbde7533385598c96
5
5
  SHA512:
6
- metadata.gz: dd05c6d01bf5f58db290ebde74d35edd0c17fbe1de358c11ddb3829ec9453355aabf788d0c63ebe04fe8b289768d4996d6bbe4a4df548a5cc3946d86972f9bd3
7
- data.tar.gz: c4b524f9c66918f231d6874ea7035d2d84cdf9e208df9d2b58ce5c9e66639cca0e777f8753eaf9f7926d799330d8d95b1e64fd73e022493111052297afcb3460
6
+ metadata.gz: f15074003e07481a35e56d687d9dd7c719d9a7279c18dfec46d0388af358ae21ff527ffd70a6d12c0cee375ecede891e176bc9074dbcf5bed34d6d3360db6f4d
7
+ data.tar.gz: cdd5ebada7f0a4977d474ebf474f9ec9316e8b7b9b0cfc6fc585e897bd2bfa6501a69a6f60324db3846a31d8d2cc33528806566f43a2db3adda72395f14a1236
data/README.md CHANGED
@@ -22,8 +22,6 @@ svg = SVGen::SVG.new(width: 600, height: 400) do |svg|
22
22
  end
23
23
  svg.generate
24
24
  #=>
25
- # <?xml version="1.0" encoding="UTF-8" standalone="no"?>
26
- # <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
27
25
  # <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
28
26
  # <rect width="300" height="200" fill="blue"/>
29
27
  # <circle cx="100" cy="100" r="50" fill="red"/>
@@ -44,8 +42,6 @@ svg = SVGen::SVG.new(width: 600, height: 400) do |svg|
44
42
  end
45
43
  svg.generate
46
44
  #=>
47
- # <?xml version="1.0" encoding="UTF-8" standalone="no"?>
48
- # <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
49
45
  # <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
50
46
  # <g stroke="red" stroke-width="5">
51
47
  # <rect x="50" y="50" width="100" height="100"/>
@@ -1,25 +1,12 @@
1
1
  module SVGen
2
2
  module Element
3
- class Circle < Base
3
+ class Circle
4
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] || "rgba(0, 0, 0, 0)"
5
+ @attrs = attrs
10
6
  end
11
7
 
12
8
  def generate(svg)
13
- svg.circle(attributes)
14
- end
15
-
16
- protected
17
-
18
- def attributes
19
- attrs = super
20
- attrs.delete(:x)
21
- attrs.delete(:y)
22
- attrs
9
+ svg.circle(@attrs)
23
10
  end
24
11
  end
25
12
  end
@@ -1,28 +1,19 @@
1
1
  module SVGen
2
2
  module Element
3
- class Group < Base
3
+ class Group
4
4
  include Nestable
5
5
 
6
6
  def initialize(attrs = {}, &block)
7
7
  @children = []
8
- @stroke = attrs[:stroke]
9
- @stroke_width = attrs[:"stroke-width"] || attrs["stroke-width"]
8
+ @attrs = attrs
10
9
  block.call(self) if block_given?
11
10
  end
12
11
 
13
12
  def generate(svg)
14
- svg.g(attributes) do |g|
13
+ svg.g(@attrs) do |g|
15
14
  @children.each { |child| child.generate(g) }
16
15
  end
17
16
  end
18
-
19
- protected
20
-
21
- def attributes
22
- attrs = super
23
- attrs.delete(:children)
24
- attrs
25
- end
26
17
  end
27
18
  end
28
19
  end
@@ -1,25 +1,12 @@
1
1
  module SVGen
2
2
  module Element
3
- class Line < Base
3
+ class Line
4
4
  def initialize(attrs = {})
5
- super(attrs)
6
- @x1 = attrs[:x1] || @x
7
- @y1 = attrs[:y1] || @y
8
- @x2 = attrs[:x2] || @x
9
- @y2 = attrs[:y2] || @y
5
+ @attrs = attrs
10
6
  end
11
7
 
12
8
  def generate(svg)
13
- svg.line(attributes)
14
- end
15
-
16
- protected
17
-
18
- def attributes
19
- attrs = super
20
- attrs.delete(:x)
21
- attrs.delete(:y)
22
- attrs
9
+ svg.line(@attrs)
23
10
  end
24
11
  end
25
12
  end
@@ -1,15 +1,12 @@
1
1
  module SVGen
2
2
  module Element
3
- class Rect < Base
3
+ class Rect
4
4
  def initialize(attrs = {})
5
- super(attrs)
6
- @width = attrs[:width] || 100
7
- @height = attrs[:height] || 100
8
- @fill = attrs[:fill] || "rgba(0, 0, 0, 0)"
5
+ @attrs = attrs
9
6
  end
10
7
 
11
8
  def generate(svg)
12
- svg.rect(attributes)
9
+ svg.rect(@attrs)
13
10
  end
14
11
  end
15
12
  end
@@ -1,21 +1,13 @@
1
1
  module SVGen
2
2
  module Element
3
- class Text < Base
3
+ class Text
4
4
  def initialize(text, attrs = {})
5
- super(attrs)
6
5
  @text = text
6
+ @attrs = attrs
7
7
  end
8
8
 
9
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
10
+ svg.text(@text, @attrs)
19
11
  end
20
12
  end
21
13
  end
data/lib/svgen/svg.rb CHANGED
@@ -6,16 +6,13 @@ module SVGen
6
6
 
7
7
  def initialize(attrs = {}, &block)
8
8
  @children = []
9
- @width = attrs[:width] || 400
10
- @height = attrs[:height] || 300
9
+ @attrs = attrs
11
10
  block.call(self) if block_given?
12
11
  end
13
12
 
14
13
  def generate
15
14
  builder = Builder::XmlMarkup.new(indent: 2)
16
- builder.instruct! :xml, version: "1.0", encoding: "UTF-8", standalone: "no"
17
- builder.declare! :DOCTYPE, :svg, :PUBLIC, "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
18
- builder.svg(width: @width, height: @height, xmlns: "http://www.w3.org/2000/svg") do |svg|
15
+ builder.svg(@attrs.merge({ xmlns: "http://www.w3.org/2000/svg" })) do |svg|
19
16
  @children.each { |child| child.generate(svg) }
20
17
  end
21
18
  end
data/lib/svgen.rb CHANGED
@@ -1,9 +1,5 @@
1
- lib = File.dirname(__FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
1
  require "svgen/nestable"
5
2
  require "svgen/svg"
6
- require "svgen/element/base"
7
3
  require "svgen/element/rect"
8
4
  require "svgen/element/circle"
9
5
  require "svgen/element/text"
@@ -0,0 +1,3 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="100" cy="100" r="50" fill="red"/>
3
+ </svg>
@@ -0,0 +1,6 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ <g stroke="red" stroke-width="5">
3
+ <rect width="300" height="200" fill="red"/>
4
+ <circle cx="50" cy="50" r="10" fill="blue"/>
5
+ </g>
6
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ <line x1="10" y1="10" x2="50" y2="50" stroke="black" stroke-width="5"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="400" height="300" fill="red"/>
3
+ </svg>
@@ -0,0 +1,2 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
2
+ <text x="20" y="20">Sample Text</text>
3
+ </svg>
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,5 @@ require File.expand_path("../lib/svgen", File.dirname(__FILE__))
2
2
 
3
3
  RSpec.configure do |config|
4
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
5
  config.order = "random"
8
6
  end
@@ -2,46 +2,47 @@ require "spec_helper"
2
2
 
3
3
  describe SVGen::SVG do
4
4
  describe "#generate" do
5
+ let(:fixtures_path) { Pathname.new("spec/fixtures") }
5
6
  after do
6
7
  data = @svg.generate
7
8
  expect(data).to eq @sample.read
8
9
  end
9
10
 
10
11
  it "returns simple SVG data" do
11
- @sample = Pathname.new("spec/support/sample.svg")
12
+ @sample = fixtures_path.join("sample.svg")
12
13
  @svg = SVGen::SVG.new(width: 600, height: 300)
13
14
  end
14
15
 
15
16
  it "returns SVG data with rect" do
16
- @sample = Pathname.new("spec/support/rect.svg")
17
+ @sample = fixtures_path.join("rect.svg")
17
18
  @svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
18
19
  svg.rect(width: 400, height: 300, fill: "red")
19
20
  end
20
21
  end
21
22
 
22
23
  it "returns SVG data with circle" do
23
- @sample = Pathname.new("spec/support/circle.svg")
24
+ @sample = fixtures_path.join("circle.svg")
24
25
  @svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
25
26
  svg.circle(cx: 100, cy: 100, r: 50, fill: "red")
26
27
  end
27
28
  end
28
29
 
29
30
  it "returns SVG data with text" do
30
- @sample = Pathname.new("spec/support/text.svg")
31
+ @sample = fixtures_path.join("text.svg")
31
32
  @svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
32
33
  svg.text("Sample Text", x: 20, y: 20)
33
34
  end
34
35
  end
35
36
 
36
37
  it "returns SVG data with line" do
37
- @sample = Pathname.new("spec/support/line.svg")
38
+ @sample = fixtures_path.join("line.svg")
38
39
  @svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
39
40
  svg.line(x1: 10, y1: 10, x2: 50, y2: 50, stroke: "black", :"stroke-width" => "5")
40
41
  end
41
42
  end
42
43
 
43
44
  it "returns SVG data with group" do
44
- @sample = Pathname.new("spec/support/group.svg")
45
+ @sample = fixtures_path.join("group.svg")
45
46
  @svg = SVGen::SVG.new(width: 600, height: 300) do |svg|
46
47
  svg.g(stroke: "red", "stroke-width" => 5) do |g|
47
48
  g.rect(width: "300", height: "200", fill: "red")
data/svgen.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "svgen"
6
- spec.version = "0.0.2"
6
+ spec.version = "0.0.3"
7
7
  spec.authors = ["Naoto Kaneko"]
8
8
  spec.email = ["naoty.k@gmail.com"]
9
9
  spec.summary = %q{SVG generator}
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Kaneko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.14.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.14.1
69
69
  description:
@@ -73,13 +73,12 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
76
+ - .gitignore
77
77
  - Gemfile
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
81
  - lib/svgen.rb
82
- - lib/svgen/element/base.rb
83
82
  - lib/svgen/element/circle.rb
84
83
  - lib/svgen/element/group.rb
85
84
  - lib/svgen/element/line.rb
@@ -88,13 +87,13 @@ files:
88
87
  - lib/svgen/nestable.rb
89
88
  - lib/svgen/svg.rb
90
89
  - lib/svgen/version.rb
90
+ - spec/fixtures/circle.svg
91
+ - spec/fixtures/group.svg
92
+ - spec/fixtures/line.svg
93
+ - spec/fixtures/rect.svg
94
+ - spec/fixtures/sample.svg
95
+ - spec/fixtures/text.svg
91
96
  - spec/spec_helper.rb
92
- - spec/support/circle.svg
93
- - spec/support/group.svg
94
- - spec/support/line.svg
95
- - spec/support/rect.svg
96
- - spec/support/sample.svg
97
- - spec/support/text.svg
98
97
  - spec/svgen/svg_spec.rb
99
98
  - svgen.gemspec
100
99
  homepage: http://github.com/naoty/svgen
@@ -107,26 +106,26 @@ require_paths:
107
106
  - lib
108
107
  required_ruby_version: !ruby/object:Gem::Requirement
109
108
  requirements:
110
- - - ">="
109
+ - - '>='
111
110
  - !ruby/object:Gem::Version
112
111
  version: '0'
113
112
  required_rubygems_version: !ruby/object:Gem::Requirement
114
113
  requirements:
115
- - - ">="
114
+ - - '>='
116
115
  - !ruby/object:Gem::Version
117
116
  version: '0'
118
117
  requirements: []
119
118
  rubyforge_project:
120
- rubygems_version: 2.2.0
119
+ rubygems_version: 2.0.14
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: SVG generator
124
123
  test_files:
124
+ - spec/fixtures/circle.svg
125
+ - spec/fixtures/group.svg
126
+ - spec/fixtures/line.svg
127
+ - spec/fixtures/rect.svg
128
+ - spec/fixtures/sample.svg
129
+ - spec/fixtures/text.svg
125
130
  - spec/spec_helper.rb
126
- - spec/support/circle.svg
127
- - spec/support/group.svg
128
- - spec/support/line.svg
129
- - spec/support/rect.svg
130
- - spec/support/sample.svg
131
- - spec/support/text.svg
132
131
  - spec/svgen/svg_spec.rb
@@ -1,30 +0,0 @@
1
- module SVGen
2
- module Element
3
- class Base
4
- def initialize(attrs = {})
5
- @x = attrs[:x] || 0
6
- @y = attrs[:y] || 0
7
- @stroke = attrs[:stroke]
8
- @stroke_width = attrs[:"stroke-width"] || attrs["stroke-width"]
9
- end
10
-
11
- def generate(svg)
12
- raise NotImplementedError.new("Subclass must override SVGen::Element::Base#generate")
13
- end
14
-
15
- protected
16
-
17
- def attributes
18
- attrs = {}
19
- instance_variables.each do |instance_variable|
20
- value = instance_variable_get(instance_variable)
21
- next if value.nil?
22
- key = instance_variable.to_s.gsub(/@/) { "" }
23
- key = key.gsub(/_/) { "-" }
24
- attrs[key.to_sym] = value
25
- end
26
- attrs
27
- end
28
- end
29
- end
30
- end
@@ -1,5 +0,0 @@
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 cx="100" cy="100" r="50" fill="red"/>
5
- </svg>
@@ -1,8 +0,0 @@
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
- <g stroke="red" stroke-width="5">
5
- <rect x="0" y="0" width="300" height="200" fill="red"/>
6
- <circle cx="50" cy="50" r="10" fill="blue"/>
7
- </g>
8
- </svg>
@@ -1,5 +0,0 @@
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
- <line stroke="black" stroke-width="5" x1="10" y1="10" x2="50" y2="50"/>
5
- </svg>
@@ -1,5 +0,0 @@
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>
@@ -1,4 +0,0 @@
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
- </svg>
@@ -1,5 +0,0 @@
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>