victor 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: f0a520dfbed8f1278e8bcf7656ff0afabb7b6568c3ac3d5a5ce08c356b187c4d
4
- data.tar.gz: 61e89f8a1da9d831bf158333f7136c1c4b6faccf937daa8d8971d908f6731fd3
3
+ metadata.gz: cf5e10e9c9f1abd3279977ba3b70579241571ee0d7ba47705b3c2c4aac243e93
4
+ data.tar.gz: 118123aa977a92a9032406b43e5da60f4d0f946f3116964f633f3572c217c746
5
5
  SHA512:
6
- metadata.gz: 651b37bf06b3d54b5f8528620821cd48fc81ea86d8fab7f9ab5391ad0d2f441c2dacc21d56edbd4f259c759aaf2224c29852516c31fff840e99f66855080c545
7
- data.tar.gz: 122c24b8734c02b21351a06da76373c9b899bda89f738d04613f6d4c5267fc62d8b583bf9afaa127d2b1b793583610e5e660930261a0375f51f97c53ef0cc5c7
6
+ metadata.gz: 41739345915bd13a9d3be83fc8820562a61627b12173ebb7b287ef3ce61c07f5f4a50ebdc6a74e9d69de7754c18a2ce905e86439cad5a78ffad9620521406618
7
+ data.tar.gz: 9404df21b13cf754d949280a45f7a26d74cfe7e5ca4b555225bd76284defe41a3f14837d1fa90e3284fb16ee17f3ac03da92c6e15ae48a4034b1805a4c9b6f33
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Victor](/examples//15_victor_logo.svg)
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
- private
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
@@ -5,12 +5,7 @@
5
5
  xmlns="http://www.w3.org/2000/svg"
6
6
  xmlns:xlink="http://www.w3.org/1999/xlink">
7
7
 
8
- <style type="text/css">
9
- <![CDATA[
10
- %{css}
11
- ]]>
12
- </style>
13
-
8
+ %{style}
14
9
  %{content}
15
10
 
16
11
  </svg>
@@ -1,10 +1,4 @@
1
1
  <svg %{attributes}>
2
-
3
- <style type="text/css" scoped>
4
- <![CDATA[
5
- %{css}
6
- ]]>
7
- </style>
8
-
2
+ %{style}
9
3
  %{content}
10
4
  </svg>
@@ -1,3 +1,3 @@
1
1
  module Victor
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/victor.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'victor/version'
2
+ require 'victor/svg_base'
2
3
  require 'victor/svg'
3
4
  require 'victor/attributes'
4
5
  require 'victor/css'
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.3
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-08-02 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.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