drawio_dsl 0.5.0 → 0.5.3

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/.data/shapes.json +119 -2
  3. data/.builders/.templates/basic/configuration_shapes.rb +3 -3
  4. data/.builders/.templates/basic/schema_require.rb +1 -0
  5. data/.builders/blueprint/shapes.rb +42 -28
  6. data/.builders/generators/02-generate-app.rb +2 -0
  7. data/.builders/generators/project_plans/drawio_dsl.rb +24 -0
  8. data/.builders/generators/sample_diagrams/50-willoughby-council.rb +52 -0
  9. data/.rubocop.yml +5 -0
  10. data/CHANGELOG.md +23 -0
  11. data/lib/drawio_dsl/configuration_shapes.rb +49 -29
  12. data/lib/drawio_dsl/dom_builder.rb +5 -5
  13. data/lib/drawio_dsl/dom_builder_shapes.rb +50 -0
  14. data/lib/drawio_dsl/drawio_shapes.rb +87 -27
  15. data/lib/drawio_dsl/layout_engine.rb +1 -8
  16. data/lib/drawio_dsl/schema/_.rb +11 -0
  17. data/lib/drawio_dsl/schema/layouts/grid_layout.rb +17 -10
  18. data/lib/drawio_dsl/schema/node.rb +29 -24
  19. data/lib/drawio_dsl/schema/node_list.rb +37 -0
  20. data/lib/drawio_dsl/schema/page.rb +5 -5
  21. data/lib/drawio_dsl/schema/shapes/embed_col200.rb +9 -0
  22. data/lib/drawio_dsl/schema/shapes/embed_col50.rb +9 -0
  23. data/lib/drawio_dsl/schema/shapes/embed_row.rb +9 -0
  24. data/lib/drawio_dsl/schema/shapes/h1.rb +9 -0
  25. data/lib/drawio_dsl/schema/shapes/h2.rb +9 -0
  26. data/lib/drawio_dsl/schema/shapes/h3.rb +9 -0
  27. data/lib/drawio_dsl/schema/shapes/h4.rb +9 -0
  28. data/lib/drawio_dsl/schema/shapes/h5.rb +9 -0
  29. data/lib/drawio_dsl/schema/shapes/h6.rb +9 -0
  30. data/lib/drawio_dsl/schema/shapes/p.rb +9 -0
  31. data/lib/drawio_dsl/schema/shapes/shape.rb +15 -4
  32. data/lib/drawio_dsl/version.rb +1 -1
  33. data/lib/drawio_dsl/xml_builder.rb +2 -12
  34. data/package-lock.json +2 -2
  35. data/package.json +1 -1
  36. metadata +15 -2
@@ -5,9 +5,16 @@
5
5
  module DrawioDsl
6
6
  # Used to attach configuration to KConfig module
7
7
  module ConfigurationShapes
8
- ShapeDefaults = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
8
+ ShapeDefaults = Struct.new(:type, :text_only, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
9
9
  Shapes = Struct.new(
10
10
  :shape,
11
+ :h1,
12
+ :h2,
13
+ :h3,
14
+ :h4,
15
+ :h5,
16
+ :h6,
17
+ :p,
11
18
  :actor,
12
19
  :actor2,
13
20
  :callout,
@@ -35,39 +42,52 @@ module DrawioDsl
35
42
  :tick,
36
43
  :face,
37
44
  :triangle,
45
+ :embed_row,
46
+ :embed_col50,
47
+ :embed_col200,
38
48
  keyword_init: true
39
49
  )
40
50
 
41
51
  def add_shapes
42
52
  @shapes = Shapes.new(
43
- shape: ShapeDefaults.new(type: :shape, x: 0, y: 0, w: 20, h: 20, style_modifiers: ''),
44
- actor: ShapeDefaults.new(type: :actor, x: 0, y: 0, w: 40, h: 50, style_modifiers: 'shape=actor'),
45
- actor2: ShapeDefaults.new(type: :actor2, x: 0, y: 0, w: 30, h: 50, style_modifiers: 'shape=umlActor;verticalLabelPosition=bottom;outlineConnect=1'),
46
- callout: ShapeDefaults.new(type: :callout, x: 0, y: 0, w: 160, h: 120, style_modifiers: 'shape=callout'),
47
- callout2: ShapeDefaults.new(type: :callout2, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.oval_callout'),
48
- callout3: ShapeDefaults.new(type: :callout3, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.cloud_callout'),
49
- callout4: ShapeDefaults.new(type: :callout4, x: 0, y: 0, w: 160, h: 120, style_modifiers: 'shape=mxgraph.basic.roundRectCallout;dx=30;dy=15;size=5;boundedLbl=1;'),
50
- circle: ShapeDefaults.new(type: :circle, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'ellipse'),
51
- cloud: ShapeDefaults.new(type: :cloud, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'shape=cloud'),
52
- cross: ShapeDefaults.new(type: :cross, x: 0, y: 0, w: 50, h: 50, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;html=1;shape=mxgraph.basic.x'),
53
- envelop: ShapeDefaults.new(type: :envelop, x: 0, y: 0, w: 160, h: 100, style_modifiers: 'shape=message'),
54
- diamond: ShapeDefaults.new(type: :diamond, x: 0, y: 0, w: 100, h: 100, style_modifiers: 'rhombus'),
55
- document: ShapeDefaults.new(type: :document, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.document'),
56
- ellipse: ShapeDefaults.new(type: :ellipse, x: 0, y: 0, w: 200, h: 120, style_modifiers: 'ellipse'),
57
- hexagon: ShapeDefaults.new(type: :hexagon, x: 0, y: 0, w: 200, h: 120, style_modifiers: 'shape=hexagon'),
58
- container: ShapeDefaults.new(type: :container, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;horizontal=0'),
59
- container2: ShapeDefaults.new(type: :container2, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'swimlane'),
60
- container3: ShapeDefaults.new(type: :container3, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;startSize=50'),
61
- container4: ShapeDefaults.new(type: :container4, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;resizable=0'),
62
- note: ShapeDefaults.new(type: :note, x: 0, y: 0, w: 160, h: 160, style_modifiers: 'shape=note'),
63
- process: ShapeDefaults.new(type: :process, x: 0, y: 0, w: 200, h: 120, style_modifiers: 'shape=process'),
64
- rectangle: ShapeDefaults.new(type: :rectangle, x: 0, y: 0, w: 200, h: 120, style_modifiers: ''),
65
- rectangle2: ShapeDefaults.new(type: :rectangle2, x: 0, y: 0, w: 200, h: 120, style_modifiers: 'shape=mxgraph.basic.cloud_rect'),
66
- square: ShapeDefaults.new(type: :square, x: 0, y: 0, w: 160, h: 160, style_modifiers: ''),
67
- step: ShapeDefaults.new(type: :step, x: 0, y: 0, w: 120, h: 80, style_modifiers: 'shape=step;perimeter=stepPerimeter;fixedSize=1'),
68
- tick: ShapeDefaults.new(type: :tick, x: 0, y: 0, w: 50, h: 50, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;shape=mxgraph.basic.tick'),
69
- face: ShapeDefaults.new(type: :face, x: 0, y: 0, w: 100, h: 100, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;shape=mxgraph.basic.smiley'),
70
- triangle: ShapeDefaults.new(type: :triangle, x: 0, y: 0, w: 100, h: 100, style_modifiers: 'triangle')
53
+ shape: ShapeDefaults.new(type: :shape, text_only: false, x: 0, y: 0, w: 20, h: 20, style_modifiers: ''),
54
+ h1: ShapeDefaults.new(type: :h1, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=89;fontColor=#ffffff;fontStyle=1;fillColor=none'),
55
+ h2: ShapeDefaults.new(type: :h2, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=67;fontColor=#ffffff;fontStyle=1;fillColor=none'),
56
+ h3: ShapeDefaults.new(type: :h3, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=50;fontColor=#ffffff;fontStyle=1;fillColor=none'),
57
+ h4: ShapeDefaults.new(type: :h4, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=37;fontColor=#ffffff;fontStyle=1;fillColor=none'),
58
+ h5: ShapeDefaults.new(type: :h5, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=28;fontColor=#ffffff;fontStyle=1;fillColor=none'),
59
+ h6: ShapeDefaults.new(type: :h6, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=21;fontColor=#ffffff;fontStyle=1;fillColor=none'),
60
+ p: ShapeDefaults.new(type: :p, x: 0, text_only: true, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=16;fontColor=#ffffff;fontStyle=1;fillColor=none'),
61
+ actor: ShapeDefaults.new(type: :actor, x: 0, text_only: false, y: 0, w: 40, h: 50, style_modifiers: 'shape=actor'),
62
+ actor2: ShapeDefaults.new(type: :actor2, x: 0, text_only: false, y: 0, w: 30, h: 50, style_modifiers: 'shape=umlActor;verticalLabelPosition=bottom;outlineConnect=1'),
63
+ callout: ShapeDefaults.new(type: :callout, x: 0, text_only: false, y: 0, w: 160, h: 120, style_modifiers: 'shape=callout'),
64
+ callout2: ShapeDefaults.new(type: :callout2, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.oval_callout'),
65
+ callout3: ShapeDefaults.new(type: :callout3, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.cloud_callout'),
66
+ callout4: ShapeDefaults.new(type: :callout4, x: 0, text_only: false, y: 0, w: 160, h: 120, style_modifiers: 'shape=mxgraph.basic.roundRectCallout;dx=30;dy=15;size=5;boundedLbl=1;'),
67
+ circle: ShapeDefaults.new(type: :circle, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'ellipse'),
68
+ cloud: ShapeDefaults.new(type: :cloud, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'shape=cloud'),
69
+ cross: ShapeDefaults.new(type: :cross, x: 0, text_only: false, y: 0, w: 50, h: 50, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;html=1;shape=mxgraph.basic.x'),
70
+ envelop: ShapeDefaults.new(type: :envelop, x: 0, text_only: false, y: 0, w: 160, h: 100, style_modifiers: 'shape=message'),
71
+ diamond: ShapeDefaults.new(type: :diamond, x: 0, text_only: false, y: 0, w: 100, h: 100, style_modifiers: 'rhombus'),
72
+ document: ShapeDefaults.new(type: :document, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'shape=mxgraph.basic.document'),
73
+ ellipse: ShapeDefaults.new(type: :ellipse, x: 0, text_only: false, y: 0, w: 200, h: 120, style_modifiers: 'ellipse'),
74
+ hexagon: ShapeDefaults.new(type: :hexagon, x: 0, text_only: false, y: 0, w: 200, h: 120, style_modifiers: 'shape=hexagon'),
75
+ container: ShapeDefaults.new(type: :container, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'swimlane'),
76
+ container2: ShapeDefaults.new(type: :container2, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;horizontal=0'),
77
+ container3: ShapeDefaults.new(type: :container3, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;startSize=50'),
78
+ container4: ShapeDefaults.new(type: :container4, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'swimlane;resizable=0'),
79
+ note: ShapeDefaults.new(type: :note, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: 'shape=note'),
80
+ process: ShapeDefaults.new(type: :process, x: 0, text_only: false, y: 0, w: 200, h: 120, style_modifiers: 'shape=process'),
81
+ rectangle: ShapeDefaults.new(type: :rectangle, x: 0, text_only: false, y: 0, w: 200, h: 120, style_modifiers: ''),
82
+ rectangle2: ShapeDefaults.new(type: :rectangle2, x: 0, text_only: false, y: 0, w: 200, h: 120, style_modifiers: 'shape=mxgraph.basic.cloud_rect'),
83
+ square: ShapeDefaults.new(type: :square, x: 0, text_only: false, y: 0, w: 160, h: 160, style_modifiers: ''),
84
+ step: ShapeDefaults.new(type: :step, x: 0, text_only: false, y: 0, w: 120, h: 80, style_modifiers: 'shape=step;perimeter=stepPerimeter;fixedSize=1'),
85
+ tick: ShapeDefaults.new(type: :tick, x: 0, text_only: false, y: 0, w: 50, h: 50, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;shape=mxgraph.basic.tick'),
86
+ face: ShapeDefaults.new(type: :face, x: 0, text_only: false, y: 0, w: 100, h: 100, style_modifiers: 'verticalLabelPosition=bottom;verticalAlign=top;shape=mxgraph.basic.smiley'),
87
+ triangle: ShapeDefaults.new(type: :triangle, x: 0, text_only: false, y: 0, w: 100, h: 100, style_modifiers: 'triangle'),
88
+ embed_row: ShapeDefaults.new(type: :embed_row, x: 0, text_only: false, y: 0, w: 200, h: 40, style_modifiers: 'shape=partialRectangle;collapsible=0;dropTarget=0;pointerEvents=0;top=0;left=0;bottom=1;right=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest'),
89
+ embed_col50: ShapeDefaults.new(type: :embed_col50, x: 0, text_only: false, y: 0, w: 50, h: 40, style_modifiers: 'shape=partialRectangle;connectable=0;top=0;left=0;bottom=0;right=0;fontStyle=1;overflow=hidden'),
90
+ embed_col200: ShapeDefaults.new(type: :embed_col200, x: 0, text_only: false, y: 0, w: 150, h: 40, style_modifiers: 'shape=partialRectangle;connectable=0;top=0;left=0;bottom=0;right=0;align=left;spacingLeft=6;overflow=hidden')
71
91
  )
72
92
  end
73
93
  end
@@ -54,20 +54,20 @@ module DrawioDsl
54
54
 
55
55
  def add_grid_layout(**opts)
56
56
  rule = DrawioDsl::Schema::GridLayout.new(current_page, **opts)
57
- add_layout_rule(rule)
57
+ add_layout(rule)
58
58
  end
59
59
 
60
60
  def add_flex_layout(**opts)
61
61
  rule = DrawioDsl::Schema::FlexLayout.new(current_page, **opts)
62
- add_layout_rule(rule)
62
+ add_layout(rule)
63
63
  end
64
64
 
65
- def add_layout_rule(rule)
65
+ def add_layout(rule)
66
66
  @current_layout_rule = rule
67
67
 
68
68
  rule.id = "rule-#{current_page.nodes.length + 1}" unless rule.id
69
69
 
70
- current_page.nodes << rule
70
+ current_page.nodes.add(rule)
71
71
 
72
72
  rule
73
73
  end
@@ -81,7 +81,7 @@ module DrawioDsl
81
81
 
82
82
  shape.id = "#{current_page.id}-#{current_page.nodes.length + 1}" unless shape.id
83
83
 
84
- current_page.nodes << shape
84
+ current_page.nodes.add(shape)
85
85
 
86
86
  shape
87
87
  end
@@ -4,6 +4,41 @@
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)
9
+ add_shape(h1)
10
+ end
11
+
12
+ def add_h2(**opts)
13
+ h2 = DrawioDsl::Schema::H2.new(current_page, **opts)
14
+ add_shape(h2)
15
+ end
16
+
17
+ def add_h3(**opts)
18
+ h3 = DrawioDsl::Schema::H3.new(current_page, **opts)
19
+ add_shape(h3)
20
+ end
21
+
22
+ def add_h4(**opts)
23
+ h4 = DrawioDsl::Schema::H4.new(current_page, **opts)
24
+ add_shape(h4)
25
+ end
26
+
27
+ def add_h5(**opts)
28
+ h5 = DrawioDsl::Schema::H5.new(current_page, **opts)
29
+ add_shape(h5)
30
+ end
31
+
32
+ def add_h6(**opts)
33
+ h6 = DrawioDsl::Schema::H6.new(current_page, **opts)
34
+ add_shape(h6)
35
+ end
36
+
37
+ def add_p(**opts)
38
+ p = DrawioDsl::Schema::P.new(current_page, **opts)
39
+ add_shape(p)
40
+ end
41
+
7
42
  def add_actor(**opts)
8
43
  actor = DrawioDsl::Schema::Actor.new(current_page, **opts)
9
44
  add_shape(actor)
@@ -138,6 +173,21 @@ module DrawioDsl
138
173
  triangle = DrawioDsl::Schema::Triangle.new(current_page, **opts)
139
174
  add_shape(triangle)
140
175
  end
176
+
177
+ def add_embed_row(**opts)
178
+ embed_row = DrawioDsl::Schema::EmbedRow.new(current_page, **opts)
179
+ add_shape(embed_row)
180
+ end
181
+
182
+ def add_embed_col50(**opts)
183
+ embed_col50 = DrawioDsl::Schema::EmbedCol50.new(current_page, **opts)
184
+ add_shape(embed_col50)
185
+ end
186
+
187
+ def add_embed_col200(**opts)
188
+ embed_col200 = DrawioDsl::Schema::EmbedCol200.new(current_page, **opts)
189
+ add_shape(embed_col200)
190
+ end
141
191
  end
142
192
  end
143
193
  # :nocov:
@@ -5,64 +5,112 @@ module DrawioDsl
5
5
  # :nocov:
6
6
  module DrawioShapes
7
7
  def random(**opts)
8
- case rand(27)
8
+ case rand(37)
9
9
  when 0
10
- actor(**opts)
10
+ h1(**opts)
11
11
  when 1
12
- actor2(**opts)
12
+ h2(**opts)
13
13
  when 2
14
- callout(**opts)
14
+ h3(**opts)
15
15
  when 3
16
- callout2(**opts)
16
+ h4(**opts)
17
17
  when 4
18
- callout3(**opts)
18
+ h5(**opts)
19
19
  when 5
20
- callout4(**opts)
20
+ h6(**opts)
21
21
  when 6
22
- circle(**opts)
22
+ p(**opts)
23
23
  when 7
24
- cloud(**opts)
24
+ actor(**opts)
25
25
  when 8
26
- cross(**opts)
26
+ actor2(**opts)
27
27
  when 9
28
- envelop(**opts)
28
+ callout(**opts)
29
29
  when 10
30
- diamond(**opts)
30
+ callout2(**opts)
31
31
  when 11
32
- document(**opts)
32
+ callout3(**opts)
33
33
  when 12
34
- ellipse(**opts)
34
+ callout4(**opts)
35
35
  when 13
36
- hexagon(**opts)
36
+ circle(**opts)
37
37
  when 14
38
- container(**opts)
38
+ cloud(**opts)
39
39
  when 15
40
- container2(**opts)
40
+ cross(**opts)
41
41
  when 16
42
- container3(**opts)
42
+ envelop(**opts)
43
43
  when 17
44
- container4(**opts)
44
+ diamond(**opts)
45
45
  when 18
46
- note(**opts)
46
+ document(**opts)
47
47
  when 19
48
- process(**opts)
48
+ ellipse(**opts)
49
49
  when 20
50
- rectangle(**opts)
50
+ hexagon(**opts)
51
51
  when 21
52
- rectangle2(**opts)
52
+ container(**opts)
53
53
  when 22
54
- square(**opts)
54
+ container2(**opts)
55
55
  when 23
56
- step(**opts)
56
+ container3(**opts)
57
57
  when 24
58
- tick(**opts)
58
+ container4(**opts)
59
59
  when 25
60
- face(**opts)
60
+ note(**opts)
61
61
  when 26
62
+ process(**opts)
63
+ when 27
64
+ rectangle(**opts)
65
+ when 28
66
+ rectangle2(**opts)
67
+ when 29
68
+ square(**opts)
69
+ when 30
70
+ step(**opts)
71
+ when 31
72
+ tick(**opts)
73
+ when 32
74
+ face(**opts)
75
+ when 33
62
76
  triangle(**opts)
77
+ when 34
78
+ embed_row(**opts)
79
+ when 35
80
+ embed_col50(**opts)
81
+ when 36
82
+ embed_col200(**opts)
63
83
  end
64
84
  end
65
85
 
86
+ def h1(**opts)
87
+ builder.add_h1(**opts)
88
+ end
89
+
90
+ def h2(**opts)
91
+ builder.add_h2(**opts)
92
+ end
93
+
94
+ def h3(**opts)
95
+ builder.add_h3(**opts)
96
+ end
97
+
98
+ def h4(**opts)
99
+ builder.add_h4(**opts)
100
+ end
101
+
102
+ def h5(**opts)
103
+ builder.add_h5(**opts)
104
+ end
105
+
106
+ def h6(**opts)
107
+ builder.add_h6(**opts)
108
+ end
109
+
110
+ def p(**opts)
111
+ builder.add_p(**opts)
112
+ end
113
+
66
114
  def actor(**opts)
67
115
  builder.add_actor(**opts)
68
116
  end
@@ -170,6 +218,18 @@ module DrawioDsl
170
218
  def triangle(**opts)
171
219
  builder.add_triangle(**opts)
172
220
  end
221
+
222
+ def embed_row(**opts)
223
+ builder.add_embed_row(**opts)
224
+ end
225
+
226
+ def embed_col50(**opts)
227
+ builder.add_embed_col50(**opts)
228
+ end
229
+
230
+ def embed_col200(**opts)
231
+ builder.add_embed_col200(**opts)
232
+ end
173
233
  end
174
234
  # :nocov:
175
235
  end
@@ -14,22 +14,15 @@ module DrawioDsl
14
14
  attr_reader :current_page
15
15
  attr_reader :current_layout
16
16
 
17
- # attr_reader :page_margin_top
18
- # attr_reader :page_margin_left
19
- # attr_reader :x
20
- # attr_reader :y
21
-
22
17
  def initialize(page)
23
18
  @page = page
24
- # @x = 0
25
- # @y = 0
26
19
  end
27
20
 
28
21
  def call
29
22
  page.position_x = page.margin_left
30
23
  page.position_y = page.margin_top
31
24
 
32
- page.nodes.each do |node|
25
+ page.nodes.all.each do |node|
33
26
  case node.classification
34
27
  when :layout_rule
35
28
  @current_layout = node
@@ -4,6 +4,7 @@ require_relative 'common_style'
4
4
  require_relative 'default_palette'
5
5
  require_relative 'diagram'
6
6
  require_relative 'node'
7
+ require_relative 'node_list'
7
8
  require_relative 'page'
8
9
 
9
10
  require_relative 'layouts/layout'
@@ -11,6 +12,13 @@ require_relative 'layouts/flex_layout'
11
12
  require_relative 'layouts/grid_layout'
12
13
 
13
14
  require_relative 'shapes/shape'
15
+ require_relative 'shapes/h1'
16
+ require_relative 'shapes/h2'
17
+ require_relative 'shapes/h3'
18
+ require_relative 'shapes/h4'
19
+ require_relative 'shapes/h5'
20
+ require_relative 'shapes/h6'
21
+ require_relative 'shapes/p'
14
22
  require_relative 'shapes/actor'
15
23
  require_relative 'shapes/actor2'
16
24
  require_relative 'shapes/callout'
@@ -38,3 +46,6 @@ require_relative 'shapes/step'
38
46
  require_relative 'shapes/tick'
39
47
  require_relative 'shapes/face'
40
48
  require_relative 'shapes/triangle'
49
+ require_relative 'shapes/embed_row'
50
+ require_relative 'shapes/embed_col50'
51
+ require_relative 'shapes/embed_col200'
@@ -6,22 +6,28 @@ module DrawioDsl
6
6
  class GridLayout < Layout
7
7
  attr_accessor :direction
8
8
  attr_accessor :wrap_at
9
- attr_accessor :grid_size
9
+ attr_accessor :grid_size # this is an alternative to grid_w/grid_h
10
+ attr_accessor :grid_w
11
+ attr_accessor :grid_h
10
12
  attr_accessor :cell_no
11
13
  attr_accessor :h_align
12
14
  attr_accessor :v_align
13
15
 
16
+ # rubocop:disable Metrics/CyclomaticComplexity
14
17
  def initialize(page, **args)
15
18
  @type = :grid_layout
16
19
  @direction = args[:direction] || :horizontal
17
20
  @wrap_at = args[:wrap_at] || 5
18
21
  @grid_size = args[:grid_size] || 220
22
+ @grid_w = args[:grid_w] || grid_size
23
+ @grid_h = args[:grid_h] || grid_size
19
24
  @h_align = args[:h_align] || :center
20
25
  @v_align = args[:v_align] || :center
21
26
  @cell_no = 1
22
27
 
23
28
  super(page, **args)
24
29
  end
30
+ # rubocop:enable Metrics/CyclomaticComplexity
25
31
 
26
32
  def position_shape(shape)
27
33
  fire_after_init
@@ -47,7 +53,8 @@ module DrawioDsl
47
53
  super.merge(
48
54
  direction: direction,
49
55
  wrap_at: wrap_at,
50
- grid_size: grid_size,
56
+ grid_w: grid_w,
57
+ grid_h: grid_h,
51
58
  cell_no: cell_no
52
59
  )
53
60
  end
@@ -56,8 +63,8 @@ module DrawioDsl
56
63
 
57
64
  # rubocop:disable Metrics/AbcSize
58
65
  def horizontal_shape_alignment(shape)
59
- return page.position_x + ((grid_size - shape.w) / 2) if h_align == :center
60
- return page.position_x + (grid_size - shape.w) if h_align == :right
66
+ return page.position_x + ((grid_w - shape.w) / 2) if h_align == :center
67
+ return page.position_x + (grid_w - shape.w) if h_align == :right
61
68
 
62
69
  page.position_x
63
70
  end
@@ -65,8 +72,8 @@ module DrawioDsl
65
72
 
66
73
  # rubocop:disable Metrics/AbcSize
67
74
  def vertical_shape_alignment(shape)
68
- return page.position_y + ((grid_size - shape.h) / 2) if v_align == :center || v_align == :middle
69
- return page.position_y + (grid_size - shape.h) if v_align == :bottom
75
+ return page.position_y + ((grid_h - shape.h) / 2) if v_align == :center || v_align == :middle
76
+ return page.position_y + (grid_h - shape.h) if v_align == :bottom
70
77
 
71
78
  page.position_y
72
79
  end
@@ -74,27 +81,27 @@ module DrawioDsl
74
81
 
75
82
  def move_cell_horizontally
76
83
  if cell_no < wrap_at
77
- page.position_x += grid_size
84
+ page.position_x += grid_w
78
85
  @cell_no += 1
79
86
  return
80
87
  end
81
88
 
82
89
  # Flow down to the next row
83
90
  page.position_x = anchor_x
84
- page.position_y += grid_size
91
+ page.position_y += grid_h
85
92
  @cell_no = 1
86
93
  end
87
94
 
88
95
  def move_cell_vertically
89
96
  if cell_no < wrap_at
90
- page.position_y += grid_size
97
+ page.position_y += grid_h
91
98
  @cell_no += 1
92
99
  return
93
100
  end
94
101
 
95
102
  # Flow right to the next column
96
103
  page.position_y = anchor_y
97
- page.position_x += grid_size
104
+ page.position_x += grid_w
98
105
  @cell_no = 1
99
106
  end
100
107
  end
@@ -22,32 +22,37 @@ module DrawioDsl
22
22
  }
23
23
  end
24
24
 
25
- # def debug(format: :detail)
26
- # if format == :detail
27
- # debug_detail(to_h)
28
- # else
29
- # debug_row(classification, id)
30
- # end
31
- # end
25
+ # :nocov:
26
+ # rubocop:disable Metrics/AbcSize
27
+ def debug(format: :detail)
28
+ if format == :detail
29
+ debug_detail(to_h)
30
+ else
31
+ debug_row(classification, id)
32
+ end
33
+ end
32
34
 
33
- # def debug_detail(**key_values)
34
- # key_values.each do |key, value|
35
- # puts "#{key.to_s.ljust(15)}: #{value}"
36
- # end
37
- # end
35
+ def debug_detail(**key_values)
36
+ key_values.each do |key, value|
37
+ puts "#{key.to_s.ljust(15)}: #{value}"
38
+ end
39
+ end
38
40
 
39
- #
40
- # def debug_row(classification, id, type = nil, x = nil, y = nil, width = nil, height = nil)
41
- # row = []
42
- # row << classification.to_s.ljust(11)
43
- # row << id.to_s.ljust(6)
44
- # row << (type.nil? ? '' : type).to_s.ljust(15)
45
- # row << (x.nil? ? '' : x).to_s.rjust(5)
46
- # row << (y.nil? ? '' : y).to_s.rjust(5)
47
- # row << (width.nil? ? '' : width).to_s.rjust(5)
48
- # row << (height.nil? ? '' : height).to_s.rjust(5)
49
- # puts row.join(' | ')
50
- # end
41
+ # rubocop:disable Metrics/ParameterLists
42
+ def debug_row(classification, id, type = nil, x = nil, y = nil, width = nil, height = nil)
43
+ row = []
44
+ row << classification.to_s.ljust(11)
45
+ row << id.to_s.ljust(6)
46
+ row << (type.nil? ? '' : type).to_s.ljust(15)
47
+ row << (x.nil? ? '' : x).to_s.rjust(5)
48
+ row << (y.nil? ? '' : y).to_s.rjust(5)
49
+ row << (width.nil? ? '' : width).to_s.rjust(5)
50
+ row << (height.nil? ? '' : height).to_s.rjust(5)
51
+ puts row.join(' | ')
52
+ end
53
+ # rubocop:enable Metrics/ParameterLists
54
+ # :nocov:
51
55
  end
56
+ # rubocop:enable Metrics/AbcSize
52
57
  end
53
58
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class NodeList
6
+ attr_reader :nodes
7
+
8
+ def initialize
9
+ @nodes = []
10
+ end
11
+
12
+ def add(node)
13
+ @nodes << node
14
+ end
15
+
16
+ def all
17
+ @nodes
18
+ end
19
+
20
+ def shapes
21
+ @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Shape) }
22
+ end
23
+
24
+ def layouts
25
+ @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Layout) }
26
+ end
27
+
28
+ def length
29
+ @nodes.length
30
+ end
31
+
32
+ def to_h
33
+ @nodes.map(&:to_h)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -86,13 +86,13 @@ module DrawioDsl
86
86
  @gradient ||= theme_palette.gradient
87
87
  end
88
88
 
89
- @nodes = args[:nodes] || []
89
+ @nodes = NodeList.new # []
90
90
  end
91
91
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
92
92
 
93
- def shapes
94
- @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Shape) }
95
- end
93
+ # def shapes
94
+ # nodes.shapes
95
+ # end
96
96
 
97
97
  def to_h
98
98
  {
@@ -104,7 +104,7 @@ module DrawioDsl
104
104
  palette: palette.to_h,
105
105
  style: style.to_h,
106
106
  settings: settings,
107
- nodes: nodes.map(&:to_h)
107
+ nodes: nodes.to_h
108
108
  }
109
109
  end
110
110
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class EmbedCol200 < Shape
6
+ configure_shape(:embed_col200)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class EmbedCol50 < Shape
6
+ configure_shape(:embed_col50)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class EmbedRow < Shape
6
+ configure_shape(:embed_row)
7
+ end
8
+ end
9
+ end