drawio_dsl 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/.data/shapes.json +168 -8
  3. data/.builders/.templates/basic/configuration_shapes.rb +27 -0
  4. data/.builders/.templates/basic/dom_builder_shapes.rb +16 -0
  5. data/.builders/.templates/basic/drawio_shapes.rb +23 -0
  6. data/.builders/.templates/basic/schema_shape.rb +9 -0
  7. data/.builders/.templates/{schema_shape_spec.rb → basic/schema_shape_spec.rb} +2 -2
  8. data/.builders/blueprint/shapes.rb +37 -12
  9. data/.builders/boot.rb +1 -0
  10. data/.builders/generators/02-generate-app.rb +43 -0
  11. data/.builders/generators/sample_diagrams/25-themes.rb +2 -2
  12. data/.builders/generators/sample_diagrams/30-shapes.rb +23 -0
  13. data/.builders/generators/sample_diagrams/50-willoughby-council.rb +38 -0
  14. data/.rubocop.yml +22 -3
  15. data/CHANGELOG.md +23 -0
  16. data/README.md +4 -0
  17. data/lib/drawio_dsl/configuration.rb +5 -101
  18. data/lib/drawio_dsl/configuration_extension.rb +13 -0
  19. data/lib/drawio_dsl/configuration_shapes.rb +83 -0
  20. data/lib/drawio_dsl/configuration_themes.rb +63 -0
  21. data/lib/drawio_dsl/dom_builder.rb +9 -55
  22. data/lib/drawio_dsl/dom_builder_shapes.rb +158 -0
  23. data/lib/drawio_dsl/drawio.rb +1 -91
  24. data/lib/drawio_dsl/drawio_shapes.rb +193 -0
  25. data/lib/drawio_dsl/layout_engine.rb +1 -8
  26. data/lib/drawio_dsl/schema/_.rb +21 -0
  27. data/lib/drawio_dsl/schema/layouts/grid_layout.rb +17 -10
  28. data/lib/drawio_dsl/schema/node_list.rb +37 -0
  29. data/lib/drawio_dsl/schema/page.rb +5 -5
  30. data/{.builders/.templates/schema_shape.rb → lib/drawio_dsl/schema/shapes/actor.rb} +2 -2
  31. data/lib/drawio_dsl/schema/shapes/actor2.rb +9 -0
  32. data/lib/drawio_dsl/schema/shapes/callout2.rb +9 -0
  33. data/lib/drawio_dsl/schema/shapes/callout3.rb +9 -0
  34. data/lib/drawio_dsl/schema/shapes/callout4.rb +9 -0
  35. data/lib/drawio_dsl/schema/shapes/container.rb +9 -0
  36. data/lib/drawio_dsl/schema/shapes/container2.rb +9 -0
  37. data/lib/drawio_dsl/schema/shapes/container3.rb +9 -0
  38. data/lib/drawio_dsl/schema/shapes/container4.rb +9 -0
  39. data/lib/drawio_dsl/schema/shapes/cross.rb +9 -0
  40. data/lib/drawio_dsl/schema/shapes/document.rb +9 -0
  41. data/lib/drawio_dsl/schema/shapes/embed_col200.rb +9 -0
  42. data/lib/drawio_dsl/schema/shapes/embed_col50.rb +9 -0
  43. data/lib/drawio_dsl/schema/shapes/embed_row.rb +9 -0
  44. data/lib/drawio_dsl/schema/shapes/envelop.rb +9 -0
  45. data/lib/drawio_dsl/schema/shapes/face.rb +9 -0
  46. data/lib/drawio_dsl/schema/shapes/rectangle2.rb +9 -0
  47. data/lib/drawio_dsl/schema/shapes/shape.rb +10 -6
  48. data/lib/drawio_dsl/schema/shapes/step.rb +9 -0
  49. data/lib/drawio_dsl/schema/shapes/tick.rb +9 -0
  50. data/lib/drawio_dsl/schema/shapes/triangle.rb +9 -0
  51. data/lib/drawio_dsl/version.rb +1 -1
  52. data/lib/drawio_dsl/xml_builder.rb +2 -12
  53. data/lib/drawio_dsl.rb +5 -0
  54. data/package-lock.json +2 -2
  55. data/package.json +1 -1
  56. metadata +36 -5
  57. data/.builders/generators/90-requires.rb +0 -35
@@ -0,0 +1,193 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ # DrawioDsl::Shapes is a list of DSL methods (one per shape)
5
+ # :nocov:
6
+ module DrawioShapes
7
+ def random(**opts)
8
+ case rand(30)
9
+ when 0
10
+ actor(**opts)
11
+ when 1
12
+ actor2(**opts)
13
+ when 2
14
+ callout(**opts)
15
+ when 3
16
+ callout2(**opts)
17
+ when 4
18
+ callout3(**opts)
19
+ when 5
20
+ callout4(**opts)
21
+ when 6
22
+ circle(**opts)
23
+ when 7
24
+ cloud(**opts)
25
+ when 8
26
+ cross(**opts)
27
+ when 9
28
+ envelop(**opts)
29
+ when 10
30
+ diamond(**opts)
31
+ when 11
32
+ document(**opts)
33
+ when 12
34
+ ellipse(**opts)
35
+ when 13
36
+ hexagon(**opts)
37
+ when 14
38
+ container(**opts)
39
+ when 15
40
+ container2(**opts)
41
+ when 16
42
+ container3(**opts)
43
+ when 17
44
+ container4(**opts)
45
+ when 18
46
+ note(**opts)
47
+ when 19
48
+ process(**opts)
49
+ when 20
50
+ rectangle(**opts)
51
+ when 21
52
+ rectangle2(**opts)
53
+ when 22
54
+ square(**opts)
55
+ when 23
56
+ step(**opts)
57
+ when 24
58
+ tick(**opts)
59
+ when 25
60
+ face(**opts)
61
+ when 26
62
+ triangle(**opts)
63
+ when 27
64
+ embed_row(**opts)
65
+ when 28
66
+ embed_col50(**opts)
67
+ when 29
68
+ embed_col200(**opts)
69
+ end
70
+ end
71
+
72
+ def actor(**opts)
73
+ builder.add_actor(**opts)
74
+ end
75
+
76
+ def actor2(**opts)
77
+ builder.add_actor2(**opts)
78
+ end
79
+
80
+ def callout(**opts)
81
+ builder.add_callout(**opts)
82
+ end
83
+
84
+ def callout2(**opts)
85
+ builder.add_callout2(**opts)
86
+ end
87
+
88
+ def callout3(**opts)
89
+ builder.add_callout3(**opts)
90
+ end
91
+
92
+ def callout4(**opts)
93
+ builder.add_callout4(**opts)
94
+ end
95
+
96
+ def circle(**opts)
97
+ builder.add_circle(**opts)
98
+ end
99
+
100
+ def cloud(**opts)
101
+ builder.add_cloud(**opts)
102
+ end
103
+
104
+ def cross(**opts)
105
+ builder.add_cross(**opts)
106
+ end
107
+
108
+ def envelop(**opts)
109
+ builder.add_envelop(**opts)
110
+ end
111
+
112
+ def diamond(**opts)
113
+ builder.add_diamond(**opts)
114
+ end
115
+
116
+ def document(**opts)
117
+ builder.add_document(**opts)
118
+ end
119
+
120
+ def ellipse(**opts)
121
+ builder.add_ellipse(**opts)
122
+ end
123
+
124
+ def hexagon(**opts)
125
+ builder.add_hexagon(**opts)
126
+ end
127
+
128
+ def container(**opts)
129
+ builder.add_container(**opts)
130
+ end
131
+
132
+ def container2(**opts)
133
+ builder.add_container2(**opts)
134
+ end
135
+
136
+ def container3(**opts)
137
+ builder.add_container3(**opts)
138
+ end
139
+
140
+ def container4(**opts)
141
+ builder.add_container4(**opts)
142
+ end
143
+
144
+ def note(**opts)
145
+ builder.add_note(**opts)
146
+ end
147
+
148
+ def process(**opts)
149
+ builder.add_process(**opts)
150
+ end
151
+
152
+ def rectangle(**opts)
153
+ builder.add_rectangle(**opts)
154
+ end
155
+
156
+ def rectangle2(**opts)
157
+ builder.add_rectangle2(**opts)
158
+ end
159
+
160
+ def square(**opts)
161
+ builder.add_square(**opts)
162
+ end
163
+
164
+ def step(**opts)
165
+ builder.add_step(**opts)
166
+ end
167
+
168
+ def tick(**opts)
169
+ builder.add_tick(**opts)
170
+ end
171
+
172
+ def face(**opts)
173
+ builder.add_face(**opts)
174
+ end
175
+
176
+ def triangle(**opts)
177
+ builder.add_triangle(**opts)
178
+ end
179
+
180
+ def embed_row(**opts)
181
+ builder.add_embed_row(**opts)
182
+ end
183
+
184
+ def embed_col50(**opts)
185
+ builder.add_embed_col50(**opts)
186
+ end
187
+
188
+ def embed_col200(**opts)
189
+ builder.add_embed_col200(**opts)
190
+ end
191
+ end
192
+ # :nocov:
193
+ 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,13 +12,33 @@ require_relative 'layouts/flex_layout'
11
12
  require_relative 'layouts/grid_layout'
12
13
 
13
14
  require_relative 'shapes/shape'
15
+ require_relative 'shapes/actor'
16
+ require_relative 'shapes/actor2'
14
17
  require_relative 'shapes/callout'
18
+ require_relative 'shapes/callout2'
19
+ require_relative 'shapes/callout3'
20
+ require_relative 'shapes/callout4'
15
21
  require_relative 'shapes/circle'
16
22
  require_relative 'shapes/cloud'
23
+ require_relative 'shapes/cross'
24
+ require_relative 'shapes/envelop'
17
25
  require_relative 'shapes/diamond'
26
+ require_relative 'shapes/document'
18
27
  require_relative 'shapes/ellipse'
19
28
  require_relative 'shapes/hexagon'
29
+ require_relative 'shapes/container'
30
+ require_relative 'shapes/container2'
31
+ require_relative 'shapes/container3'
32
+ require_relative 'shapes/container4'
20
33
  require_relative 'shapes/note'
21
34
  require_relative 'shapes/process'
22
35
  require_relative 'shapes/rectangle'
36
+ require_relative 'shapes/rectangle2'
23
37
  require_relative 'shapes/square'
38
+ require_relative 'shapes/step'
39
+ require_relative 'shapes/tick'
40
+ require_relative 'shapes/face'
41
+ require_relative 'shapes/triangle'
42
+ require_relative 'shapes/embed_row'
43
+ require_relative 'shapes/embed_col50'
44
+ 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_w
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_h
98
105
  @cell_no = 1
99
106
  end
100
107
  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
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class {{camle type}} < Shape
6
- configure_shape(:{{snake type}})
5
+ class Actor < Shape
6
+ configure_shape(:actor)
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Actor2 < Shape
6
+ configure_shape(:actor2)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Callout2 < Shape
6
+ configure_shape(:callout2)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Callout3 < Shape
6
+ configure_shape(:callout3)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Callout4 < Shape
6
+ configure_shape(:callout4)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Container < Shape
6
+ configure_shape(:container)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Container2 < Shape
6
+ configure_shape(:container2)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Container3 < Shape
6
+ configure_shape(:container3)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Container4 < Shape
6
+ configure_shape(:container4)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Cross < Shape
6
+ configure_shape(:cross)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Document < Shape
6
+ configure_shape(:document)
7
+ end
8
+ end
9
+ end
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Envelop < Shape
6
+ configure_shape(:envelop)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Face < Shape
6
+ configure_shape(:face)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Rectangle2 < Shape
6
+ configure_shape(:rectangle2)
7
+ end
8
+ end
9
+ end
@@ -5,6 +5,8 @@ module DrawioDsl
5
5
  # Shape is a graphical element, it can be a shape, a text, or a group (todo)
6
6
  class Shape < Node
7
7
  class << self
8
+ attr_reader :shape_defaults
9
+
8
10
  def configure_shape(name)
9
11
  raise "Shape #{name} not found in configuration" unless KConfig.configuration.drawio.shapes.members.include?(name)
10
12
 
@@ -12,12 +14,6 @@ module DrawioDsl
12
14
 
13
15
  @shape_defaults = config.clone
14
16
  end
15
-
16
- def shape_defaults
17
- return @shape_defaults if defined? @shape_defaults
18
-
19
- raise 'Shape defaults not configured'
20
- end
21
17
  end
22
18
 
23
19
  configure_shape(:shape)
@@ -100,6 +96,12 @@ module DrawioDsl
100
96
  end
101
97
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
102
98
 
99
+ def as_xml(xml)
100
+ xml.mxCell(id: id, value: title, style: style, vertex: 1, parent: "#{page.id}-B") do
101
+ xml.mxGeometry(x: x, y: y, width: w, height: h, as: 'geometry')
102
+ end
103
+ end
104
+
103
105
  def to_h
104
106
  {
105
107
  id: id,
@@ -113,6 +115,7 @@ module DrawioDsl
113
115
  }
114
116
  end
115
117
 
118
+ # :nocov:
116
119
  def debug(format: :detail)
117
120
  if format == :detail
118
121
  debug_detail({ id: id, classification: classification, type: type })
@@ -120,6 +123,7 @@ module DrawioDsl
120
123
  debug_row(classification, id, type, x, y, w, h)
121
124
  end
122
125
  end
126
+ # :nocov:
123
127
  end
124
128
  end
125
129
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Step < Shape
6
+ configure_shape(:step)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Tick < Shape
6
+ configure_shape(:tick)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Triangle < Shape
6
+ configure_shape(:triangle)
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DrawioDsl
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.2'
5
5
  end