drawio_dsl 0.4.0 → 0.5.1

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/.data/shapes.json +242 -0
  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_require.rb +16 -0
  7. data/.builders/.templates/basic/schema_shape.rb +9 -0
  8. data/.builders/.templates/basic/schema_shape_spec.rb +13 -0
  9. data/.builders/blueprint/shapes.rb +47 -12
  10. data/.builders/boot.rb +5 -0
  11. data/.builders/generators/02-generate-app.rb +43 -0
  12. data/.builders/generators/{10-page-margin.rb → sample_diagrams/10-page-margin.rb} +0 -0
  13. data/.builders/generators/{15-grid-direction.rb → sample_diagrams/15-grid-direction.rb} +0 -0
  14. data/.builders/generators/{16-grid-alignment.rb → sample_diagrams/16-grid-alignment.rb} +0 -0
  15. data/.builders/generators/{20-styles.rb → sample_diagrams/20-styles.rb} +0 -0
  16. data/.builders/generators/{25-themes.rb → sample_diagrams/25-themes.rb} +2 -2
  17. data/.builders/generators/sample_diagrams/30-shapes.rb +23 -0
  18. data/.rubocop.yml +22 -3
  19. data/CHANGELOG.md +23 -0
  20. data/README.md +4 -0
  21. data/lib/drawio_dsl/configuration.rb +5 -101
  22. data/lib/drawio_dsl/configuration_extension.rb +13 -0
  23. data/lib/drawio_dsl/configuration_shapes.rb +83 -0
  24. data/lib/drawio_dsl/configuration_themes.rb +63 -0
  25. data/lib/drawio_dsl/dom_builder.rb +9 -55
  26. data/lib/drawio_dsl/dom_builder_shapes.rb +158 -0
  27. data/lib/drawio_dsl/drawio.rb +1 -91
  28. data/lib/drawio_dsl/drawio_shapes.rb +193 -0
  29. data/lib/drawio_dsl/layout_engine.rb +1 -8
  30. data/lib/drawio_dsl/schema/_.rb +21 -0
  31. data/lib/drawio_dsl/schema/node_list.rb +37 -0
  32. data/lib/drawio_dsl/schema/page.rb +5 -5
  33. data/{.builders/.templates/schema_shape.rb → lib/drawio_dsl/schema/shapes/actor.rb} +2 -2
  34. data/lib/drawio_dsl/schema/shapes/actor2.rb +9 -0
  35. data/lib/drawio_dsl/schema/shapes/callout2.rb +9 -0
  36. data/lib/drawio_dsl/schema/shapes/callout3.rb +9 -0
  37. data/lib/drawio_dsl/schema/shapes/callout4.rb +9 -0
  38. data/lib/drawio_dsl/schema/shapes/container.rb +9 -0
  39. data/lib/drawio_dsl/schema/shapes/container2.rb +9 -0
  40. data/lib/drawio_dsl/schema/shapes/container3.rb +9 -0
  41. data/lib/drawio_dsl/schema/shapes/container4.rb +9 -0
  42. data/lib/drawio_dsl/schema/shapes/cross.rb +9 -0
  43. data/lib/drawio_dsl/schema/shapes/document.rb +9 -0
  44. data/lib/drawio_dsl/schema/shapes/embed_col200.rb +9 -0
  45. data/lib/drawio_dsl/schema/shapes/embed_col50.rb +9 -0
  46. data/lib/drawio_dsl/schema/shapes/embed_row.rb +9 -0
  47. data/lib/drawio_dsl/schema/shapes/envelop.rb +9 -0
  48. data/lib/drawio_dsl/schema/shapes/face.rb +9 -0
  49. data/lib/drawio_dsl/schema/shapes/rectangle2.rb +9 -0
  50. data/lib/drawio_dsl/schema/shapes/shape.rb +10 -6
  51. data/lib/drawio_dsl/schema/shapes/step.rb +9 -0
  52. data/lib/drawio_dsl/schema/shapes/tick.rb +9 -0
  53. data/lib/drawio_dsl/schema/shapes/triangle.rb +9 -0
  54. data/lib/drawio_dsl/version.rb +1 -1
  55. data/lib/drawio_dsl/xml_builder.rb +2 -12
  56. data/lib/drawio_dsl.rb +5 -0
  57. data/package-lock.json +2 -2
  58. data/package.json +1 -1
  59. metadata +42 -9
  60. data/.builders/.templates/command.rb +0 -8
@@ -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'
@@ -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.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -52,23 +52,13 @@ module DrawioDsl
52
52
  xml.root do
53
53
  xml.mxCell(id: "#{page.id}-A")
54
54
  xml.mxCell(id: "#{page.id}-B", parent: "#{page.id}-A")
55
- page.nodes.each do |node|
56
- build_shape(xml, node) if node.classification == :shape
55
+ page.nodes.all.each do |node|
56
+ node.as_xml(xml) if node.classification == :shape
57
57
  end
58
58
  end
59
59
  end
60
60
  end
61
61
  end
62
62
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/BlockLength
63
-
64
- def build_shape(xml, shape)
65
- # puts "opts: #{opts}"
66
- # puts shape.x
67
- # puts shape.y
68
-
69
- xml.mxCell(id: shape.id, value: shape.title, style: shape.style, vertex: 1, parent: "#{shape.page.id}-B") do
70
- xml.mxGeometry(x: shape.x, y: shape.y, width: shape.w, height: shape.h, as: 'geometry')
71
- end
72
- end
73
63
  end
74
64
  end
data/lib/drawio_dsl.rb CHANGED
@@ -7,12 +7,17 @@ require 'k_config'
7
7
  require 'k_log'
8
8
  require 'k_director'
9
9
 
10
+ require_relative 'drawio_dsl/configuration_extension'
11
+ require_relative 'drawio_dsl/configuration_shapes'
12
+ require_relative 'drawio_dsl/configuration_themes'
10
13
  require_relative 'drawio_dsl/configuration'
11
14
  require_relative 'drawio_dsl/version'
12
15
  require_relative 'drawio_dsl/schema/_'
16
+ require_relative 'drawio_dsl/dom_builder_shapes'
13
17
  require_relative 'drawio_dsl/dom_builder'
14
18
  require_relative 'drawio_dsl/xml_builder'
15
19
  require_relative 'drawio_dsl/layout_engine'
20
+ require_relative 'drawio_dsl/drawio_shapes'
16
21
  require_relative 'drawio_dsl/drawio'
17
22
 
18
23
  module DrawioDsl
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "drawio_dsl",
9
- "version": "0.4.0",
9
+ "version": "0.5.1",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "DrawIO DSL can build DrawIO diagrams using a Domain Specific Language",
5
5
  "scripts": {
6
6
  "release": "semantic-release"