drawio_dsl 0.8.11 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/config/configuration.json +1191 -8
  4. data/docs/project-plan/project.drawio +89 -77
  5. data/docs/project-plan/project_done.svg +1 -1
  6. data/docs/project-plan/project_in_progress.svg +1 -1
  7. data/docs/samples/grid-direction-vertical.svg +1 -1
  8. data/docs/samples/styles-glass.svg +1 -1
  9. data/docs/samples/styles-plain.svg +1 -1
  10. data/docs/samples/styles-rounded.svg +1 -1
  11. data/docs/samples/styles-shadow.svg +1 -1
  12. data/docs/samples/styles-sketch.svg +1 -1
  13. data/docs/samples/themes-random.svg +1 -1
  14. data/docs/samples/willoughby-council.svg +1 -1
  15. data/lib/drawio_dsl/configuration.rb +110 -20
  16. data/lib/drawio_dsl/configuration_shapes.rb +9 -9
  17. data/lib/drawio_dsl/dom_builder_shapes.rb +3 -3
  18. data/lib/drawio_dsl/drawio_shapes.rb +3 -3
  19. data/lib/drawio_dsl/schema/_.rb +55 -45
  20. data/lib/drawio_dsl/schema/diagram.rb +17 -11
  21. data/lib/drawio_dsl/schema/element.rb +23 -0
  22. data/lib/drawio_dsl/schema/{shapes/face.rb → elements/actor.rb} +2 -2
  23. data/lib/drawio_dsl/schema/{shapes/cross.rb → elements/actor2.rb} +2 -2
  24. data/lib/drawio_dsl/schema/{shapes/actor2.rb → elements/callout.rb} +2 -2
  25. data/lib/drawio_dsl/schema/{shapes/callout.rb → elements/callout2.rb} +2 -2
  26. data/lib/drawio_dsl/schema/elements/callout3.rb +9 -0
  27. data/lib/drawio_dsl/schema/elements/callout4.rb +9 -0
  28. data/lib/drawio_dsl/schema/{shapes/actor.rb → elements/circle.rb} +2 -2
  29. data/lib/drawio_dsl/schema/elements/cloud.rb +9 -0
  30. data/lib/drawio_dsl/schema/elements/container.rb +9 -0
  31. data/lib/drawio_dsl/schema/elements/container2.rb +9 -0
  32. data/lib/drawio_dsl/schema/elements/container3.rb +9 -0
  33. data/lib/drawio_dsl/schema/elements/container4.rb +9 -0
  34. data/lib/drawio_dsl/schema/elements/cross.rb +9 -0
  35. data/lib/drawio_dsl/schema/elements/database.rb +9 -0
  36. data/lib/drawio_dsl/schema/{shapes/circle.rb → elements/db_json.rb} +2 -2
  37. data/lib/drawio_dsl/schema/elements/diamond.rb +9 -0
  38. data/lib/drawio_dsl/schema/elements/document.rb +9 -0
  39. data/lib/drawio_dsl/schema/elements/ellipse.rb +9 -0
  40. data/lib/drawio_dsl/schema/elements/embed_col200.rb +9 -0
  41. data/lib/drawio_dsl/schema/elements/embed_col50.rb +9 -0
  42. data/lib/drawio_dsl/schema/{shapes/callout2.rb → elements/embed_row.rb} +2 -2
  43. data/lib/drawio_dsl/schema/elements/envelop.rb +9 -0
  44. data/lib/drawio_dsl/schema/elements/face.rb +9 -0
  45. data/lib/drawio_dsl/schema/elements/group.rb +9 -0
  46. data/lib/drawio_dsl/schema/elements/hexagon.rb +9 -0
  47. data/lib/drawio_dsl/schema/elements/interface.rb +9 -0
  48. data/lib/drawio_dsl/schema/elements/klass.rb +9 -0
  49. data/lib/drawio_dsl/schema/elements/note.rb +9 -0
  50. data/lib/drawio_dsl/schema/elements/process.rb +9 -0
  51. data/lib/drawio_dsl/schema/elements/rectangle.rb +9 -0
  52. data/lib/drawio_dsl/schema/elements/rectangle2.rb +9 -0
  53. data/lib/drawio_dsl/schema/{shapes/cloud.rb → elements/square.rb} +2 -2
  54. data/lib/drawio_dsl/schema/elements/step.rb +9 -0
  55. data/lib/drawio_dsl/schema/elements/tick.rb +9 -0
  56. data/lib/drawio_dsl/schema/elements/todo.rb +9 -0
  57. data/lib/drawio_dsl/schema/elements/triangle.rb +9 -0
  58. data/lib/drawio_dsl/schema/line.rb +24 -0
  59. data/lib/drawio_dsl/schema/lines/solid.rb +9 -0
  60. data/lib/drawio_dsl/schema/page.rb +15 -7
  61. data/lib/drawio_dsl/schema/{shapes/shape.rb → shape.rb} +19 -22
  62. data/lib/drawio_dsl/schema/text.rb +23 -0
  63. data/lib/drawio_dsl/schema/{shapes → texts}/h1.rb +2 -2
  64. data/lib/drawio_dsl/schema/{shapes → texts}/h2.rb +2 -2
  65. data/lib/drawio_dsl/schema/{shapes → texts}/h3.rb +2 -2
  66. data/lib/drawio_dsl/schema/{shapes → texts}/h4.rb +2 -2
  67. data/lib/drawio_dsl/schema/{shapes → texts}/h5.rb +2 -2
  68. data/lib/drawio_dsl/schema/{shapes → texts}/h6.rb +2 -2
  69. data/lib/drawio_dsl/schema/{shapes → texts}/p.rb +2 -2
  70. data/lib/drawio_dsl/version.rb +1 -1
  71. data/lib/drawio_dsl.rb +7 -10
  72. data/package-lock.json +2 -2
  73. data/package.json +1 -1
  74. metadata +50 -48
  75. data/lib/drawio_dsl/configuration_themes.rb +0 -63
  76. data/lib/drawio_dsl/schema/shapes/callout3.rb +0 -9
  77. data/lib/drawio_dsl/schema/shapes/callout4.rb +0 -9
  78. data/lib/drawio_dsl/schema/shapes/container.rb +0 -9
  79. data/lib/drawio_dsl/schema/shapes/container2.rb +0 -9
  80. data/lib/drawio_dsl/schema/shapes/container3.rb +0 -9
  81. data/lib/drawio_dsl/schema/shapes/container4.rb +0 -9
  82. data/lib/drawio_dsl/schema/shapes/database.rb +0 -9
  83. data/lib/drawio_dsl/schema/shapes/db_json.rb +0 -9
  84. data/lib/drawio_dsl/schema/shapes/diamond.rb +0 -9
  85. data/lib/drawio_dsl/schema/shapes/document.rb +0 -9
  86. data/lib/drawio_dsl/schema/shapes/ellipse.rb +0 -9
  87. data/lib/drawio_dsl/schema/shapes/embed_col200.rb +0 -9
  88. data/lib/drawio_dsl/schema/shapes/embed_col50.rb +0 -9
  89. data/lib/drawio_dsl/schema/shapes/embed_row.rb +0 -9
  90. data/lib/drawio_dsl/schema/shapes/envelop.rb +0 -9
  91. data/lib/drawio_dsl/schema/shapes/group.rb +0 -9
  92. data/lib/drawio_dsl/schema/shapes/hexagon.rb +0 -9
  93. data/lib/drawio_dsl/schema/shapes/interface.rb +0 -9
  94. data/lib/drawio_dsl/schema/shapes/klass.rb +0 -9
  95. data/lib/drawio_dsl/schema/shapes/line.rb +0 -9
  96. data/lib/drawio_dsl/schema/shapes/note.rb +0 -9
  97. data/lib/drawio_dsl/schema/shapes/process.rb +0 -9
  98. data/lib/drawio_dsl/schema/shapes/rectangle.rb +0 -9
  99. data/lib/drawio_dsl/schema/shapes/rectangle2.rb +0 -9
  100. data/lib/drawio_dsl/schema/shapes/square.rb +0 -9
  101. data/lib/drawio_dsl/schema/shapes/step.rb +0 -9
  102. data/lib/drawio_dsl/schema/shapes/tick.rb +0 -9
  103. data/lib/drawio_dsl/schema/shapes/todo.rb +0 -9
  104. data/lib/drawio_dsl/schema/shapes/triangle.rb +0 -9
@@ -5,14 +5,13 @@ module DrawioDsl
5
5
  # Configuration container for the DrawIO DSL
6
6
  class Configuration
7
7
  include DrawioDsl::ConfigurationShapes
8
- include DrawioDsl::ConfigurationThemes
9
8
 
10
9
  include KLog::Logging
11
10
 
12
- BaseStyle = Struct.new(:white_space, :html, :rounded, :shadow, :sketch, :glass, keyword_init: true)
13
- Element = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
14
- Line = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
15
- Text = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
11
+ BaseStyle = Struct.new(:white_space, :html, :rounded, :shadow, :sketch, :glass, keyword_init: true)
12
+ ElementConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
13
+ LineConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
14
+ TextConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
16
15
 
17
16
  attr_accessor :base_style
18
17
 
@@ -21,16 +20,8 @@ module DrawioDsl
21
20
  def initialize
22
21
  @base_style = BaseStyle.new(white_space: :wrap, html: 1, rounded: nil, shadow: nil, sketch: nil, glass: nil)
23
22
 
23
+ # TODO: these need to be removed
24
24
  add_shapes
25
- add_themes
26
- end
27
-
28
- def palette(theme)
29
- themes[theme]
30
- end
31
-
32
- def random_theme
33
- themes.keys.sample
34
25
  end
35
26
 
36
27
  def stroke(type)
@@ -48,8 +39,20 @@ module DrawioDsl
48
39
  @strokes
49
40
  end
50
41
 
42
+ # need test
43
+ def get_item_by_category(type, category)
44
+ case category
45
+ when :text
46
+ text(type)
47
+ when :line
48
+ line(type)
49
+ else
50
+ element(type)
51
+ end
52
+ end
53
+
51
54
  def element(type)
52
- elements[type] || ''
55
+ elements[type]
53
56
  end
54
57
 
55
58
  def elements
@@ -57,7 +60,7 @@ module DrawioDsl
57
60
 
58
61
  @elements = {}
59
62
  source_config['shapes'].select { |shape| shape['category'] == 'element' }.each do |element|
60
- @elements[element['type'].to_sym] = Element.new(
63
+ @elements[element['type'].to_sym] = ElementConfig.new(
61
64
  type: element['type'].to_sym,
62
65
  x: element['x'].to_i,
63
66
  y: element['y'].to_i,
@@ -71,7 +74,7 @@ module DrawioDsl
71
74
  end
72
75
 
73
76
  def line(type)
74
- lines[type] || ''
77
+ lines[type]
75
78
  end
76
79
 
77
80
  def lines
@@ -79,7 +82,7 @@ module DrawioDsl
79
82
 
80
83
  @lines = {}
81
84
  source_config['shapes'].select { |shape| shape['category'] == 'line' }.each do |line|
82
- @lines[line['type'].to_sym] = Line.new(
85
+ @lines[line['type'].to_sym] = LineConfig.new(
83
86
  type: line['type'].to_sym,
84
87
  x: line['x'].to_i,
85
88
  y: line['y'].to_i,
@@ -93,7 +96,7 @@ module DrawioDsl
93
96
  end
94
97
 
95
98
  def text(type)
96
- texts[type] || ''
99
+ texts[type]
97
100
  end
98
101
 
99
102
  def texts
@@ -101,7 +104,7 @@ module DrawioDsl
101
104
 
102
105
  @texts = {}
103
106
  source_config['shapes'].select { |shape| shape['category'] == 'text' }.each do |text|
104
- @texts[text['type'].to_sym] = Text.new(
107
+ @texts[text['type'].to_sym] = TextConfig.new(
105
108
  type: text['type'].to_sym,
106
109
  x: text['x'].to_i,
107
110
  y: text['y'].to_i,
@@ -118,6 +121,10 @@ module DrawioDsl
118
121
  @connector ||= Connector.new(source_config['connector'])
119
122
  end
120
123
 
124
+ def theme
125
+ @theme ||= Theme.new(source_config['theme'])
126
+ end
127
+
121
128
  def source_config
122
129
  return @source_config if defined? @source_config
123
130
 
@@ -197,6 +204,89 @@ module DrawioDsl
197
204
  @designs
198
205
  end
199
206
  end
207
+
208
+ class Theme
209
+ attr_reader :source_config
210
+
211
+ BackgroundThemeConfig = Struct.new(:type, :bg_color, :font_color, :favourite, keyword_init: true)
212
+ ElementThemeConfig = Struct.new(:type, :fill_color, :stroke_color, :font_color, :gradient, keyword_init: true)
213
+
214
+ def initialize(source_config)
215
+ @source_config = source_config
216
+ end
217
+
218
+ def background(type)
219
+ backgrounds[type] || BackgroundThemeConfig.new(
220
+ type: type,
221
+ bg_color: '#000000',
222
+ font_color: '#FFFFFF',
223
+ favourite: false
224
+ )
225
+ end
226
+
227
+ def backgrounds
228
+ return @backgrounds if defined? @backgrounds
229
+
230
+ @backgrounds = {}
231
+ source_config['backgrounds'].each do |background|
232
+ @backgrounds[background['type'].to_sym] = BackgroundThemeConfig.new(
233
+ type: background['type'].to_sym,
234
+ bg_color: background['bg_color'],
235
+ font_color: background['font_color'],
236
+ favourite: background['favourite'] == 1
237
+ )
238
+ end
239
+
240
+ @backgrounds
241
+ end
242
+
243
+ def background_types
244
+ backgrounds.keys
245
+ end
246
+
247
+ def favourite_background_types
248
+ backgrounds.values.select(&:favourite).map(&:type)
249
+ end
250
+
251
+ def random_background_type
252
+ backgrounds.values.sample.type
253
+ end
254
+
255
+ def element(type)
256
+ elements[type] || ElementThemeConfig.new(
257
+ type: type,
258
+ fill_color: '#ffffff',
259
+ stroke_color: '#000000',
260
+ font_color: '#000000',
261
+ gradient: nil
262
+ )
263
+ end
264
+
265
+ def elements
266
+ return @elements if defined? @elements
267
+
268
+ @elements = {}
269
+ source_config['elements'].each do |element|
270
+ @elements[element['type'].to_sym] = ElementThemeConfig.new(
271
+ type: element['type'].to_sym,
272
+ fill_color: element['fill_color'],
273
+ stroke_color: element['stroke_color'],
274
+ font_color: element['font_color'],
275
+ gradient: element['gradient']
276
+ )
277
+ end
278
+
279
+ @elements
280
+ end
281
+
282
+ def element_types
283
+ elements.keys
284
+ end
285
+
286
+ def random_element_type
287
+ elements.values.sample.type
288
+ end
289
+ end
200
290
  end
201
291
  end
202
292
 
@@ -8,7 +8,7 @@ module DrawioDsl
8
8
  ShapeDefaults = Struct.new(:type, :category, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
9
9
  Shapes = Struct.new(
10
10
  :shape,
11
- :line,
11
+ :solid,
12
12
  :h1,
13
13
  :h2,
14
14
  :h3,
@@ -58,14 +58,14 @@ module DrawioDsl
58
58
  def add_shapes
59
59
  @shapes = Shapes.new(
60
60
  shape: ShapeDefaults.new(type: :shape, category: :element, x: 0, y: 0, w: 20, h: 20, style_modifiers: ''),
61
- line: ShapeDefaults.new(type: :line, x: 0, category: :line, y: 0, w: 50, h: 50, style_modifiers: 'edgeStyle=none;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0'),
62
- h1: ShapeDefaults.new(type: :h1, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=89;fontColor=#ffffff;fontStyle=1;fillColor=none'),
63
- h2: ShapeDefaults.new(type: :h2, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=67;fontColor=#ffffff;fontStyle=1;fillColor=none'),
64
- h3: ShapeDefaults.new(type: :h3, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=50;fontColor=#ffffff;fontStyle=1;fillColor=none'),
65
- h4: ShapeDefaults.new(type: :h4, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=37;fontColor=#ffffff;fontStyle=1;fillColor=none'),
66
- h5: ShapeDefaults.new(type: :h5, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=28;fontColor=#ffffff;fontStyle=1;fillColor=none'),
67
- h6: ShapeDefaults.new(type: :h6, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=21;fontColor=#ffffff;fontStyle=1;fillColor=none'),
68
- p: ShapeDefaults.new(type: :p, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=16;fontColor=#ffffff;fontStyle=1;fillColor=none'),
61
+ solid: ShapeDefaults.new(type: :solid, x: 0, category: :line, y: 0, w: 50, h: 50, style_modifiers: 'edgeStyle=none;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0'),
62
+ h1: ShapeDefaults.new(type: :h1, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=89;fontStyle=1;fillColor=none'),
63
+ h2: ShapeDefaults.new(type: :h2, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=67;fontStyle=1;fillColor=none'),
64
+ h3: ShapeDefaults.new(type: :h3, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=50;fontStyle=1;fillColor=none'),
65
+ h4: ShapeDefaults.new(type: :h4, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=37;fontStyle=1;fillColor=none'),
66
+ h5: ShapeDefaults.new(type: :h5, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=28;fontStyle=1;fillColor=none'),
67
+ h6: ShapeDefaults.new(type: :h6, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=21;fontStyle=1;fillColor=none'),
68
+ p: ShapeDefaults.new(type: :p, x: 0, category: :text, y: 0, w: 100, h: 50, style_modifiers: 'text;fontSize=16;fontStyle=1;fillColor=none'),
69
69
  actor: ShapeDefaults.new(type: :actor, x: 0, category: :element, y: 0, w: 40, h: 50, style_modifiers: 'shape=actor'),
70
70
  actor2: ShapeDefaults.new(type: :actor2, x: 0, category: :element, y: 0, w: 30, h: 50, style_modifiers: 'shape=umlActor;verticalLabelPosition=bottom;outlineConnect=1'),
71
71
  callout: ShapeDefaults.new(type: :callout, x: 0, category: :element, y: 0, w: 160, h: 120, style_modifiers: 'shape=callout'),
@@ -4,10 +4,10 @@
4
4
  module DrawioDsl
5
5
  # DrawioDsl is a DSL for draw-io diagrams.
6
6
  module DomBuilderShapes
7
- def add_line(id = nil, **opts, &block)
7
+ def add_solid(id = nil, **opts, &block)
8
8
  opts = { id: id }.merge(opts) if id
9
- line = DrawioDsl::Schema::Line.new(current_page, **opts, &block)
10
- add_shape(line)
9
+ solid = DrawioDsl::Schema::Solid.new(current_page, **opts, &block)
10
+ add_shape(solid)
11
11
  end
12
12
 
13
13
  def add_h1(id = nil, **opts, &block)
@@ -7,7 +7,7 @@ module DrawioDsl
7
7
  def random(**opts)
8
8
  case rand(44)
9
9
  when 0
10
- line(**opts)
10
+ solid(**opts)
11
11
  when 1
12
12
  h1(**opts)
13
13
  when 2
@@ -97,8 +97,8 @@ module DrawioDsl
97
97
  end
98
98
  end
99
99
 
100
- def line(id = nil, **opts, &block)
101
- builder.add_line(id, **opts, &block)
100
+ def solid(id = nil, **opts, &block)
101
+ builder.add_solid(id, **opts, &block)
102
102
  end
103
103
 
104
104
  def h1(id = nil, **opts, &block)
@@ -11,50 +11,60 @@ require_relative 'layouts/layout'
11
11
  require_relative 'layouts/flex_layout'
12
12
  require_relative 'layouts/grid_layout'
13
13
 
14
- require_relative 'shapes/shape'
15
- require_relative 'shapes/line'
16
- require_relative 'shapes/h1'
17
- require_relative 'shapes/h2'
18
- require_relative 'shapes/h3'
19
- require_relative 'shapes/h4'
20
- require_relative 'shapes/h5'
21
- require_relative 'shapes/h6'
22
- require_relative 'shapes/p'
23
- require_relative 'shapes/actor'
24
- require_relative 'shapes/actor2'
25
- require_relative 'shapes/callout'
26
- require_relative 'shapes/callout2'
27
- require_relative 'shapes/callout3'
28
- require_relative 'shapes/callout4'
29
- require_relative 'shapes/circle'
30
- require_relative 'shapes/cloud'
31
- require_relative 'shapes/container'
32
- require_relative 'shapes/container2'
33
- require_relative 'shapes/container3'
34
- require_relative 'shapes/container4'
35
- require_relative 'shapes/cross'
36
- require_relative 'shapes/envelop'
37
- require_relative 'shapes/database'
38
- require_relative 'shapes/db_json'
39
- require_relative 'shapes/diamond'
40
- require_relative 'shapes/document'
41
- require_relative 'shapes/ellipse'
42
- require_relative 'shapes/group'
43
- require_relative 'shapes/hexagon'
44
- require_relative 'shapes/interface'
45
- require_relative 'shapes/klass'
46
- require_relative 'shapes/note'
47
- require_relative 'shapes/process'
48
- require_relative 'shapes/rectangle'
49
- require_relative 'shapes/rectangle2'
50
- require_relative 'shapes/square'
51
- require_relative 'shapes/step'
52
- require_relative 'shapes/tick'
53
- require_relative 'shapes/todo'
54
- require_relative 'shapes/face'
55
- require_relative 'shapes/triangle'
56
- require_relative 'shapes/embed_row'
57
- require_relative 'shapes/embed_col50'
58
- require_relative 'shapes/embed_col200'
14
+ require_relative 'shape'
15
+ require_relative 'element'
16
+ require_relative 'line'
17
+ require_relative 'text'
59
18
 
19
+ # Block elements such as actor, callout, square, circle, etc.
20
+ require_relative 'elements/actor'
21
+ require_relative 'elements/actor2'
22
+ require_relative 'elements/callout'
23
+ require_relative 'elements/callout2'
24
+ require_relative 'elements/callout3'
25
+ require_relative 'elements/callout4'
26
+ require_relative 'elements/circle'
27
+ require_relative 'elements/cloud'
28
+ require_relative 'elements/container'
29
+ require_relative 'elements/container2'
30
+ require_relative 'elements/container3'
31
+ require_relative 'elements/container4'
32
+ require_relative 'elements/cross'
33
+ require_relative 'elements/envelop'
34
+ require_relative 'elements/database'
35
+ require_relative 'elements/db_json'
36
+ require_relative 'elements/diamond'
37
+ require_relative 'elements/document'
38
+ require_relative 'elements/ellipse'
39
+ require_relative 'elements/group'
40
+ require_relative 'elements/hexagon'
41
+ require_relative 'elements/interface'
42
+ require_relative 'elements/klass'
43
+ require_relative 'elements/note'
44
+ require_relative 'elements/process'
45
+ require_relative 'elements/rectangle'
46
+ require_relative 'elements/rectangle2'
47
+ require_relative 'elements/square'
48
+ require_relative 'elements/step'
49
+ require_relative 'elements/tick'
50
+ require_relative 'elements/todo'
51
+ require_relative 'elements/face'
52
+ require_relative 'elements/triangle'
53
+ require_relative 'elements/embed_row'
54
+ require_relative 'elements/embed_col50'
55
+ require_relative 'elements/embed_col200'
56
+
57
+ # Connector lines
58
+ require_relative 'lines/solid'
59
+
60
+ # Text elements such as h1, h2, p, etc.
61
+ require_relative 'texts/h1'
62
+ require_relative 'texts/h2'
63
+ require_relative 'texts/h3'
64
+ require_relative 'texts/h4'
65
+ require_relative 'texts/h5'
66
+ require_relative 'texts/h6'
67
+ require_relative 'texts/p'
68
+
69
+ # Virtual elements have internal uses
60
70
  require_relative 'virtual/anchor'
@@ -6,16 +6,17 @@ module DrawioDsl
6
6
  class Diagram
7
7
  attr_accessor :host
8
8
  attr_accessor :theme
9
+ attr_accessor :bg_theme
9
10
  attr_accessor :style
10
11
  attr_accessor :palette
11
12
  attr_accessor :pages
12
13
 
13
14
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
14
15
  def initialize(**args)
15
- @host = args[:host] || SecureRandom.alphanumeric(3)
16
-
17
- # Apply a random theme to the diagram if none is specified.
18
- @theme = args[:theme] || KConfig.configuration.drawio.random_theme
16
+ @host = args[:host] || SecureRandom.alphanumeric(3)
17
+ # TODO: assess and resolve this inconsistency
18
+ @theme = args[:theme] || KConfig.configuration.drawio.theme.random_background_type
19
+ @bg_theme = args[:bg_theme] || :not_set
19
20
 
20
21
  @style = DrawioDsl::Schema::CommonStyle.new(**args) do
21
22
  default_style = KConfig.configuration.drawio.base_style
@@ -30,19 +31,24 @@ module DrawioDsl
30
31
  end
31
32
 
32
33
  @palette = DrawioDsl::Schema::DefaultPalette.new(self, **args) do |diagram|
33
- theme_palette = KConfig.configuration.drawio.palette(diagram.theme)
34
-
35
- # Inherit from theme when specific palette options are not specified.
36
- @fill_color ||= theme_palette.fill_color
37
- @stroke_color ||= theme_palette.stroke_color
38
- @font_color ||= theme_palette.font_color
39
- @gradient ||= theme_palette.gradient
34
+ @fill_color ||= diagram.theme_palette.fill_color
35
+ @stroke_color ||= diagram.theme_palette.stroke_color
36
+ @font_color ||= diagram.theme_palette.font_color
37
+ @gradient ||= diagram.theme_palette.gradient
40
38
  end
41
39
 
42
40
  @pages = args[:pages] || []
43
41
  end
44
42
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
45
43
 
44
+ def theme_palette
45
+ @theme_palette ||= KConfig.configuration.drawio.theme.element(theme)
46
+ end
47
+
48
+ def bg_theme_palette
49
+ @bg_theme_palette ||= KConfig.configuration.drawio.theme.background(bg_theme)
50
+ end
51
+
46
52
  def to_h
47
53
  {
48
54
  host: host,
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ # Elements represents some kind of shape such as a Square, Circle, Callout, Actor, etc.
6
+ class Element < Shape
7
+ class << self
8
+ def configure_as(key)
9
+ configure_shape(key, :element)
10
+ end
11
+ end
12
+
13
+ def apply_defaults(args)
14
+ super(args)
15
+
16
+ @fill_color = args[:fill_color] || theme_palette.fill_color
17
+ @stroke_color = args[:stroke_color] || theme_palette.stroke_color
18
+ @gradient = args[:gradient] || theme_palette.gradient
19
+ @font_color = args[:font_color] || theme_palette.font_color
20
+ end
21
+ end
22
+ end
23
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Face < Shape
6
- configure_shape(:face)
5
+ class Actor < Element
6
+ configure_as(:actor)
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Cross < Shape
6
- configure_shape(:cross)
5
+ class Actor2 < Element
6
+ configure_as(:actor2)
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Actor2 < Shape
6
- configure_shape(:actor2)
5
+ class Callout < Element
6
+ configure_as(:callout)
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Callout < Shape
6
- configure_shape(:callout)
5
+ class Callout2 < Element
6
+ configure_as(:callout2)
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 Callout3 < Element
6
+ configure_as(: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 < Element
6
+ configure_as(:callout4)
7
+ end
8
+ end
9
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Actor < Shape
6
- configure_shape(:actor)
5
+ class Circle < Element
6
+ configure_as(:circle)
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 Cloud < Element
6
+ configure_as(:cloud)
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 < Element
6
+ configure_as(: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 < Element
6
+ configure_as(: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 < Element
6
+ configure_as(: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 < Element
6
+ configure_as(: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 < Element
6
+ configure_as(: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 Database < Element
6
+ configure_as(:database)
7
+ end
8
+ end
9
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DrawioDsl
4
4
  module Schema
5
- class Circle < Shape
6
- configure_shape(:circle)
5
+ class DbJson < Element
6
+ configure_as(:db_json)
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 Diamond < Element
6
+ configure_as(:diamond)
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 < Element
6
+ configure_as(: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 Ellipse < Element
6
+ configure_as(:ellipse)
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 < Element
6
+ configure_as(:embed_col200)
7
+ end
8
+ end
9
+ end