drawio_dsl 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/.templates/command.rb +8 -0
- data/.builders/.templates/schema_shape.rb +9 -0
- data/.builders/blueprint/shapes.rb +19 -0
- data/.builders/boot.rb +1 -0
- data/.builders/generators/25-themes.rb +3 -0
- data/CHANGELOG.md +7 -0
- data/lib/drawio_dsl/configuration.rb +36 -27
- data/lib/drawio_dsl/dom_builder.rb +15 -0
- data/lib/drawio_dsl/drawio.rb +19 -1
- data/lib/drawio_dsl/layout_engine.rb +1 -1
- data/lib/drawio_dsl/schema/_.rb +23 -0
- data/lib/drawio_dsl/schema/common_style.rb +42 -0
- data/lib/drawio_dsl/schema/default_palette.rb +31 -0
- data/lib/drawio_dsl/schema/diagram.rb +57 -0
- data/lib/drawio_dsl/schema/layouts/flex_layout.rb +87 -0
- data/lib/drawio_dsl/schema/layouts/grid_layout.rb +102 -0
- data/lib/drawio_dsl/schema/layouts/layout.rb +41 -0
- data/lib/drawio_dsl/schema/node.rb +53 -0
- data/lib/drawio_dsl/schema/page.rb +135 -0
- data/lib/drawio_dsl/schema/shapes/callout.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/circle.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/cloud.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/diamond.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/ellipse.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/hexagon.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/note.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/process.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/rectangle.rb +9 -0
- data/lib/drawio_dsl/schema/shapes/shape.rb +125 -0
- data/lib/drawio_dsl/schema/shapes/square.rb +9 -0
- data/lib/drawio_dsl/version.rb +1 -1
- data/lib/drawio_dsl.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +25 -3
- data/lib/drawio_dsl/schema.rb +0 -617
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DrawioDsl
|
4
|
+
module Schema
|
5
|
+
# Node is a base class for shapes, connections, positioners and layout rules
|
6
|
+
#
|
7
|
+
class Node
|
8
|
+
attr_accessor :id
|
9
|
+
attr_accessor :page
|
10
|
+
attr_accessor :classification
|
11
|
+
|
12
|
+
def initialize(page, **args)
|
13
|
+
@page = page
|
14
|
+
@id = args[:id]
|
15
|
+
@classification = args[:classification] || :unknown
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
{
|
20
|
+
id: id,
|
21
|
+
classification: classification
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# def debug(format: :detail)
|
26
|
+
# if format == :detail
|
27
|
+
# debug_detail(to_h)
|
28
|
+
# else
|
29
|
+
# debug_row(classification, id)
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# def debug_detail(**key_values)
|
34
|
+
# key_values.each do |key, value|
|
35
|
+
# puts "#{key.to_s.ljust(15)}: #{value}"
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
#
|
40
|
+
# def debug_row(classification, id, type = nil, x = nil, y = nil, width = nil, height = nil)
|
41
|
+
# row = []
|
42
|
+
# row << classification.to_s.ljust(11)
|
43
|
+
# row << id.to_s.ljust(6)
|
44
|
+
# row << (type.nil? ? '' : type).to_s.ljust(15)
|
45
|
+
# row << (x.nil? ? '' : x).to_s.rjust(5)
|
46
|
+
# row << (y.nil? ? '' : y).to_s.rjust(5)
|
47
|
+
# row << (width.nil? ? '' : width).to_s.rjust(5)
|
48
|
+
# row << (height.nil? ? '' : height).to_s.rjust(5)
|
49
|
+
# puts row.join(' | ')
|
50
|
+
# end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -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,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
|
data/lib/drawio_dsl/version.rb
CHANGED
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.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "drawio_dsl",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.4.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
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.
|
4
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: k_config
|
@@ -73,7 +73,10 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".builders/.templates/command.rb"
|
77
|
+
- ".builders/.templates/schema_shape.rb"
|
76
78
|
- ".builders/_.rb"
|
79
|
+
- ".builders/blueprint/shapes.rb"
|
77
80
|
- ".builders/boot.rb"
|
78
81
|
- ".builders/generators/01-bootstrap.rb"
|
79
82
|
- ".builders/generators/10-page-margin.rb"
|
@@ -99,7 +102,26 @@ files:
|
|
99
102
|
- lib/drawio_dsl/dom_builder.rb
|
100
103
|
- lib/drawio_dsl/drawio.rb
|
101
104
|
- lib/drawio_dsl/layout_engine.rb
|
102
|
-
- lib/drawio_dsl/schema.rb
|
105
|
+
- lib/drawio_dsl/schema/_.rb
|
106
|
+
- lib/drawio_dsl/schema/common_style.rb
|
107
|
+
- lib/drawio_dsl/schema/default_palette.rb
|
108
|
+
- lib/drawio_dsl/schema/diagram.rb
|
109
|
+
- lib/drawio_dsl/schema/layouts/flex_layout.rb
|
110
|
+
- lib/drawio_dsl/schema/layouts/grid_layout.rb
|
111
|
+
- lib/drawio_dsl/schema/layouts/layout.rb
|
112
|
+
- lib/drawio_dsl/schema/node.rb
|
113
|
+
- lib/drawio_dsl/schema/page.rb
|
114
|
+
- lib/drawio_dsl/schema/shapes/callout.rb
|
115
|
+
- lib/drawio_dsl/schema/shapes/circle.rb
|
116
|
+
- lib/drawio_dsl/schema/shapes/cloud.rb
|
117
|
+
- lib/drawio_dsl/schema/shapes/diamond.rb
|
118
|
+
- lib/drawio_dsl/schema/shapes/ellipse.rb
|
119
|
+
- lib/drawio_dsl/schema/shapes/hexagon.rb
|
120
|
+
- lib/drawio_dsl/schema/shapes/note.rb
|
121
|
+
- lib/drawio_dsl/schema/shapes/process.rb
|
122
|
+
- lib/drawio_dsl/schema/shapes/rectangle.rb
|
123
|
+
- lib/drawio_dsl/schema/shapes/shape.rb
|
124
|
+
- lib/drawio_dsl/schema/shapes/square.rb
|
103
125
|
- lib/drawio_dsl/version.rb
|
104
126
|
- lib/drawio_dsl/xml_builder.rb
|
105
127
|
- package-lock.json
|