drawio_dsl 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/.data/shapes.json +218 -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 +48 -0
  10. data/.builders/boot.rb +6 -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} +5 -2
  17. data/.builders/generators/sample_diagrams/30-shapes.rb +23 -0
  18. data/.rubocop.yml +20 -3
  19. data/CHANGELOG.md +21 -0
  20. data/README.md +4 -0
  21. data/lib/drawio_dsl/configuration.rb +7 -94
  22. data/lib/drawio_dsl/configuration_extension.rb +13 -0
  23. data/lib/drawio_dsl/configuration_shapes.rb +75 -0
  24. data/lib/drawio_dsl/configuration_themes.rb +63 -0
  25. data/lib/drawio_dsl/dom_builder.rb +4 -35
  26. data/lib/drawio_dsl/dom_builder_shapes.rb +143 -0
  27. data/lib/drawio_dsl/drawio.rb +1 -73
  28. data/lib/drawio_dsl/drawio_shapes.rb +175 -0
  29. data/lib/drawio_dsl/layout_engine.rb +1 -1
  30. data/lib/drawio_dsl/schema/_.rb +40 -0
  31. data/lib/drawio_dsl/schema/common_style.rb +42 -0
  32. data/lib/drawio_dsl/schema/default_palette.rb +31 -0
  33. data/lib/drawio_dsl/schema/diagram.rb +57 -0
  34. data/lib/drawio_dsl/schema/layouts/flex_layout.rb +87 -0
  35. data/lib/drawio_dsl/schema/layouts/grid_layout.rb +102 -0
  36. data/lib/drawio_dsl/schema/layouts/layout.rb +41 -0
  37. data/lib/drawio_dsl/schema/node.rb +53 -0
  38. data/lib/drawio_dsl/schema/page.rb +135 -0
  39. data/lib/drawio_dsl/schema/shapes/actor.rb +9 -0
  40. data/lib/drawio_dsl/schema/shapes/actor2.rb +9 -0
  41. data/lib/drawio_dsl/schema/shapes/callout.rb +9 -0
  42. data/lib/drawio_dsl/schema/shapes/callout2.rb +9 -0
  43. data/lib/drawio_dsl/schema/shapes/callout3.rb +9 -0
  44. data/lib/drawio_dsl/schema/shapes/callout4.rb +9 -0
  45. data/lib/drawio_dsl/schema/shapes/circle.rb +9 -0
  46. data/lib/drawio_dsl/schema/shapes/cloud.rb +9 -0
  47. data/lib/drawio_dsl/schema/shapes/container.rb +9 -0
  48. data/lib/drawio_dsl/schema/shapes/container2.rb +9 -0
  49. data/lib/drawio_dsl/schema/shapes/container3.rb +9 -0
  50. data/lib/drawio_dsl/schema/shapes/container4.rb +9 -0
  51. data/lib/drawio_dsl/schema/shapes/cross.rb +9 -0
  52. data/lib/drawio_dsl/schema/shapes/diamond.rb +9 -0
  53. data/lib/drawio_dsl/schema/shapes/document.rb +9 -0
  54. data/lib/drawio_dsl/schema/shapes/ellipse.rb +9 -0
  55. data/lib/drawio_dsl/schema/shapes/envelop.rb +9 -0
  56. data/lib/drawio_dsl/schema/shapes/face.rb +9 -0
  57. data/lib/drawio_dsl/schema/shapes/hexagon.rb +9 -0
  58. data/lib/drawio_dsl/schema/shapes/note.rb +9 -0
  59. data/lib/drawio_dsl/schema/shapes/process.rb +9 -0
  60. data/lib/drawio_dsl/schema/shapes/rectangle.rb +9 -0
  61. data/lib/drawio_dsl/schema/shapes/rectangle2.rb +9 -0
  62. data/lib/drawio_dsl/schema/shapes/shape.rb +123 -0
  63. data/lib/drawio_dsl/schema/shapes/square.rb +9 -0
  64. data/lib/drawio_dsl/schema/shapes/step.rb +9 -0
  65. data/lib/drawio_dsl/schema/shapes/tick.rb +9 -0
  66. data/lib/drawio_dsl/schema/shapes/triangle.rb +9 -0
  67. data/lib/drawio_dsl/version.rb +1 -1
  68. data/lib/drawio_dsl.rb +6 -1
  69. data/package-lock.json +2 -2
  70. data/package.json +1 -1
  71. metadata +59 -8
  72. data/lib/drawio_dsl/schema.rb +0 -617
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ # Page is a container for nodes
6
+ class Page
7
+ attr_accessor :diagram
8
+
9
+ # These transient attributes hold the current x, y location for the last element added to the page
10
+ attr_accessor :position_x
11
+ attr_accessor :position_y
12
+
13
+ attr_accessor :id
14
+ attr_reader :name
15
+ attr_reader :theme
16
+ attr_reader :style
17
+ attr_reader :palette
18
+ attr_reader :margin_left
19
+ attr_reader :margin_top
20
+ attr_reader :nodes
21
+
22
+ attr_reader :grid # grid = "0"
23
+ attr_reader :grid_size # gridSize = "10"
24
+ attr_reader :guides # guides = "1"
25
+ attr_reader :tooltips # tooltips = "1"
26
+ attr_reader :connect # connect = "1"
27
+ attr_reader :arrows # arrows = "1"
28
+ attr_reader :fold # fold = "1"
29
+ attr_reader :page_no # page = "1"
30
+ attr_reader :page_scale # pageScale = "1"
31
+ attr_reader :page_width # pageWidth = "583"
32
+ attr_reader :page_height # pageHeight = "827"
33
+ attr_reader :background # background = "#FFFACD"
34
+ attr_reader :page_shadow # shadow = "0"
35
+ attr_reader :math # math = "0"
36
+
37
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
38
+ def initialize(diagram, **args)
39
+ @diagram = diagram
40
+
41
+ @id = args[:id]
42
+ @name = args[:name]
43
+ @theme = args[:theme] || diagram.theme
44
+
45
+ # cursor positioning is used by the layout engine
46
+ @position_x = 0
47
+ @position_y = 0
48
+
49
+ # settings to support the layout engine
50
+ @margin_left = args[:margin_left] || 50
51
+ @margin_top = args[:margin_top] || 50
52
+
53
+ # settings that live on the drawio page object
54
+ @grid = args[:grid] || 0
55
+ @grid_size = args[:grid_size] || 10
56
+ @guides = args[:guides] || 1
57
+ @tooltips = args[:tooltips] || 1
58
+ @connect = args[:connect] || 1
59
+ @arrows = args[:arrows] || 1
60
+ @fold = args[:fold] || 1
61
+ @page_no = args[:page_no] || 1
62
+ @page_scale = args[:page_scale] || 1
63
+ @page_width = args[:page_width] || 1169 # A4
64
+ @page_height = args[:page_height] || 827 # A4
65
+ @background = args[:background] || '#FFFACD'
66
+ @page_shadow = args[:page_shadow] || 0
67
+ @math = args[:math] || 0
68
+
69
+ @style = DrawioDsl::Schema::CommonStyle.new(**args) do
70
+ # Inherit from the diagram style when specific style not specified.
71
+ @white_space ||= diagram.style.white_space
72
+ @html ||= diagram.style.html
73
+ @rounded ||= diagram.style.rounded
74
+ @shadow ||= diagram.style.shadow
75
+ @sketch ||= diagram.style.sketch
76
+ @glass ||= diagram.style.glass
77
+ end
78
+
79
+ @palette = DrawioDsl::Schema::DefaultPalette.new(self, **args) do |page|
80
+ theme_palette = KConfig.configuration.drawio.palette(page.theme)
81
+
82
+ # Inherit from theme when specific palette options are not specified.
83
+ @fill_color ||= theme_palette.fill_color
84
+ @stroke_color ||= theme_palette.stroke_color
85
+ @font_color ||= theme_palette.font_color
86
+ @gradient ||= theme_palette.gradient
87
+ end
88
+
89
+ @nodes = args[:nodes] || []
90
+ end
91
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
92
+
93
+ def shapes
94
+ @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Shape) }
95
+ end
96
+
97
+ def to_h
98
+ {
99
+ id: id,
100
+ name: name,
101
+ position_x: position_x,
102
+ position_y: position_y,
103
+ theme: theme,
104
+ palette: palette.to_h,
105
+ style: style.to_h,
106
+ settings: settings,
107
+ nodes: nodes.map(&:to_h)
108
+ }
109
+ end
110
+
111
+ private
112
+
113
+ def settings
114
+ {
115
+ margin_left: margin_left,
116
+ margin_top: margin_top,
117
+ grid: grid,
118
+ grid_size: grid_size,
119
+ guides: guides,
120
+ tooltips: tooltips,
121
+ connect: connect,
122
+ arrows: arrows,
123
+ fold: fold,
124
+ page_no: page_no,
125
+ page_scale: page_scale,
126
+ page_width: page_width,
127
+ page_height: page_height,
128
+ background: background,
129
+ page_shadow: page_shadow,
130
+ math: math
131
+ }
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Actor < Shape
6
+ configure_shape(:actor)
7
+ end
8
+ end
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 Callout < Shape
6
+ configure_shape(:callout)
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 Circle < Shape
6
+ configure_shape(:circle)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Cloud < Shape
6
+ configure_shape(: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 < 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 Diamond < Shape
6
+ configure_shape(: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 < 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 Ellipse < Shape
6
+ configure_shape(: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 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 Hexagon < Shape
6
+ configure_shape(:hexagon)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Note < Shape
6
+ configure_shape(:note)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Process < Shape
6
+ configure_shape(:process)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Rectangle < Shape
6
+ configure_shape(:rectangle)
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
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ # Shape is a graphical element, it can be a shape, a text, or a group (todo)
6
+ class Shape < Node
7
+ class << self
8
+ attr_reader :shape_defaults
9
+
10
+ def configure_shape(name)
11
+ raise "Shape #{name} not found in configuration" unless KConfig.configuration.drawio.shapes.members.include?(name)
12
+
13
+ config = KConfig.configuration.drawio.shapes[name]
14
+
15
+ @shape_defaults = config.clone
16
+ end
17
+ end
18
+
19
+ configure_shape(:shape)
20
+
21
+ attr_accessor :theme
22
+ attr_accessor :title
23
+
24
+ # The style of the element, these will derive from the page style if not provided
25
+ attr_accessor :white_space
26
+ attr_accessor :html
27
+ attr_accessor :rounded
28
+ attr_accessor :shadow
29
+ attr_accessor :glass
30
+ attr_accessor :sketch
31
+
32
+ attr_accessor :fill_color
33
+ attr_accessor :stroke_color
34
+ attr_accessor :font_color
35
+ attr_accessor :gradient
36
+
37
+ attr_accessor :type
38
+ attr_accessor :x
39
+ attr_accessor :y
40
+ attr_accessor :w
41
+ attr_accessor :h
42
+ attr_accessor :style_modifiers
43
+
44
+ def initialize(page, **args)
45
+ args[:classification] = :shape
46
+ super(page, **args)
47
+
48
+ apply_defaults(args)
49
+ end
50
+
51
+ def shape_defaults
52
+ @shape_defaults ||= self.class.shape_defaults.clone
53
+ end
54
+
55
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
56
+ def apply_defaults(args)
57
+ @theme = args[:theme] || page.theme # KConfig.configuration.drawio.themes.sample
58
+ theme_palette = KConfig.configuration.drawio.palette(theme)
59
+ @title = args[:title] || ''
60
+
61
+ @white_space = args[:white_space] || page.style.white_space # wrap or nil
62
+ @html = args[:html] || page.style.html
63
+ @rounded = args[:rounded] || page.style.rounded
64
+ @shadow = args[:shadow] || page.style.shadow
65
+ @sketch = args[:sketch] || page.style.sketch
66
+ @glass = args[:glass] || page.style.glass
67
+
68
+ @type = args[:type] || shape_defaults.type
69
+ @x = args[:x] || shape_defaults.x
70
+ @y = args[:y] || shape_defaults.y
71
+ @w = args[:w] || shape_defaults.w
72
+ @h = args[:h] || shape_defaults.h
73
+ @style_modifiers = args[:style_modifiers] || shape_defaults.style_modifiers
74
+
75
+ @fill_color = args[:fill_color] || theme_palette.fill_color
76
+ @stroke_color = args[:stroke_color] || theme_palette.stroke_color
77
+ @font_color = args[:font_color] || theme_palette.font_color
78
+ @gradient = args[:gradient] || theme_palette.gradient
79
+ end
80
+
81
+ def style
82
+ key_values = []
83
+ key_values << style_modifiers unless style_modifiers.empty?
84
+ key_values << "whiteSpace=#{white_space}" if white_space
85
+ key_values << "html=#{html}" if html
86
+ key_values << "rounded=#{rounded}" if rounded
87
+ key_values << "shadow=#{shadow}" if shadow
88
+ key_values << "sketch=#{sketch}" if sketch
89
+ key_values << "glass=#{glass}" if glass
90
+ key_values << "fillColor=#{fill_color}" if fill_color
91
+ key_values << "strokeColor=#{stroke_color}" if stroke_color
92
+ key_values << "fontColor=#{font_color}" if font_color
93
+ key_values << "gradient=#{gradient}" if gradient
94
+
95
+ key_values.join(';')
96
+ end
97
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
98
+
99
+ def to_h
100
+ {
101
+ id: id,
102
+ classification: classification,
103
+ type: type,
104
+ x: x,
105
+ y: y,
106
+ w: w,
107
+ h: h,
108
+ style: style
109
+ }
110
+ end
111
+
112
+ # :nocov:
113
+ def debug(format: :detail)
114
+ if format == :detail
115
+ debug_detail({ id: id, classification: classification, type: type })
116
+ else
117
+ debug_row(classification, id, type, x, y, w, h)
118
+ end
119
+ end
120
+ # :nocov:
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ class Square < Shape
6
+ configure_shape(:square)
7
+ end
8
+ end
9
+ 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.3.0'
4
+ VERSION = '0.5.0'
5
5
  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
- require_relative 'drawio_dsl/schema'
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.3.0",
3
+ "version": "0.5.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "drawio_dsl",
9
- "version": "0.3.0",
9
+ "version": "0.5.0",
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.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "DrawIO DSL can build DrawIO diagrams using a Domain Specific Language",
5
5
  "scripts": {
6
6
  "release": "semantic-release"