drawio_dsl 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,188 +4,198 @@
4
4
  module DrawioDsl
5
5
  # DrawioDsl is a DSL for draw-io diagrams.
6
6
  module DomBuilderShapes
7
- def add_h1(**opts)
8
- h1 = DrawioDsl::Schema::H1.new(current_page, **opts)
7
+ def add_h1(**opts, &block)
8
+ h1 = DrawioDsl::Schema::H1.new(current_page, **opts, &block)
9
9
  add_shape(h1)
10
10
  end
11
11
 
12
- def add_h2(**opts)
13
- h2 = DrawioDsl::Schema::H2.new(current_page, **opts)
12
+ def add_h2(**opts, &block)
13
+ h2 = DrawioDsl::Schema::H2.new(current_page, **opts, &block)
14
14
  add_shape(h2)
15
15
  end
16
16
 
17
- def add_h3(**opts)
18
- h3 = DrawioDsl::Schema::H3.new(current_page, **opts)
17
+ def add_h3(**opts, &block)
18
+ h3 = DrawioDsl::Schema::H3.new(current_page, **opts, &block)
19
19
  add_shape(h3)
20
20
  end
21
21
 
22
- def add_h4(**opts)
23
- h4 = DrawioDsl::Schema::H4.new(current_page, **opts)
22
+ def add_h4(**opts, &block)
23
+ h4 = DrawioDsl::Schema::H4.new(current_page, **opts, &block)
24
24
  add_shape(h4)
25
25
  end
26
26
 
27
- def add_h5(**opts)
28
- h5 = DrawioDsl::Schema::H5.new(current_page, **opts)
27
+ def add_h5(**opts, &block)
28
+ h5 = DrawioDsl::Schema::H5.new(current_page, **opts, &block)
29
29
  add_shape(h5)
30
30
  end
31
31
 
32
- def add_h6(**opts)
33
- h6 = DrawioDsl::Schema::H6.new(current_page, **opts)
32
+ def add_h6(**opts, &block)
33
+ h6 = DrawioDsl::Schema::H6.new(current_page, **opts, &block)
34
34
  add_shape(h6)
35
35
  end
36
36
 
37
- def add_p(**opts)
38
- p = DrawioDsl::Schema::P.new(current_page, **opts)
37
+ def add_p(**opts, &block)
38
+ p = DrawioDsl::Schema::P.new(current_page, **opts, &block)
39
39
  add_shape(p)
40
40
  end
41
41
 
42
- def add_actor(**opts)
43
- actor = DrawioDsl::Schema::Actor.new(current_page, **opts)
42
+ def add_actor(**opts, &block)
43
+ actor = DrawioDsl::Schema::Actor.new(current_page, **opts, &block)
44
44
  add_shape(actor)
45
45
  end
46
46
 
47
- def add_actor2(**opts)
48
- actor2 = DrawioDsl::Schema::Actor2.new(current_page, **opts)
47
+ def add_actor2(**opts, &block)
48
+ actor2 = DrawioDsl::Schema::Actor2.new(current_page, **opts, &block)
49
49
  add_shape(actor2)
50
50
  end
51
51
 
52
- def add_callout(**opts)
53
- callout = DrawioDsl::Schema::Callout.new(current_page, **opts)
52
+ def add_callout(**opts, &block)
53
+ callout = DrawioDsl::Schema::Callout.new(current_page, **opts, &block)
54
54
  add_shape(callout)
55
55
  end
56
56
 
57
- def add_callout2(**opts)
58
- callout2 = DrawioDsl::Schema::Callout2.new(current_page, **opts)
57
+ def add_callout2(**opts, &block)
58
+ callout2 = DrawioDsl::Schema::Callout2.new(current_page, **opts, &block)
59
59
  add_shape(callout2)
60
60
  end
61
61
 
62
- def add_callout3(**opts)
63
- callout3 = DrawioDsl::Schema::Callout3.new(current_page, **opts)
62
+ def add_callout3(**opts, &block)
63
+ callout3 = DrawioDsl::Schema::Callout3.new(current_page, **opts, &block)
64
64
  add_shape(callout3)
65
65
  end
66
66
 
67
- def add_callout4(**opts)
68
- callout4 = DrawioDsl::Schema::Callout4.new(current_page, **opts)
67
+ def add_callout4(**opts, &block)
68
+ callout4 = DrawioDsl::Schema::Callout4.new(current_page, **opts, &block)
69
69
  add_shape(callout4)
70
70
  end
71
71
 
72
- def add_circle(**opts)
73
- circle = DrawioDsl::Schema::Circle.new(current_page, **opts)
72
+ def add_circle(**opts, &block)
73
+ circle = DrawioDsl::Schema::Circle.new(current_page, **opts, &block)
74
74
  add_shape(circle)
75
75
  end
76
76
 
77
- def add_cloud(**opts)
78
- cloud = DrawioDsl::Schema::Cloud.new(current_page, **opts)
77
+ def add_cloud(**opts, &block)
78
+ cloud = DrawioDsl::Schema::Cloud.new(current_page, **opts, &block)
79
79
  add_shape(cloud)
80
80
  end
81
81
 
82
- def add_cross(**opts)
83
- cross = DrawioDsl::Schema::Cross.new(current_page, **opts)
82
+ def add_container(**opts, &block)
83
+ container = DrawioDsl::Schema::Container.new(current_page, **opts, &block)
84
+ add_shape(container)
85
+ end
86
+
87
+ def add_container2(**opts, &block)
88
+ container2 = DrawioDsl::Schema::Container2.new(current_page, **opts, &block)
89
+ add_shape(container2)
90
+ end
91
+
92
+ def add_container3(**opts, &block)
93
+ container3 = DrawioDsl::Schema::Container3.new(current_page, **opts, &block)
94
+ add_shape(container3)
95
+ end
96
+
97
+ def add_container4(**opts, &block)
98
+ container4 = DrawioDsl::Schema::Container4.new(current_page, **opts, &block)
99
+ add_shape(container4)
100
+ end
101
+
102
+ def add_cross(**opts, &block)
103
+ cross = DrawioDsl::Schema::Cross.new(current_page, **opts, &block)
84
104
  add_shape(cross)
85
105
  end
86
106
 
87
- def add_envelop(**opts)
88
- envelop = DrawioDsl::Schema::Envelop.new(current_page, **opts)
107
+ def add_envelop(**opts, &block)
108
+ envelop = DrawioDsl::Schema::Envelop.new(current_page, **opts, &block)
89
109
  add_shape(envelop)
90
110
  end
91
111
 
92
- def add_diamond(**opts)
93
- diamond = DrawioDsl::Schema::Diamond.new(current_page, **opts)
112
+ def add_diamond(**opts, &block)
113
+ diamond = DrawioDsl::Schema::Diamond.new(current_page, **opts, &block)
94
114
  add_shape(diamond)
95
115
  end
96
116
 
97
- def add_document(**opts)
98
- document = DrawioDsl::Schema::Document.new(current_page, **opts)
117
+ def add_document(**opts, &block)
118
+ document = DrawioDsl::Schema::Document.new(current_page, **opts, &block)
99
119
  add_shape(document)
100
120
  end
101
121
 
102
- def add_ellipse(**opts)
103
- ellipse = DrawioDsl::Schema::Ellipse.new(current_page, **opts)
122
+ def add_ellipse(**opts, &block)
123
+ ellipse = DrawioDsl::Schema::Ellipse.new(current_page, **opts, &block)
104
124
  add_shape(ellipse)
105
125
  end
106
126
 
107
- def add_hexagon(**opts)
108
- hexagon = DrawioDsl::Schema::Hexagon.new(current_page, **opts)
127
+ def add_hexagon(**opts, &block)
128
+ hexagon = DrawioDsl::Schema::Hexagon.new(current_page, **opts, &block)
109
129
  add_shape(hexagon)
110
130
  end
111
131
 
112
- def add_container(**opts)
113
- container = DrawioDsl::Schema::Container.new(current_page, **opts)
114
- add_shape(container)
115
- end
116
-
117
- def add_container2(**opts)
118
- container2 = DrawioDsl::Schema::Container2.new(current_page, **opts)
119
- add_shape(container2)
132
+ def add_interface(**opts, &block)
133
+ interface = DrawioDsl::Schema::Interface.new(current_page, **opts, &block)
134
+ add_shape(interface)
120
135
  end
121
136
 
122
- def add_container3(**opts)
123
- container3 = DrawioDsl::Schema::Container3.new(current_page, **opts)
124
- add_shape(container3)
125
- end
126
-
127
- def add_container4(**opts)
128
- container4 = DrawioDsl::Schema::Container4.new(current_page, **opts)
129
- add_shape(container4)
137
+ def add_klass(**opts, &block)
138
+ klass = DrawioDsl::Schema::Klass.new(current_page, **opts, &block)
139
+ add_shape(klass)
130
140
  end
131
141
 
132
- def add_note(**opts)
133
- note = DrawioDsl::Schema::Note.new(current_page, **opts)
142
+ def add_note(**opts, &block)
143
+ note = DrawioDsl::Schema::Note.new(current_page, **opts, &block)
134
144
  add_shape(note)
135
145
  end
136
146
 
137
- def add_process(**opts)
138
- process = DrawioDsl::Schema::Process.new(current_page, **opts)
147
+ def add_process(**opts, &block)
148
+ process = DrawioDsl::Schema::Process.new(current_page, **opts, &block)
139
149
  add_shape(process)
140
150
  end
141
151
 
142
- def add_rectangle(**opts)
143
- rectangle = DrawioDsl::Schema::Rectangle.new(current_page, **opts)
152
+ def add_rectangle(**opts, &block)
153
+ rectangle = DrawioDsl::Schema::Rectangle.new(current_page, **opts, &block)
144
154
  add_shape(rectangle)
145
155
  end
146
156
 
147
- def add_rectangle2(**opts)
148
- rectangle2 = DrawioDsl::Schema::Rectangle2.new(current_page, **opts)
157
+ def add_rectangle2(**opts, &block)
158
+ rectangle2 = DrawioDsl::Schema::Rectangle2.new(current_page, **opts, &block)
149
159
  add_shape(rectangle2)
150
160
  end
151
161
 
152
- def add_square(**opts)
153
- square = DrawioDsl::Schema::Square.new(current_page, **opts)
162
+ def add_square(**opts, &block)
163
+ square = DrawioDsl::Schema::Square.new(current_page, **opts, &block)
154
164
  add_shape(square)
155
165
  end
156
166
 
157
- def add_step(**opts)
158
- step = DrawioDsl::Schema::Step.new(current_page, **opts)
167
+ def add_step(**opts, &block)
168
+ step = DrawioDsl::Schema::Step.new(current_page, **opts, &block)
159
169
  add_shape(step)
160
170
  end
161
171
 
162
- def add_tick(**opts)
163
- tick = DrawioDsl::Schema::Tick.new(current_page, **opts)
172
+ def add_tick(**opts, &block)
173
+ tick = DrawioDsl::Schema::Tick.new(current_page, **opts, &block)
164
174
  add_shape(tick)
165
175
  end
166
176
 
167
- def add_face(**opts)
168
- face = DrawioDsl::Schema::Face.new(current_page, **opts)
177
+ def add_face(**opts, &block)
178
+ face = DrawioDsl::Schema::Face.new(current_page, **opts, &block)
169
179
  add_shape(face)
170
180
  end
171
181
 
172
- def add_triangle(**opts)
173
- triangle = DrawioDsl::Schema::Triangle.new(current_page, **opts)
182
+ def add_triangle(**opts, &block)
183
+ triangle = DrawioDsl::Schema::Triangle.new(current_page, **opts, &block)
174
184
  add_shape(triangle)
175
185
  end
176
186
 
177
- def add_embed_row(**opts)
178
- embed_row = DrawioDsl::Schema::EmbedRow.new(current_page, **opts)
187
+ def add_embed_row(**opts, &block)
188
+ embed_row = DrawioDsl::Schema::EmbedRow.new(current_page, **opts, &block)
179
189
  add_shape(embed_row)
180
190
  end
181
191
 
182
- def add_embed_col50(**opts)
183
- embed_col50 = DrawioDsl::Schema::EmbedCol50.new(current_page, **opts)
192
+ def add_embed_col50(**opts, &block)
193
+ embed_col50 = DrawioDsl::Schema::EmbedCol50.new(current_page, **opts, &block)
184
194
  add_shape(embed_col50)
185
195
  end
186
196
 
187
- def add_embed_col200(**opts)
188
- embed_col200 = DrawioDsl::Schema::EmbedCol200.new(current_page, **opts)
197
+ def add_embed_col200(**opts, &block)
198
+ embed_col200 = DrawioDsl::Schema::EmbedCol200.new(current_page, **opts, &block)
189
199
  add_shape(embed_col200)
190
200
  end
191
201
  end
@@ -5,7 +5,7 @@ module DrawioDsl
5
5
  # :nocov:
6
6
  module DrawioShapes
7
7
  def random(**opts)
8
- case rand(37)
8
+ case rand(39)
9
9
  when 0
10
10
  h1(**opts)
11
11
  when 1
@@ -37,198 +37,210 @@ module DrawioDsl
37
37
  when 14
38
38
  cloud(**opts)
39
39
  when 15
40
- cross(**opts)
40
+ container(**opts)
41
41
  when 16
42
- envelop(**opts)
42
+ container2(**opts)
43
43
  when 17
44
- diamond(**opts)
44
+ container3(**opts)
45
45
  when 18
46
- document(**opts)
46
+ container4(**opts)
47
47
  when 19
48
- ellipse(**opts)
48
+ cross(**opts)
49
49
  when 20
50
- hexagon(**opts)
50
+ envelop(**opts)
51
51
  when 21
52
- container(**opts)
52
+ diamond(**opts)
53
53
  when 22
54
- container2(**opts)
54
+ document(**opts)
55
55
  when 23
56
- container3(**opts)
56
+ ellipse(**opts)
57
57
  when 24
58
- container4(**opts)
58
+ hexagon(**opts)
59
59
  when 25
60
- note(**opts)
60
+ interface(**opts)
61
61
  when 26
62
- process(**opts)
62
+ klass(**opts)
63
63
  when 27
64
- rectangle(**opts)
64
+ note(**opts)
65
65
  when 28
66
- rectangle2(**opts)
66
+ process(**opts)
67
67
  when 29
68
- square(**opts)
68
+ rectangle(**opts)
69
69
  when 30
70
- step(**opts)
70
+ rectangle2(**opts)
71
71
  when 31
72
- tick(**opts)
72
+ square(**opts)
73
73
  when 32
74
- face(**opts)
74
+ step(**opts)
75
75
  when 33
76
- triangle(**opts)
76
+ tick(**opts)
77
77
  when 34
78
- embed_row(**opts)
78
+ face(**opts)
79
79
  when 35
80
- embed_col50(**opts)
80
+ triangle(**opts)
81
81
  when 36
82
+ embed_row(**opts)
83
+ when 37
84
+ embed_col50(**opts)
85
+ when 38
82
86
  embed_col200(**opts)
83
87
  end
84
88
  end
85
89
 
86
- def h1(**opts)
87
- builder.add_h1(**opts)
90
+ def h1(**opts, &block)
91
+ builder.add_h1(**opts, &block)
92
+ end
93
+
94
+ def h2(**opts, &block)
95
+ builder.add_h2(**opts, &block)
96
+ end
97
+
98
+ def h3(**opts, &block)
99
+ builder.add_h3(**opts, &block)
88
100
  end
89
101
 
90
- def h2(**opts)
91
- builder.add_h2(**opts)
102
+ def h4(**opts, &block)
103
+ builder.add_h4(**opts, &block)
92
104
  end
93
105
 
94
- def h3(**opts)
95
- builder.add_h3(**opts)
106
+ def h5(**opts, &block)
107
+ builder.add_h5(**opts, &block)
96
108
  end
97
109
 
98
- def h4(**opts)
99
- builder.add_h4(**opts)
110
+ def h6(**opts, &block)
111
+ builder.add_h6(**opts, &block)
100
112
  end
101
113
 
102
- def h5(**opts)
103
- builder.add_h5(**opts)
114
+ def p(**opts, &block)
115
+ builder.add_p(**opts, &block)
104
116
  end
105
117
 
106
- def h6(**opts)
107
- builder.add_h6(**opts)
118
+ def actor(**opts, &block)
119
+ builder.add_actor(**opts, &block)
108
120
  end
109
121
 
110
- def p(**opts)
111
- builder.add_p(**opts)
122
+ def actor2(**opts, &block)
123
+ builder.add_actor2(**opts, &block)
112
124
  end
113
125
 
114
- def actor(**opts)
115
- builder.add_actor(**opts)
126
+ def callout(**opts, &block)
127
+ builder.add_callout(**opts, &block)
116
128
  end
117
129
 
118
- def actor2(**opts)
119
- builder.add_actor2(**opts)
130
+ def callout2(**opts, &block)
131
+ builder.add_callout2(**opts, &block)
120
132
  end
121
133
 
122
- def callout(**opts)
123
- builder.add_callout(**opts)
134
+ def callout3(**opts, &block)
135
+ builder.add_callout3(**opts, &block)
124
136
  end
125
137
 
126
- def callout2(**opts)
127
- builder.add_callout2(**opts)
138
+ def callout4(**opts, &block)
139
+ builder.add_callout4(**opts, &block)
128
140
  end
129
141
 
130
- def callout3(**opts)
131
- builder.add_callout3(**opts)
142
+ def circle(**opts, &block)
143
+ builder.add_circle(**opts, &block)
132
144
  end
133
145
 
134
- def callout4(**opts)
135
- builder.add_callout4(**opts)
146
+ def cloud(**opts, &block)
147
+ builder.add_cloud(**opts, &block)
136
148
  end
137
149
 
138
- def circle(**opts)
139
- builder.add_circle(**opts)
150
+ def container(**opts, &block)
151
+ builder.add_container(**opts, &block)
140
152
  end
141
153
 
142
- def cloud(**opts)
143
- builder.add_cloud(**opts)
154
+ def container2(**opts, &block)
155
+ builder.add_container2(**opts, &block)
144
156
  end
145
157
 
146
- def cross(**opts)
147
- builder.add_cross(**opts)
158
+ def container3(**opts, &block)
159
+ builder.add_container3(**opts, &block)
148
160
  end
149
161
 
150
- def envelop(**opts)
151
- builder.add_envelop(**opts)
162
+ def container4(**opts, &block)
163
+ builder.add_container4(**opts, &block)
152
164
  end
153
165
 
154
- def diamond(**opts)
155
- builder.add_diamond(**opts)
166
+ def cross(**opts, &block)
167
+ builder.add_cross(**opts, &block)
156
168
  end
157
169
 
158
- def document(**opts)
159
- builder.add_document(**opts)
170
+ def envelop(**opts, &block)
171
+ builder.add_envelop(**opts, &block)
160
172
  end
161
173
 
162
- def ellipse(**opts)
163
- builder.add_ellipse(**opts)
174
+ def diamond(**opts, &block)
175
+ builder.add_diamond(**opts, &block)
164
176
  end
165
177
 
166
- def hexagon(**opts)
167
- builder.add_hexagon(**opts)
178
+ def document(**opts, &block)
179
+ builder.add_document(**opts, &block)
168
180
  end
169
181
 
170
- def container(**opts)
171
- builder.add_container(**opts)
182
+ def ellipse(**opts, &block)
183
+ builder.add_ellipse(**opts, &block)
172
184
  end
173
185
 
174
- def container2(**opts)
175
- builder.add_container2(**opts)
186
+ def hexagon(**opts, &block)
187
+ builder.add_hexagon(**opts, &block)
176
188
  end
177
189
 
178
- def container3(**opts)
179
- builder.add_container3(**opts)
190
+ def interface(**opts, &block)
191
+ builder.add_interface(**opts, &block)
180
192
  end
181
193
 
182
- def container4(**opts)
183
- builder.add_container4(**opts)
194
+ def klass(**opts, &block)
195
+ builder.add_klass(**opts, &block)
184
196
  end
185
197
 
186
- def note(**opts)
187
- builder.add_note(**opts)
198
+ def note(**opts, &block)
199
+ builder.add_note(**opts, &block)
188
200
  end
189
201
 
190
- def process(**opts)
191
- builder.add_process(**opts)
202
+ def process(**opts, &block)
203
+ builder.add_process(**opts, &block)
192
204
  end
193
205
 
194
- def rectangle(**opts)
195
- builder.add_rectangle(**opts)
206
+ def rectangle(**opts, &block)
207
+ builder.add_rectangle(**opts, &block)
196
208
  end
197
209
 
198
- def rectangle2(**opts)
199
- builder.add_rectangle2(**opts)
210
+ def rectangle2(**opts, &block)
211
+ builder.add_rectangle2(**opts, &block)
200
212
  end
201
213
 
202
- def square(**opts)
203
- builder.add_square(**opts)
214
+ def square(**opts, &block)
215
+ builder.add_square(**opts, &block)
204
216
  end
205
217
 
206
- def step(**opts)
207
- builder.add_step(**opts)
218
+ def step(**opts, &block)
219
+ builder.add_step(**opts, &block)
208
220
  end
209
221
 
210
- def tick(**opts)
211
- builder.add_tick(**opts)
222
+ def tick(**opts, &block)
223
+ builder.add_tick(**opts, &block)
212
224
  end
213
225
 
214
- def face(**opts)
215
- builder.add_face(**opts)
226
+ def face(**opts, &block)
227
+ builder.add_face(**opts, &block)
216
228
  end
217
229
 
218
- def triangle(**opts)
219
- builder.add_triangle(**opts)
230
+ def triangle(**opts, &block)
231
+ builder.add_triangle(**opts, &block)
220
232
  end
221
233
 
222
- def embed_row(**opts)
223
- builder.add_embed_row(**opts)
234
+ def embed_row(**opts, &block)
235
+ builder.add_embed_row(**opts, &block)
224
236
  end
225
237
 
226
- def embed_col50(**opts)
227
- builder.add_embed_col50(**opts)
238
+ def embed_col50(**opts, &block)
239
+ builder.add_embed_col50(**opts, &block)
228
240
  end
229
241
 
230
- def embed_col200(**opts)
231
- builder.add_embed_col200(**opts)
242
+ def embed_col200(**opts, &block)
243
+ builder.add_embed_col200(**opts, &block)
232
244
  end
233
245
  end
234
246
  # :nocov:
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'style_builder'
4
+ require_relative 'html_builder'
5
+ require_relative 'base_formatter'
6
+ require_relative 'klass_formatter'
7
+ require_relative 'interface_formatter'
8
+ require_relative 'factory'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Work with HTML formatters to DrawIO shapes
4
+ module DrawioDsl
5
+ # HTML formatters can be used on shapes to render HTML using a DSL
6
+ module Formatters
7
+ # Create an instance of a HTML formatter on the shape
8
+ class BaseFormatter
9
+ attr_reader :html
10
+
11
+ def initialize(element_style_defaults = {})
12
+ @html = DrawioDsl::Formatters::HtmlBuilder.new(element_style_defaults)
13
+ end
14
+
15
+ def empty?
16
+ html.empty?
17
+ end
18
+
19
+ def as_html(new_line: false)
20
+ html.as_html(new_line: new_line)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Work with HTML formatters to DrawIO shapes
4
+ module DrawioDsl
5
+ # HTML formatters can be used on shapes to render HTML using a DSL
6
+ module Formatters
7
+ # Create an instance of a HTML formatter on the shape
8
+ module Factory
9
+ include KLog::Logging
10
+
11
+ FORMATTERS = {
12
+ class: DrawioDsl::Formatters::KlassFormatter,
13
+ interface: DrawioDsl::Formatters::InterfaceFormatter
14
+ }.freeze
15
+
16
+ def format(type)
17
+ unless FORMATTERS.key?(type)
18
+ log.error "Unknown formatter type: #{type}"
19
+ @formatter = nil
20
+ return formatter
21
+ end
22
+
23
+ @formatter = FORMATTERS[type].new
24
+ formatter
25
+ end
26
+
27
+ def formatter
28
+ @formatter ||= DrawioDsl::Formatters::BaseFormatter.new
29
+ end
30
+ end
31
+ end
32
+ end