drawio_dsl 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/.data/shapes.json +82 -0
  3. data/.builders/.templates/basic/schema_require.rb +16 -0
  4. data/.builders/.templates/schema_shape.rb +9 -0
  5. data/.builders/.templates/schema_shape_spec.rb +13 -0
  6. data/.builders/blueprint/shapes.rb +29 -0
  7. data/.builders/boot.rb +5 -0
  8. data/.builders/generators/90-requires.rb +35 -0
  9. data/.builders/generators/sample_diagrams/10-page-margin.rb +46 -0
  10. data/.builders/generators/sample_diagrams/15-grid-direction.rb +40 -0
  11. data/.builders/generators/sample_diagrams/16-grid-alignment.rb +73 -0
  12. data/.builders/generators/sample_diagrams/20-styles.rb +64 -0
  13. data/.builders/generators/sample_diagrams/25-themes.rb +24 -0
  14. data/.rubocop.yml +2 -1
  15. data/CHANGELOG.md +21 -0
  16. data/lib/drawio_dsl/configuration.rb +56 -43
  17. data/lib/drawio_dsl/dom_builder.rb +25 -0
  18. data/lib/drawio_dsl/drawio.rb +49 -0
  19. data/lib/drawio_dsl/layout_engine.rb +12 -28
  20. data/lib/drawio_dsl/schema/_.rb +23 -0
  21. data/lib/drawio_dsl/schema/common_style.rb +42 -0
  22. data/lib/drawio_dsl/schema/default_palette.rb +31 -0
  23. data/lib/drawio_dsl/schema/diagram.rb +57 -0
  24. data/lib/drawio_dsl/schema/layouts/flex_layout.rb +87 -0
  25. data/lib/drawio_dsl/schema/layouts/grid_layout.rb +102 -0
  26. data/lib/drawio_dsl/schema/layouts/layout.rb +41 -0
  27. data/lib/drawio_dsl/schema/node.rb +53 -0
  28. data/lib/drawio_dsl/schema/page.rb +135 -0
  29. data/lib/drawio_dsl/schema/shapes/callout.rb +9 -0
  30. data/lib/drawio_dsl/schema/shapes/circle.rb +9 -0
  31. data/lib/drawio_dsl/schema/shapes/cloud.rb +9 -0
  32. data/lib/drawio_dsl/schema/shapes/diamond.rb +9 -0
  33. data/lib/drawio_dsl/schema/shapes/ellipse.rb +9 -0
  34. data/lib/drawio_dsl/schema/shapes/hexagon.rb +9 -0
  35. data/lib/drawio_dsl/schema/shapes/note.rb +9 -0
  36. data/lib/drawio_dsl/schema/shapes/process.rb +9 -0
  37. data/lib/drawio_dsl/schema/shapes/rectangle.rb +9 -0
  38. data/lib/drawio_dsl/schema/shapes/shape.rb +125 -0
  39. data/lib/drawio_dsl/schema/shapes/square.rb +9 -0
  40. data/lib/drawio_dsl/version.rb +1 -1
  41. data/lib/drawio_dsl.rb +1 -1
  42. data/package-lock.json +2 -2
  43. data/package.json +1 -1
  44. metadata +33 -5
  45. data/.builders/generators/10-layout.rb +0 -34
  46. data/lib/drawio_dsl/drawio_dsl-OLD.x +0 -335
  47. data/lib/drawio_dsl/schema.rb +0 -604
@@ -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 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 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 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 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 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,125 @@
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
+ def configure_shape(name)
9
+ raise "Shape #{name} not found in configuration" unless KConfig.configuration.drawio.shapes.members.include?(name)
10
+
11
+ config = KConfig.configuration.drawio.shapes[name]
12
+
13
+ @shape_defaults = config.clone
14
+ end
15
+
16
+ def shape_defaults
17
+ return @shape_defaults if defined? @shape_defaults
18
+
19
+ raise 'Shape defaults not configured'
20
+ end
21
+ end
22
+
23
+ configure_shape(:shape)
24
+
25
+ attr_accessor :theme
26
+ attr_accessor :title
27
+
28
+ # The style of the element, these will derive from the page style if not provided
29
+ attr_accessor :white_space
30
+ attr_accessor :html
31
+ attr_accessor :rounded
32
+ attr_accessor :shadow
33
+ attr_accessor :glass
34
+ attr_accessor :sketch
35
+
36
+ attr_accessor :fill_color
37
+ attr_accessor :stroke_color
38
+ attr_accessor :font_color
39
+ attr_accessor :gradient
40
+
41
+ attr_accessor :type
42
+ attr_accessor :x
43
+ attr_accessor :y
44
+ attr_accessor :w
45
+ attr_accessor :h
46
+ attr_accessor :style_modifiers
47
+
48
+ def initialize(page, **args)
49
+ args[:classification] = :shape
50
+ super(page, **args)
51
+
52
+ apply_defaults(args)
53
+ end
54
+
55
+ def shape_defaults
56
+ @shape_defaults ||= self.class.shape_defaults.clone
57
+ end
58
+
59
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
60
+ def apply_defaults(args)
61
+ @theme = args[:theme] || page.theme # KConfig.configuration.drawio.themes.sample
62
+ theme_palette = KConfig.configuration.drawio.palette(theme)
63
+ @title = args[:title] || ''
64
+
65
+ @white_space = args[:white_space] || page.style.white_space # wrap or nil
66
+ @html = args[:html] || page.style.html
67
+ @rounded = args[:rounded] || page.style.rounded
68
+ @shadow = args[:shadow] || page.style.shadow
69
+ @sketch = args[:sketch] || page.style.sketch
70
+ @glass = args[:glass] || page.style.glass
71
+
72
+ @type = args[:type] || shape_defaults.type
73
+ @x = args[:x] || shape_defaults.x
74
+ @y = args[:y] || shape_defaults.y
75
+ @w = args[:w] || shape_defaults.w
76
+ @h = args[:h] || shape_defaults.h
77
+ @style_modifiers = args[:style_modifiers] || shape_defaults.style_modifiers
78
+
79
+ @fill_color = args[:fill_color] || theme_palette.fill_color
80
+ @stroke_color = args[:stroke_color] || theme_palette.stroke_color
81
+ @font_color = args[:font_color] || theme_palette.font_color
82
+ @gradient = args[:gradient] || theme_palette.gradient
83
+ end
84
+
85
+ def style
86
+ key_values = []
87
+ key_values << style_modifiers unless style_modifiers.empty?
88
+ key_values << "whiteSpace=#{white_space}" if white_space
89
+ key_values << "html=#{html}" if html
90
+ key_values << "rounded=#{rounded}" if rounded
91
+ key_values << "shadow=#{shadow}" if shadow
92
+ key_values << "sketch=#{sketch}" if sketch
93
+ key_values << "glass=#{glass}" if glass
94
+ key_values << "fillColor=#{fill_color}" if fill_color
95
+ key_values << "strokeColor=#{stroke_color}" if stroke_color
96
+ key_values << "fontColor=#{font_color}" if font_color
97
+ key_values << "gradient=#{gradient}" if gradient
98
+
99
+ key_values.join(';')
100
+ end
101
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
102
+
103
+ def to_h
104
+ {
105
+ id: id,
106
+ classification: classification,
107
+ type: type,
108
+ x: x,
109
+ y: y,
110
+ w: w,
111
+ h: h,
112
+ style: style
113
+ }
114
+ end
115
+
116
+ def debug(format: :detail)
117
+ if format == :detail
118
+ debug_detail({ id: id, classification: classification, type: type })
119
+ else
120
+ debug_row(classification, id, type, x, y, w, h)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DrawioDsl
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.1'
5
5
  end
data/lib/drawio_dsl.rb CHANGED
@@ -9,7 +9,7 @@ require 'k_director'
9
9
 
10
10
  require_relative 'drawio_dsl/configuration'
11
11
  require_relative 'drawio_dsl/version'
12
- require_relative 'drawio_dsl/schema'
12
+ require_relative 'drawio_dsl/schema/_'
13
13
  require_relative 'drawio_dsl/dom_builder'
14
14
  require_relative 'drawio_dsl/xml_builder'
15
15
  require_relative 'drawio_dsl/layout_engine'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.2.0",
3
+ "version": "0.4.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "drawio_dsl",
9
- "version": "0.2.0",
9
+ "version": "0.4.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.2.0",
3
+ "version": "0.4.1",
4
4
  "description": "DrawIO DSL can build DrawIO diagrams using a Domain Specific Language",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drawio_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_config
@@ -73,10 +73,20 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".builders/.data/shapes.json"
77
+ - ".builders/.templates/basic/schema_require.rb"
78
+ - ".builders/.templates/schema_shape.rb"
79
+ - ".builders/.templates/schema_shape_spec.rb"
76
80
  - ".builders/_.rb"
81
+ - ".builders/blueprint/shapes.rb"
77
82
  - ".builders/boot.rb"
78
83
  - ".builders/generators/01-bootstrap.rb"
79
- - ".builders/generators/10-layout.rb"
84
+ - ".builders/generators/90-requires.rb"
85
+ - ".builders/generators/sample_diagrams/10-page-margin.rb"
86
+ - ".builders/generators/sample_diagrams/15-grid-direction.rb"
87
+ - ".builders/generators/sample_diagrams/16-grid-alignment.rb"
88
+ - ".builders/generators/sample_diagrams/20-styles.rb"
89
+ - ".builders/generators/sample_diagrams/25-themes.rb"
80
90
  - ".releaserc.json"
81
91
  - ".rspec"
82
92
  - ".rubocop.yml"
@@ -94,9 +104,27 @@ files:
94
104
  - lib/drawio_dsl/configuration.rb
95
105
  - lib/drawio_dsl/dom_builder.rb
96
106
  - lib/drawio_dsl/drawio.rb
97
- - lib/drawio_dsl/drawio_dsl-OLD.x
98
107
  - lib/drawio_dsl/layout_engine.rb
99
- - lib/drawio_dsl/schema.rb
108
+ - lib/drawio_dsl/schema/_.rb
109
+ - lib/drawio_dsl/schema/common_style.rb
110
+ - lib/drawio_dsl/schema/default_palette.rb
111
+ - lib/drawio_dsl/schema/diagram.rb
112
+ - lib/drawio_dsl/schema/layouts/flex_layout.rb
113
+ - lib/drawio_dsl/schema/layouts/grid_layout.rb
114
+ - lib/drawio_dsl/schema/layouts/layout.rb
115
+ - lib/drawio_dsl/schema/node.rb
116
+ - lib/drawio_dsl/schema/page.rb
117
+ - lib/drawio_dsl/schema/shapes/callout.rb
118
+ - lib/drawio_dsl/schema/shapes/circle.rb
119
+ - lib/drawio_dsl/schema/shapes/cloud.rb
120
+ - lib/drawio_dsl/schema/shapes/diamond.rb
121
+ - lib/drawio_dsl/schema/shapes/ellipse.rb
122
+ - lib/drawio_dsl/schema/shapes/hexagon.rb
123
+ - lib/drawio_dsl/schema/shapes/note.rb
124
+ - lib/drawio_dsl/schema/shapes/process.rb
125
+ - lib/drawio_dsl/schema/shapes/rectangle.rb
126
+ - lib/drawio_dsl/schema/shapes/shape.rb
127
+ - lib/drawio_dsl/schema/shapes/square.rb
100
128
  - lib/drawio_dsl/version.rb
101
129
  - lib/drawio_dsl/xml_builder.rb
102
130
  - package-lock.json
@@ -1,34 +0,0 @@
1
- KManager.action :bootstrap do
2
- action do
3
- director = DrawioDsl::Drawio
4
- .init(k_builder,
5
- on_exist: :skip, # %i[skip write compare]
6
- on_action: :queue # %i[queue execute]
7
- )
8
- .diagram(theme: :style_01)
9
- .page('Grid-Right', page_shadow: 1) do
10
- grid_layout(wrap_at: 3)
11
- square(title: 'Square')
12
- rectangle(title: 'Rectangle')
13
- rectangle(title: 'Rectangle (Rounded)', rounded: 1)
14
- circle(title: 'Circle')
15
- process(title: 'Process')
16
- ellipse(title: 'Ellipse')
17
- end
18
-
19
- diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
20
-
21
-
22
- File.write('../spec/.samples/drawio/10-layout.xml', diagram.build)
23
- File.write('../spec/.samples/drawio/10-layout.drawio', diagram.build)
24
- end
25
- end
26
-
27
- KManager.opts.app_name = 'drawio_dsl'
28
- KManager.opts.sleep = 2
29
- KManager.opts.reboot_on_kill = 0
30
- KManager.opts.reboot_sleep = 4
31
- KManager.opts.exception_style = :short
32
- KManager.opts.show.time_taken = true
33
- KManager.opts.show.finished = true
34
- KManager.opts.show.finished_message = 'FINISHED :)'