svgstack 0.1.1 → 0.2.0

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: ad4ff843110d0f458af2c7328e96804b0c13e8292e5594af777ca0985c306171
4
- data.tar.gz: 2aa80a53cf8e23a6657e1ba3d2acb35c7c1542f0738813d2a1336314cea97041
3
+ metadata.gz: f1f001010e568240312f529e6df2ce88f7d083b789342a759abcfd4ea92d1616
4
+ data.tar.gz: 158ba28544bc45395b63b1004c2e5f0744f9145c97320b963b12f4adecf17d5a
5
5
  SHA512:
6
- metadata.gz: 23e4f3ccc0b18c78e3b69f5681cc9122c82b5c73c66e3a2f7b1ee7ad082132ee5f1cb13cd5d6320f43f276af9525ab024888dd014f03fcf8a7153d8c97965d7c
7
- data.tar.gz: 0be5f5b38b47a74cbc239c9d3518fe6195c392e02f3bdc214a37459d5e1bf143464351e018076ae1705d45c10fd740737bc2e9e9769846a1ce55a5a9bb12349d
6
+ metadata.gz: a426512df54ef7f16b3765025eef9e473e46f33d296b78fd3652d31071604e32f1315bdec74558f628a1b6c2bc853cc77350d3dfd55688918cd89067ea573748
7
+ data.tar.gz: '084a5da20e0f8e8ef3189ce81718b2eb07dc305fa23c9972f28dff19b34a490424ae26d593fdd36c4d1d7c1f2906d7c6b622b78c082d498bce9c5ef4c93607ad'
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,6 +5,7 @@
5
5
  # description: A 1st attempt at creating a stack using SVG
6
6
 
7
7
  require 'victor'
8
+ require 'dynarex'
8
9
 
9
10
 
10
11
  module RegGem
@@ -26,14 +27,9 @@ class SvgStack
26
27
  attr_accessor :css
27
28
 
28
29
  def initialize(data=nil, x: 0, y: 0, width: 150, height: nil)
29
-
30
- boxes = data if data.is_a? Array
31
30
 
32
- height ||= (boxes.length * 50) + 50
33
-
34
- @svg = Victor::SVG.new viewBox: [x, y, width, height].join(' ')
35
- @boxwidth = width
36
- build boxes
31
+
32
+ @x, @y, @width, @height = x, y, width, height
37
33
 
38
34
  @css = "
39
35
  rect {
@@ -43,38 +39,90 @@ class SvgStack
43
39
  text { fill: blue}
44
40
  "
45
41
 
42
+ if data then
43
+ @boxes = data
44
+ @doc = render()
45
+ end
46
+
47
+
46
48
  end
49
+
50
+ def import(s)
51
+
52
+ s2 = s.slice(/<\?svgstack [^>]*\?>/)
47
53
 
48
- def save(file='untitled')
54
+ if s2 then
55
+
56
+ attributes = %w(delimiter id schema).inject({}) do |r, keyword|
57
+ found = s2[/(?<=#{keyword}=['"])[^'"]+/]
58
+ found ? r.merge(keyword.to_sym => found) : r
59
+ end
60
+
61
+ end
49
62
 
50
- @svg.save file
63
+ @dx = Dynarex.new s.sub(/svgstack/, 'dynarex')
64
+ @boxes = @dx.to_h.to_a.reverse
65
+ @doc = render()
66
+
67
+ end
68
+
69
+ def render()
51
70
 
52
- #inject the css
71
+ @height ||= (@boxes.length * 50) + 50
72
+
73
+ @svg = Victor::SVG.new viewBox: [@x, @y, @width, @height].join(' ')
74
+
75
+ build @boxes
53
76
 
54
- s = File.read file
55
- s2 = s.lines.insert 7, css_code()
56
- File.write file, s2.join
77
+ end
78
+
79
+ def save(file='untitled')
80
+ File.write file, @doc
81
+ end
82
+
83
+ def to_svg()
84
+ @doc
57
85
  end
58
86
 
59
87
  private
88
+
89
+ def add_box(label, y)
90
+
91
+ boxwidth = @width
92
+
93
+ @svg.rect(x: 0, y: y, width: boxwidth, height: 40)
94
+ @svg.text label, {x: boxwidth / 2, y: y+20, font_family: 'arial',
95
+ font_weight: 'bold', font_size: 20,
96
+ :"dominant-baseline" => "middle", :"text-anchor" => "middle"}
97
+ end
60
98
 
61
- def build(labels)
99
+ def build(layers)
62
100
 
63
101
  y = 0
64
102
 
65
- labels.reverse.each do |label|
103
+ layers.reverse.each do |label, url|
66
104
 
67
105
  @svg.g do
68
- @svg.rect x: 0, y: y, width: @boxwidth, height: 40
69
- @svg.text label, {x: @boxwidth / 2, y: y+20, font_family: 'arial',
70
- font_weight: 'bold', font_size: 20,
71
- :"dominant-baseline" => "middle", :"text-anchor" => "middle"}
106
+
107
+ if url then
108
+
109
+ @svg.a(href: url) do
110
+ add_box(label, y)
111
+ end
112
+
113
+ else
114
+ add_box(label, y)
115
+ end
72
116
 
73
117
  end
74
118
 
75
119
  y+=50
76
120
 
77
121
  end
122
+
123
+ #inject the css
124
+
125
+ @svg.render.lines.insert(7, css_code()).join
78
126
 
79
127
  end
80
128
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  /t04zmFjtiFj2Zd4pHZCw0lFsUaO9SEZpWpWqWQpOSoonkVFhiZL1DTTEqmGq2HS
36
36
  cW6mXMQVJTv3bDf0prQ7jjkt
37
37
  -----END CERTIFICATE-----
38
- date: 2019-06-04 00:00:00.000000000 Z
38
+ date: 2019-06-05 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: victor
@@ -57,6 +57,26 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 0.2.6
60
+ - !ruby/object:Gem::Dependency
61
+ name: dynarex
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.8'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.19
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.8'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.8.19
60
80
  description:
61
81
  email: james@jamesrobertson.eu
62
82
  executables: []
@@ -86,5 +106,5 @@ requirements: []
86
106
  rubygems_version: 3.0.1
87
107
  signing_key:
88
108
  specification_version: 4
89
- summary: A 1st attempt at creating a stack using SVG. Under development.
109
+ summary: Creates a stack using SVG.
90
110
  test_files: []
metadata.gz.sig CHANGED
Binary file