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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/svgstack.rb +67 -19
- metadata +23 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f001010e568240312f529e6df2ce88f7d083b789342a759abcfd4ea92d1616
|
4
|
+
data.tar.gz: 158ba28544bc45395b63b1004c2e5f0744f9145c97320b963b12f4adecf17d5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a426512df54ef7f16b3765025eef9e473e46f33d296b78fd3652d31071604e32f1315bdec74558f628a1b6c2bc853cc77350d3dfd55688918cd89067ea573748
|
7
|
+
data.tar.gz: '084a5da20e0f8e8ef3189ce81718b2eb07dc305fa23c9972f28dff19b34a490424ae26d593fdd36c4d1d7c1f2906d7c6b622b78c082d498bce9c5ef4c93607ad'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/svgstack.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
@
|
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
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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(
|
99
|
+
def build(layers)
|
62
100
|
|
63
101
|
y = 0
|
64
102
|
|
65
|
-
|
103
|
+
layers.reverse.each do |label, url|
|
66
104
|
|
67
105
|
@svg.g do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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.
|
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-
|
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:
|
109
|
+
summary: Creates a stack using SVG.
|
90
110
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|