victor 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6169e5a528a272be07b50c054454828a59877a57
4
+ data.tar.gz: 5f51076c9346ca40dfd470a9be139d0a588d2fcd
5
+ SHA512:
6
+ metadata.gz: e0511f7103e0046dc0620776cc21e422321a7f5f996c59131c42df071db9d5c56c121bfefaffb4efc683c4662424f5255dab73b6888a9eaaf0968e8d6080cb75
7
+ data.tar.gz: ca6e5eca44dce8b644df23a6107822157644235662a1ed4f13695b9abf1ca6c52f3e000551f7ab8e65d9588fe00d9f9d4757c7d35613b39b6fb9223b4730b10a
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ Victor - Ruby SVG Image Builder
2
+ ==================================================
3
+
4
+ [![Gem](https://img.shields.io/gem/v/victor.svg?style=flat-square)](https://rubygems.org/gems/victor)
5
+ [![Travis](https://img.shields.io/travis/DannyBen/victor.svg?style=flat-square)](https://travis-ci.org/DannyBen/victor)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/victor.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/victor)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/victor.svg?style=flat-square)](https://gemnasium.com/DannyBen/victor)
8
+
9
+ ---
10
+
11
+ Victor is a direct Ruby to SVG builder. All method calls are converted
12
+ directly to SVG elements.
13
+
14
+ ---
15
+
16
+ Install
17
+ --------------------------------------------------
18
+
19
+ ```
20
+ $ gem install victor
21
+ ```
22
+
23
+ Or with bundler:
24
+
25
+ ```ruby
26
+ gem 'victor'
27
+ ```
28
+
29
+ Examples
30
+ --------------------------------------------------
31
+
32
+ See the examples folder for several ruby scripts and their SVG output.
33
+
34
+
35
+ Usage
36
+ --------------------------------------------------
37
+
38
+ Victor uses a single method (`element`) to generate all SVG elements:
39
+
40
+ ```ruby
41
+ require 'victor'
42
+ svg = SVG.new
43
+
44
+ svg.element :rect, x: 2, y: 2, width: 200, height: 200
45
+ # => <rect x="2" y="2" width="200" height="200"/>
46
+ ```
47
+
48
+ But you can omit it. Calls to any other method, will be delegated to the
49
+ `element` method, so normal usage looks more like this:
50
+
51
+ ```ruby
52
+ # this will generate the exact same result
53
+ svg.rect x: 2, y: 2, width: 200, height: 200
54
+ # => <rect x="2" y="2" width="200" height="200"/>
55
+ ```
56
+
57
+ You can use the `build` method, to generate the SVG with a block
58
+
59
+ ```ruby
60
+ svg.build do
61
+ rect x: 0, y: 0, width: 100, height: 100, style: { fill: '#ccc' }
62
+ rect x: 20, y: 20, width: 60, height: 60, style: { fill: '#f99' }
63
+ end
64
+ ```
65
+
66
+ Generate the SVG to a string with `render`:
67
+
68
+ ```ruby
69
+ result = svg.render
70
+ ```
71
+
72
+ Or, save it to a file with `save`:
73
+
74
+ ```ruby
75
+ svg.save 'filename' # the '.svg' extension is optional
76
+ ```
data/lib/victor.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'victor/version'
2
+ require 'victor/svg'
3
+
4
+ include Victor
data/lib/victor/svg.rb ADDED
@@ -0,0 +1,70 @@
1
+
2
+
3
+ module Victor
4
+
5
+ class SVG
6
+ attr_accessor :height, :width
7
+ attr_reader :content
8
+
9
+ def initialize(opts={})
10
+ @height = opts[:height] || "100%"
11
+ @width = opts[:width] || "100%"
12
+ @content = []
13
+ end
14
+
15
+ def method_missing(method_sym, *arguments, &block)
16
+ element method_sym, *arguments
17
+ end
18
+
19
+ def build(&block)
20
+ self.instance_eval &block
21
+ end
22
+
23
+ def element(name, attributes={}, &block)
24
+ xml_attributes = expand attributes
25
+ elem = "<#{name} #{xml_attributes}/>"
26
+ content.push elem
27
+ elem
28
+ end
29
+
30
+ def render
31
+ template % { height: height, width: width, content: content.join("\n") }
32
+ end
33
+
34
+ def save(filename)
35
+ filename = "#{filename}.svg" unless filename =~ /\..{2,4}$/
36
+ File.write filename, render
37
+ end
38
+
39
+ private
40
+
41
+ def expand(attributes={})
42
+ mapped = attributes.map do |key, value|
43
+ value.is_a?(Hash) ? inner_expand(key, value) : "#{key}=\"#{value}\""
44
+ end
45
+
46
+ mapped.join ' '
47
+ end
48
+
49
+ def inner_expand(key, attributes)
50
+ mapped = attributes.map do |key, value|
51
+ "#{key}:#{value}"
52
+ end
53
+
54
+ "#{key}=\"#{mapped.join '; '}\""
55
+ end
56
+
57
+ def template
58
+ File.read template_path
59
+ end
60
+
61
+ def template_path
62
+ File.join File.dirname(__FILE__), template_file
63
+ end
64
+
65
+ def template_file
66
+ 'template.svg'
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" 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="%{width}" height="%{height}" xmlns="http://www.w3.org/2000/svg">
4
+ %{content}
5
+ </svg>
@@ -0,0 +1,3 @@
1
+ module Victor
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: victor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: runfile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: runfile-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: filewatcher
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ description: Build SVG images with ease
84
+ email: db@dannyben.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - README.md
90
+ - lib/victor.rb
91
+ - lib/victor/svg.rb
92
+ - lib/victor/template.svg
93
+ - lib/victor/version.rb
94
+ homepage: https://github.com/DannyBen/victor
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.0.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: SVG Builder
118
+ test_files: []