victor 0.2.3 → 0.2.4
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 +4 -4
- data/README.md +10 -0
- data/lib/victor/css.rb +8 -4
- data/lib/victor/svg.rb +1 -74
- data/lib/victor/svg_base.rb +76 -0
- data/lib/victor/templates/default.svg +1 -6
- data/lib/victor/templates/html.svg +1 -7
- data/lib/victor/version.rb +1 -1
- data/lib/victor.rb +1 -0
- metadata +4 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf5e10e9c9f1abd3279977ba3b70579241571ee0d7ba47705b3c2c4aac243e93
|
4
|
+
data.tar.gz: 118123aa977a92a9032406b43e5da60f4d0f946f3116964f633f3572c217c746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41739345915bd13a9d3be83fc8820562a61627b12173ebb7b287ef3ce61c07f5f4a50ebdc6a74e9d69de7754c18a2ce905e86439cad5a78ffad9620521406618
|
7
|
+
data.tar.gz: 9404df21b13cf754d949280a45f7a26d74cfe7e5ca4b555225bd76284defe41a3f14837d1fa90e3284fb16ee17f3ac03da92c6e15ae48a4034b1805a4c9b6f33
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+

|
2
|
+
|
1
3
|
Victor - Ruby SVG Image Builder
|
2
4
|
==================================================
|
3
5
|
|
@@ -26,6 +28,7 @@ Table of Contents
|
|
26
28
|
* [Saving the Output](#saving-the-output)
|
27
29
|
* [SVG Templates](#svg-templates)
|
28
30
|
* [CSS](#css)
|
31
|
+
* [Using with Rails](#using-with-rails)
|
29
32
|
|
30
33
|
---
|
31
34
|
|
@@ -316,6 +319,13 @@ will result in two `@import url(...)` rows.
|
|
316
319
|
See the [custom fonts example](https://github.com/DannyBen/victor/tree/master/examples#12-custom-fonts).
|
317
320
|
|
318
321
|
|
322
|
+
Using with Rails
|
323
|
+
--------------------------------------------------
|
324
|
+
|
325
|
+
See the [example_rails](example_rails) folder.
|
326
|
+
|
327
|
+
|
328
|
+
|
319
329
|
---
|
320
330
|
|
321
331
|
[examples]: https://github.com/DannyBen/victor/tree/master/examples#examples
|
data/lib/victor/css.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
module Victor
|
2
2
|
|
3
|
-
# Converts a Hash to a CSS string
|
4
3
|
class CSS
|
5
4
|
attr_reader :attributes
|
6
5
|
|
7
|
-
def initialize(attributes=
|
8
|
-
@attributes = attributes
|
6
|
+
def initialize(attributes = nil)
|
7
|
+
@attributes = attributes || {}
|
9
8
|
end
|
10
9
|
|
11
10
|
def to_s
|
12
11
|
convert_hash attributes
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
def render
|
15
|
+
return '' if attributes.empty?
|
16
|
+
%Q{<style type="text/css">\n<![CDATA[\n#{self}\n]]>\n</style>\n}
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
16
20
|
|
17
21
|
def convert_hash(hash, indent=2)
|
18
22
|
return hash unless hash.is_a? Hash
|
data/lib/victor/svg.rb
CHANGED
@@ -1,80 +1,7 @@
|
|
1
1
|
module Victor
|
2
|
-
|
3
|
-
# This is the primary Victor class. It handles all the conversion from
|
4
|
-
# ruby to SVG using {#method_missing}
|
5
|
-
class SVG
|
6
|
-
attr_accessor :template, :css
|
7
|
-
attr_reader :content, :svg_attributes
|
8
|
-
|
9
|
-
def initialize(attributes={})
|
10
|
-
@template = attributes.delete(:template) || :default
|
11
|
-
@svg_attributes = Attributes.new attributes
|
12
|
-
svg_attributes[:width] ||= "100%"
|
13
|
-
svg_attributes[:height] ||= "100%"
|
14
|
-
@content = []
|
15
|
-
@css = {}
|
16
|
-
end
|
17
|
-
|
2
|
+
class SVG < SVGBase
|
18
3
|
def method_missing(method_sym, *arguments, &block)
|
19
4
|
element method_sym, *arguments, &block
|
20
5
|
end
|
21
|
-
|
22
|
-
def <<(additional_content)
|
23
|
-
content.push additional_content.to_s
|
24
|
-
end
|
25
|
-
alias append <<
|
26
|
-
|
27
|
-
def build(&block)
|
28
|
-
self.instance_eval(&block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def element(name, value=nil, attributes={}, &_block)
|
32
|
-
if value.is_a? Hash
|
33
|
-
attributes = value
|
34
|
-
value = nil
|
35
|
-
end
|
36
|
-
|
37
|
-
attributes = Attributes.new attributes
|
38
|
-
|
39
|
-
if block_given? || value
|
40
|
-
content.push "<#{name} #{attributes}".strip + ">"
|
41
|
-
value ? content.push(value) : yield
|
42
|
-
content.push "</#{name}>"
|
43
|
-
else
|
44
|
-
content.push "<#{name} #{attributes}/>"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def render
|
49
|
-
svg_template % {
|
50
|
-
css: CSS.new(css),
|
51
|
-
attributes: svg_attributes,
|
52
|
-
content: content.join("\n")
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def to_s
|
57
|
-
content.join "\n"
|
58
|
-
end
|
59
|
-
|
60
|
-
def save(filename)
|
61
|
-
filename = "#{filename}.svg" unless filename =~ /\..{2,4}$/
|
62
|
-
File.write filename, render
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def svg_template
|
68
|
-
File.read template_path
|
69
|
-
end
|
70
|
-
|
71
|
-
def template_path
|
72
|
-
if template.is_a? Symbol
|
73
|
-
File.join File.dirname(__FILE__), 'templates', "#{template}.svg"
|
74
|
-
else
|
75
|
-
template
|
76
|
-
end
|
77
|
-
end
|
78
6
|
end
|
79
|
-
|
80
7
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Victor
|
2
|
+
|
3
|
+
class SVGBase
|
4
|
+
attr_accessor :template, :css
|
5
|
+
attr_reader :content, :svg_attributes
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
@template = attributes.delete(:template) || :default
|
9
|
+
@svg_attributes = Attributes.new attributes
|
10
|
+
svg_attributes[:width] ||= "100%"
|
11
|
+
svg_attributes[:height] ||= "100%"
|
12
|
+
@content = []
|
13
|
+
@css = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def <<(additional_content)
|
17
|
+
content.push additional_content.to_s
|
18
|
+
end
|
19
|
+
alias append <<
|
20
|
+
|
21
|
+
def build(&block)
|
22
|
+
self.instance_eval(&block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def element(name, value=nil, attributes={}, &_block)
|
26
|
+
if value.is_a? Hash
|
27
|
+
attributes = value
|
28
|
+
value = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
attributes = Attributes.new attributes
|
32
|
+
|
33
|
+
if block_given? || value
|
34
|
+
content.push "<#{name} #{attributes}".strip + ">"
|
35
|
+
value ? content.push(value) : yield
|
36
|
+
content.push "</#{name}>"
|
37
|
+
else
|
38
|
+
content.push "<#{name} #{attributes}/>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def render
|
43
|
+
css_string = CSS.new css
|
44
|
+
svg_template % {
|
45
|
+
css: css_string,
|
46
|
+
style: css_string.render,
|
47
|
+
attributes: svg_attributes,
|
48
|
+
content: content.join("\n")
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
content.join "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
def save(filename)
|
57
|
+
filename = "#{filename}.svg" unless filename =~ /\..{2,4}$/
|
58
|
+
File.write filename, render
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def svg_template
|
64
|
+
File.read template_path
|
65
|
+
end
|
66
|
+
|
67
|
+
def template_path
|
68
|
+
if template.is_a? Symbol
|
69
|
+
File.join File.dirname(__FILE__), 'templates', "#{template}.svg"
|
70
|
+
else
|
71
|
+
template
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/lib/victor/version.rb
CHANGED
data/lib/victor.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: victor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
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.10'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.10'
|
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.6'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.6'
|
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.16'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.16'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: filewatcher
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.0'
|
11
|
+
date: 2018-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
83
13
|
description: Build SVG images with ease
|
84
14
|
email: db@dannyben.com
|
85
15
|
executables: []
|
@@ -91,6 +21,7 @@ files:
|
|
91
21
|
- lib/victor/attributes.rb
|
92
22
|
- lib/victor/css.rb
|
93
23
|
- lib/victor/svg.rb
|
24
|
+
- lib/victor/svg_base.rb
|
94
25
|
- lib/victor/templates/default.svg
|
95
26
|
- lib/victor/templates/html.svg
|
96
27
|
- lib/victor/version.rb
|