drawio_dsl 0.11.4 → 0.11.7

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.
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DrawioDsl
4
+ module Schema
5
+ # Build the style attribute for shape elements
6
+ #
7
+ # Requirements:
8
+ # Need to be able to take a string and break it up into style parts
9
+ # A style part is usually a lowerCamel equals value pair (e.g. fontSize=12)
10
+ # but sometimes it is just a singular value, (e.g. ellipse)
11
+ # A string may also contain more then one style part separated by semi-colons
12
+ # e.g. overflow=fill;fontSize=12;fontFamily=Helvetica
13
+ #
14
+ # The purpose of this class is to build a style attribute with unique values and
15
+ # to take inputs from either single key/value pairs or string following the
16
+ # pattern previously described.
17
+ class StyleBuilder
18
+ def initialize
19
+ @style_parts = []
20
+ end
21
+
22
+ def add(value)
23
+ return if value.nil?
24
+
25
+ if value.is_a?(Symbol)
26
+ set(value)
27
+ return
28
+ end
29
+
30
+ value.split(';') do |v|
31
+ kv = v.to_s.split('=')
32
+
33
+ if kv.length == 1
34
+ set(v.to_s)
35
+ else
36
+ set_kv(kv[0], kv[1])
37
+ end
38
+ end
39
+ end
40
+
41
+ def add_kv(key, value)
42
+ key = camel_case_lower(key) if key.is_a?(Symbol)
43
+
44
+ set_kv(key, value)
45
+ end
46
+
47
+ def style
48
+ @style_parts.join(';')
49
+ end
50
+
51
+ # def style_attribute
52
+ # style_value = style
53
+ # style_value.empty? ? nil : " style=\"#{style_value}\""
54
+ # end
55
+
56
+ private
57
+
58
+ def camel_case_lower(key)
59
+ key.to_s.split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
60
+ end
61
+
62
+ def set(value)
63
+ value = value.to_s.strip
64
+ index = @style_parts.index { |part| part == value }
65
+
66
+ @style_parts << value if index.nil?
67
+ end
68
+
69
+ def set_kv(key, value)
70
+ key = key.to_s.strip
71
+ value = value.to_s.strip
72
+ index = @style_parts.index { |part| part.start_with?("#{key}=") }
73
+
74
+ if index.nil?
75
+ @style_parts << "#{key}=#{value}"
76
+ else
77
+ @style_parts[index] = "#{key}=#{value}"
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DrawioDsl
4
- VERSION = '0.11.4'
4
+ VERSION = '0.11.7'
5
5
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.11.4",
3
+ "version": "0.11.7",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "drawio_dsl",
9
- "version": "0.11.4",
9
+ "version": "0.11.7",
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.11.4",
3
+ "version": "0.11.7",
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.11.4
4
+ version: 0.11.7
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-28 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_config
@@ -365,6 +365,7 @@ files:
365
365
  - lib/drawio_dsl/schema/node_list.rb
366
366
  - lib/drawio_dsl/schema/page.rb
367
367
  - lib/drawio_dsl/schema/shape.rb
368
+ - lib/drawio_dsl/schema/style_builder.rb
368
369
  - lib/drawio_dsl/schema/text.rb
369
370
  - lib/drawio_dsl/schema/texts/h1.rb
370
371
  - lib/drawio_dsl/schema/texts/h2.rb