lutaml-uml 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +36 -0
- data/.github/workflows/ubuntu.yml +38 -0
- data/.github/workflows/windows.yml +41 -0
- data/.gitignore +1 -0
- data/Gemfile +2 -1
- data/LUTAML.adoc +314 -0
- data/{README.md → README.adoc} +15 -16
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/bin/lutaml2dotpng +23 -0
- data/bin/yaml2lutaml +108 -0
- data/exe/lutaml-uml +4 -3
- data/lib/lutaml/layout/engine.rb +15 -0
- data/lib/lutaml/layout/graph_viz_engine.rb +16 -0
- data/lib/lutaml/uml.rb +3 -0
- data/lib/lutaml/uml/abstraction.rb +7 -5
- data/lib/lutaml/uml/activity.rb +7 -5
- data/lib/lutaml/uml/actor.rb +14 -12
- data/lib/lutaml/uml/association.rb +40 -14
- data/lib/lutaml/uml/behavior.rb +7 -5
- data/lib/lutaml/uml/class.rb +56 -16
- data/lib/lutaml/uml/classifier.rb +9 -6
- data/lib/lutaml/uml/connector.rb +16 -12
- data/lib/lutaml/uml/constraint.rb +8 -7
- data/lib/lutaml/uml/constructor_end.rb +11 -8
- data/lib/lutaml/uml/data_type.rb +9 -4
- data/lib/lutaml/uml/dependency.rb +16 -13
- data/lib/lutaml/uml/document.rb +71 -0
- data/lib/lutaml/uml/enum.rb +33 -0
- data/lib/lutaml/uml/event.rb +7 -5
- data/lib/lutaml/uml/final_state.rb +7 -5
- data/lib/lutaml/uml/formatter.rb +21 -0
- data/lib/lutaml/uml/formatter/base.rb +67 -0
- data/lib/lutaml/uml/formatter/graphviz.rb +335 -0
- data/lib/lutaml/uml/has_attributes.rb +14 -0
- data/lib/lutaml/uml/has_members.rb +30 -0
- data/lib/lutaml/uml/instance.rb +15 -10
- data/lib/lutaml/uml/interface/base.rb +28 -0
- data/lib/lutaml/uml/interface/command_line.rb +265 -0
- data/lib/lutaml/uml/model.rb +11 -8
- data/lib/lutaml/uml/node/base.rb +21 -0
- data/lib/lutaml/uml/node/class_node.rb +57 -0
- data/lib/lutaml/uml/node/class_relationship.rb +14 -0
- data/lib/lutaml/uml/node/document.rb +18 -0
- data/lib/lutaml/uml/node/field.rb +34 -0
- data/lib/lutaml/uml/node/has_name.rb +15 -0
- data/lib/lutaml/uml/node/has_type.rb +15 -0
- data/lib/lutaml/uml/node/method.rb +29 -0
- data/lib/lutaml/uml/node/method_argument.rb +16 -0
- data/lib/lutaml/uml/node/relationship.rb +28 -0
- data/lib/lutaml/uml/opaque_behavior.rb +7 -6
- data/lib/lutaml/uml/package.rb +16 -13
- data/lib/lutaml/uml/parsers/attribute.rb +70 -0
- data/lib/lutaml/uml/parsers/dsl.rb +375 -0
- data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +44 -0
- data/lib/lutaml/uml/parsers/dsl_transform.rb +27 -0
- data/lib/lutaml/uml/parsers/yaml.rb +46 -0
- data/lib/lutaml/uml/port.rb +6 -4
- data/lib/lutaml/uml/primitive_type.rb +9 -4
- data/lib/lutaml/uml/property.rb +25 -15
- data/lib/lutaml/uml/pseudostate.rb +7 -6
- data/lib/lutaml/uml/realization.rb +7 -5
- data/lib/lutaml/uml/region.rb +7 -6
- data/lib/lutaml/uml/serializers/association.rb +58 -0
- data/lib/lutaml/uml/serializers/base.rb +16 -0
- data/lib/lutaml/uml/serializers/class.rb +29 -0
- data/lib/lutaml/uml/serializers/top_element_attribute.rb +14 -0
- data/lib/lutaml/uml/serializers/yaml_view.rb +18 -0
- data/lib/lutaml/uml/state.rb +8 -6
- data/lib/lutaml/uml/state_machine.rb +7 -5
- data/lib/lutaml/uml/top_element.rb +45 -35
- data/lib/lutaml/uml/top_element_attribute.rb +25 -0
- data/lib/lutaml/uml/transition.rb +8 -6
- data/lib/lutaml/uml/trigger.rb +8 -6
- data/lib/lutaml/uml/version.rb +3 -1
- data/lib/lutaml/uml/vertex.rb +7 -5
- data/lutaml-uml.gemspec +9 -2
- data/spec/fixtures/datamodel/models/AddressClassProfile.yml +90 -0
- data/spec/fixtures/datamodel/models/AddressComponentProfile.yml +63 -0
- data/spec/fixtures/datamodel/models/AddressComponentSpecification.yml +15 -0
- data/spec/fixtures/datamodel/models/AddressProfile.yml +36 -0
- data/spec/fixtures/datamodel/models/AttributeProfile.yml +32 -0
- data/spec/fixtures/datamodel/models/InterchangeAddressClassProfile.yml +79 -0
- data/spec/fixtures/datamodel/models/Localization copy.yml +23 -0
- data/spec/fixtures/datamodel/models/Localization.yml +23 -0
- data/spec/fixtures/datamodel/models/ProfileCompliantAddress.yml +36 -0
- data/spec/fixtures/datamodel/models/ProfileCompliantAddressComponent.yml +15 -0
- data/spec/fixtures/datamodel/models/Signature.yml +20 -0
- data/spec/fixtures/datamodel/models/SignatureBlankDefinition.yml +20 -0
- data/spec/fixtures/datamodel/models/TextDirectionCode copy.yml +16 -0
- data/spec/fixtures/datamodel/models/TextDirectionCode.yml +16 -0
- data/spec/fixtures/datamodel/models/Validity.yml +14 -0
- data/spec/fixtures/datamodel/models/iso19160-1/Address.yml +22 -0
- data/spec/fixtures/datamodel/models/iso19160-1/AddressComponent.yml +2 -0
- data/spec/fixtures/datamodel/style.uml.inc +37 -0
- data/spec/fixtures/datamodel/views/AddressClassProfile.yml +12 -0
- data/spec/fixtures/datamodel/views/AddressProfile.yml +3 -0
- data/spec/fixtures/datamodel/views/CommonModels.yml +9 -0
- data/spec/fixtures/datamodel/views/TopDown.yml +62 -0
- data/spec/fixtures/dsl/diagram.lutaml +3 -0
- data/spec/fixtures/dsl/diagram_attributes.lutaml +5 -0
- data/spec/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
- data/spec/fixtures/dsl/diagram_class_fields.lutaml +19 -0
- data/spec/fixtures/dsl/diagram_comments.lutaml +28 -0
- data/spec/fixtures/dsl/diagram_concept_model.lutaml +132 -0
- data/spec/fixtures/dsl/diagram_data_types.lutaml +24 -0
- data/spec/fixtures/dsl/diagram_includes.lutaml +6 -0
- data/spec/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
- data/spec/fixtures/dsl/shared.lutaml +3 -0
- data/spec/fixtures/dsl/shared1.lutaml +4 -0
- data/spec/fixtures/generated_dot/AddressClassProfile.dot +170 -0
- data/spec/fixtures/generated_dot/AddressProfile.dot +34 -0
- data/spec/lutaml/uml/formatter/graphviz_spec.rb +41 -0
- data/spec/lutaml/uml/parsers/dsl_spec.rb +252 -0
- data/spec/lutaml/uml/parsers/yaml_spec.rb +18 -0
- data/spec/lutaml/uml/serializers/yaml_view_spec.rb +20 -0
- data/spec/lutaml/uml_spec.rb +2 -4
- data/spec/spec_helper.rb +11 -0
- metadata +161 -13
@@ -1,8 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Classifier < TopElement
|
4
|
-
attr_accessor :generalization
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
3
|
+
require "lutaml/uml/top_element"
|
7
4
|
|
8
|
-
|
5
|
+
module Lutaml
|
6
|
+
module Uml
|
7
|
+
class Classifier < TopElement
|
8
|
+
attr_accessor :generalization
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/lutaml/uml/connector.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
## Behaviour metamodel
|
3
5
|
##
|
4
|
-
module Lutaml
|
5
|
-
|
6
|
-
class Connector
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@name = nil
|
10
|
-
@xmi_id = nil
|
11
|
-
@xmi_uuid = nil
|
12
|
-
@connector_end = []
|
13
|
-
@namespace = nil
|
14
|
-
@kind = nil
|
15
|
-
end
|
6
|
+
module Lutaml
|
7
|
+
module Uml
|
8
|
+
class Connector < TopElement
|
9
|
+
attr_accessor :kind, :connector_end
|
16
10
|
|
11
|
+
def initialize
|
12
|
+
@name = nil
|
13
|
+
@xmi_id = nil
|
14
|
+
@xmi_uuid = nil
|
15
|
+
@connector_end = []
|
16
|
+
@namespace = nil
|
17
|
+
@kind = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
17
21
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
## Behaviour metamodel
|
3
5
|
##
|
4
|
-
module Lutaml
|
5
|
-
|
6
|
-
class Constraint < TopElement
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
|
6
|
+
module Lutaml
|
7
|
+
module Uml
|
8
|
+
class Constraint < TopElement
|
9
|
+
attr_accessor :body
|
10
|
+
end
|
11
|
+
end
|
11
12
|
end
|
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
## Behaviour metamodel
|
3
5
|
##
|
4
|
-
module Lutaml
|
6
|
+
module Lutaml
|
7
|
+
module Uml
|
8
|
+
class ConnectorEnd < TopElement
|
9
|
+
attr_accessor :role, :part_with_port, :connector
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def initialize
|
12
|
+
@role = nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
11
16
|
end
|
12
|
-
|
13
|
-
end
|
data/lib/lutaml/uml/data_type.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
## Behaviour metamodel
|
3
5
|
##
|
4
|
-
module Lutaml
|
5
|
-
|
6
|
-
class Dependency < TopElement
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@name = nil
|
10
|
-
@xmi_id = nil
|
11
|
-
@xmi_uuid = nil
|
12
|
-
@client = []
|
13
|
-
@supplier = []
|
14
|
-
@namespace = nil
|
15
|
-
end
|
16
|
-
end
|
6
|
+
module Lutaml
|
7
|
+
module Uml
|
8
|
+
class Dependency < TopElement
|
9
|
+
attr_accessor :client, :supplier
|
17
10
|
|
11
|
+
def initialize
|
12
|
+
@name = nil
|
13
|
+
@xmi_id = nil
|
14
|
+
@xmi_uuid = nil
|
15
|
+
@client = []
|
16
|
+
@supplier = []
|
17
|
+
@namespace = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
18
21
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/uml/class"
|
4
|
+
require "lutaml/uml/enum"
|
5
|
+
require "lutaml/uml/data_type"
|
6
|
+
require "lutaml/uml/primitive_type"
|
7
|
+
|
8
|
+
module Lutaml
|
9
|
+
module Uml
|
10
|
+
class Document
|
11
|
+
include HasAttributes
|
12
|
+
include HasMembers
|
13
|
+
|
14
|
+
attr_accessor :name,
|
15
|
+
:title,
|
16
|
+
:caption,
|
17
|
+
:groups,
|
18
|
+
:fidelity,
|
19
|
+
:fontname,
|
20
|
+
:comments
|
21
|
+
|
22
|
+
# rubocop:disable Rails/ActiveRecordAliases
|
23
|
+
def initialize(attributes = {})
|
24
|
+
update_attributes(attributes)
|
25
|
+
end
|
26
|
+
# rubocop:enable Rails/ActiveRecordAliases
|
27
|
+
|
28
|
+
def classes=(value)
|
29
|
+
@classes = value.to_a.map { |attributes| Class.new(attributes) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def enums=(value)
|
33
|
+
@enums = value.to_a.map { |attributes| Enum.new(attributes) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def data_types=(value)
|
37
|
+
@data_types = value.to_a.map { |attributes| DataType.new(attributes) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def primitives=(value)
|
41
|
+
@primitives = value.to_a.map { |attributes| PrimitiveType.new(attributes) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def associations=(value)
|
45
|
+
@associations = value.to_a.map do |attributes|
|
46
|
+
Association.new(attributes)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def classes
|
51
|
+
@classes || []
|
52
|
+
end
|
53
|
+
|
54
|
+
def enums
|
55
|
+
@enums || []
|
56
|
+
end
|
57
|
+
|
58
|
+
def data_types
|
59
|
+
@data_types || []
|
60
|
+
end
|
61
|
+
|
62
|
+
def primitives
|
63
|
+
@primitives || []
|
64
|
+
end
|
65
|
+
|
66
|
+
def associations
|
67
|
+
@associations || []
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/uml/has_members"
|
4
|
+
require "lutaml/uml/classifier"
|
5
|
+
require "lutaml/uml/association"
|
6
|
+
require "lutaml/uml/top_element_attribute"
|
7
|
+
|
8
|
+
module Lutaml
|
9
|
+
module Uml
|
10
|
+
class Enum < Classifier
|
11
|
+
include HasMembers
|
12
|
+
|
13
|
+
attr_reader :attributes,
|
14
|
+
:members,
|
15
|
+
:modifier
|
16
|
+
|
17
|
+
def attributes=(value)
|
18
|
+
@attributes = value.to_a.map do |attr|
|
19
|
+
TopElementAttribute.new(attr)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: reserved name, change
|
24
|
+
def methods
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
def keyword
|
29
|
+
"enumeration"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/lutaml/uml/event.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lutaml
|
4
|
+
module Uml
|
5
|
+
module Formatter
|
6
|
+
class << self
|
7
|
+
def all
|
8
|
+
@all ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_by_name(name)
|
12
|
+
name = name.to_sym
|
13
|
+
|
14
|
+
all.detect { |formatter_class| formatter_class.name == name }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require "lutaml/uml/formatter/graphviz"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/uml/formatter"
|
4
|
+
require "lutaml/uml/has_attributes"
|
5
|
+
|
6
|
+
module Lutaml
|
7
|
+
module Uml
|
8
|
+
module Formatter
|
9
|
+
class Base
|
10
|
+
class << self
|
11
|
+
def inherited(subclass)
|
12
|
+
Formatter.all << subclass
|
13
|
+
end
|
14
|
+
|
15
|
+
def format(node, attributes = {})
|
16
|
+
new(attributes).format(node)
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
to_s.split("::").last.downcase.to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
include HasAttributes
|
25
|
+
|
26
|
+
# rubocop:disable Rails/ActiveRecordAliases
|
27
|
+
def initialize(attributes = {})
|
28
|
+
update_attributes(attributes)
|
29
|
+
end
|
30
|
+
# rubocop:enable Rails/ActiveRecordAliases
|
31
|
+
|
32
|
+
def name
|
33
|
+
self.class.name
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :type
|
37
|
+
|
38
|
+
def type=(value)
|
39
|
+
@type = value.to_s.strip.downcase.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
def format(node)
|
43
|
+
case node
|
44
|
+
when Node::Field then format_field(node)
|
45
|
+
when Node::Method then format_method(node)
|
46
|
+
when Node::Relationship then format_relationship(node)
|
47
|
+
when Node::ClassRelationship then format_class_relationship(node)
|
48
|
+
when Node::ClassNode then format_class(node)
|
49
|
+
when Lutaml::Uml::Document then format_document(node)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_field(_node); raise NotImplementedError; end
|
54
|
+
|
55
|
+
def format_method(_node); raise NotImplementedError; end
|
56
|
+
|
57
|
+
def format_relationship(_node); raise NotImplementedError; end
|
58
|
+
|
59
|
+
def format_class_relationship(_node); raise NotImplementedError; end
|
60
|
+
|
61
|
+
def format_class(_node); raise NotImplementedError; end
|
62
|
+
|
63
|
+
def format_document(_node); raise NotImplementedError; end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,335 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "lutaml/uml/formatter/base"
|
5
|
+
require "lutaml/layout/graph_viz_engine"
|
6
|
+
|
7
|
+
module Lutaml
|
8
|
+
module Uml
|
9
|
+
module Formatter
|
10
|
+
class Graphviz < Base
|
11
|
+
class Attributes < Hash
|
12
|
+
def to_s
|
13
|
+
to_a
|
14
|
+
.reject { |(_k, val)| val.nil? }
|
15
|
+
.map { |(a, b)| "#{a}=#{b.inspect}" }
|
16
|
+
.join(" ")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ACCESS_SYMBOLS = {
|
21
|
+
"public" => "+",
|
22
|
+
"protected" => "#",
|
23
|
+
"private" => "-",
|
24
|
+
}.freeze
|
25
|
+
DEFAULT_CLASS_FONT = "Helvetica".freeze
|
26
|
+
|
27
|
+
VALID_TYPES = %i[
|
28
|
+
dot
|
29
|
+
xdot
|
30
|
+
ps
|
31
|
+
pdf
|
32
|
+
svg
|
33
|
+
svgz
|
34
|
+
fig
|
35
|
+
png
|
36
|
+
gif
|
37
|
+
jpg
|
38
|
+
jpeg
|
39
|
+
json
|
40
|
+
imap
|
41
|
+
cmapx
|
42
|
+
].freeze
|
43
|
+
|
44
|
+
def initialize(attributes = {})
|
45
|
+
super
|
46
|
+
|
47
|
+
@graph = Attributes.new
|
48
|
+
# Associations lines style, `true` gives curved lines
|
49
|
+
# https://graphviz.org/doc/info/attrs.html#d:splines
|
50
|
+
@graph["splines"] = "ortho"
|
51
|
+
# Padding between outside of picture and nodes
|
52
|
+
@graph["pad"] = 0.5
|
53
|
+
# Padding between levels
|
54
|
+
@graph["ranksep"] = "1.2.equally"
|
55
|
+
# Padding between nodes
|
56
|
+
@graph["nodesep"] = "1.2.equally"
|
57
|
+
# TODO: set rankdir
|
58
|
+
# @graph['rankdir'] = 'BT'
|
59
|
+
|
60
|
+
@edge = Attributes.new
|
61
|
+
@edge["color"] = "gray50"
|
62
|
+
|
63
|
+
@node = Attributes.new
|
64
|
+
@node["shape"] = "box"
|
65
|
+
|
66
|
+
@type = :dot
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :graph
|
70
|
+
attr_reader :edge
|
71
|
+
attr_reader :node
|
72
|
+
|
73
|
+
def type=(value)
|
74
|
+
super
|
75
|
+
|
76
|
+
@type = :dot unless VALID_TYPES.include?(@type)
|
77
|
+
end
|
78
|
+
|
79
|
+
def format(node)
|
80
|
+
dot = super.lines.map(&:rstrip).join("\n")
|
81
|
+
|
82
|
+
generate_from_dot(dot)
|
83
|
+
end
|
84
|
+
|
85
|
+
def escape_html_chars(text)
|
86
|
+
text
|
87
|
+
.gsub(/</, "<")
|
88
|
+
.gsub(/>/, ">")
|
89
|
+
.gsub(/\[/, "[")
|
90
|
+
.gsub(/\]/, "]")
|
91
|
+
end
|
92
|
+
|
93
|
+
def format_field(node)
|
94
|
+
symbol = ACCESS_SYMBOLS[node.visibility]
|
95
|
+
result = "#{symbol}#{node.name}"
|
96
|
+
if node.type
|
97
|
+
keyword = node.keyword ? "«#{node.keyword}»" : ""
|
98
|
+
result += " : #{keyword}#{node.type}"
|
99
|
+
end
|
100
|
+
if node.cardinality
|
101
|
+
result += "[#{node.cardinality[:min]}..#{node.cardinality[:max]}]"
|
102
|
+
end
|
103
|
+
result = escape_html_chars(result)
|
104
|
+
result = "<U>#{result}</U>" if node.static
|
105
|
+
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def format_method(node)
|
110
|
+
symbol = ACCESS_SYMBOLS[node.access]
|
111
|
+
result = "#{symbol} #{node.name}"
|
112
|
+
if node.arguments
|
113
|
+
arguments = node.arguments.map do |argument|
|
114
|
+
"#{argument.name}#{" : #{argument.type}" if argument.type}"
|
115
|
+
end.join(", ")
|
116
|
+
end
|
117
|
+
|
118
|
+
result << "(#{arguments})"
|
119
|
+
result << " : #{node.type}" if node.type
|
120
|
+
result = "<U>#{result}</U>" if node.static
|
121
|
+
result = "<I>#{result}</I>" if node.abstract
|
122
|
+
|
123
|
+
result
|
124
|
+
end
|
125
|
+
|
126
|
+
def format_relationship(node)
|
127
|
+
graph_parent_name = generate_graph_name(node.owner_end)
|
128
|
+
graph_node_name = generate_graph_name(node.member_end)
|
129
|
+
attributes = generate_graph_relationship_attributes(node)
|
130
|
+
graph_attributes = " [#{attributes}]" unless attributes.empty?
|
131
|
+
|
132
|
+
%{#{graph_parent_name} -> #{graph_node_name}#{graph_attributes}}
|
133
|
+
end
|
134
|
+
|
135
|
+
def generate_graph_relationship_attributes(node)
|
136
|
+
attributes = Attributes.new
|
137
|
+
if %w[dependency realizes].include?(node.member_end_type)
|
138
|
+
attributes["style"] = "dashed"
|
139
|
+
end
|
140
|
+
attributes["dir"] = if node.owner_end_type && node.member_end_type
|
141
|
+
"both"
|
142
|
+
elsif node.owner_end_type
|
143
|
+
"back"
|
144
|
+
else
|
145
|
+
"direct"
|
146
|
+
end
|
147
|
+
attributes["label"] = node.action if node.action
|
148
|
+
if node.owner_end_attribute_name
|
149
|
+
attributes["headlabel"] = format_label(
|
150
|
+
node.owner_end_attribute_name,
|
151
|
+
node.owner_end_cardinality
|
152
|
+
)
|
153
|
+
end
|
154
|
+
if node.member_end_attribute_name
|
155
|
+
attributes["taillabel"] = format_label(
|
156
|
+
node.member_end_attribute_name,
|
157
|
+
node.member_end_cardinality
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
attributes["arrowtail"] = case node.owner_end_type
|
162
|
+
when "composition"
|
163
|
+
"diamond"
|
164
|
+
when "aggregation"
|
165
|
+
"odiamond"
|
166
|
+
when "direct"
|
167
|
+
"vee"
|
168
|
+
else
|
169
|
+
"onormal"
|
170
|
+
end
|
171
|
+
|
172
|
+
attributes["arrowhead"] = case node.member_end_type
|
173
|
+
when "composition"
|
174
|
+
"diamond"
|
175
|
+
when "aggregation"
|
176
|
+
"odiamond"
|
177
|
+
when "direct"
|
178
|
+
"vee"
|
179
|
+
else
|
180
|
+
"onormal"
|
181
|
+
end
|
182
|
+
# swap labels and arrows if `dir` eq to `back`
|
183
|
+
if attributes["dir"] == "back"
|
184
|
+
attributes["arrowhead"], attributes["arrowtail"] = [attributes["arrowtail"], attributes["arrowhead"]]
|
185
|
+
attributes["headlabel"], attributes["taillabel"] = [attributes["taillabel"], attributes["headlabel"]]
|
186
|
+
end
|
187
|
+
attributes
|
188
|
+
end
|
189
|
+
|
190
|
+
def format_label(name, cardinality = {})
|
191
|
+
res = "+#{name}"
|
192
|
+
if cardinality.nil? ||
|
193
|
+
(cardinality["min"].nil? || cardinality["max"].nil?)
|
194
|
+
return res
|
195
|
+
end
|
196
|
+
|
197
|
+
"#{res} #{cardinality['min']}..#{cardinality['max']}"
|
198
|
+
end
|
199
|
+
|
200
|
+
def format_member_rows(members, hide_members)
|
201
|
+
unless !hide_members && members && members.length.positive?
|
202
|
+
return <<~HEREDOC.chomp
|
203
|
+
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
|
204
|
+
<TR><TD ALIGN="LEFT"></TD></TR>
|
205
|
+
</TABLE>
|
206
|
+
HEREDOC
|
207
|
+
end
|
208
|
+
|
209
|
+
field_rows = members.map do |field|
|
210
|
+
%{<TR><TD ALIGN="LEFT">#{format_field(field)}</TD></TR>}
|
211
|
+
end
|
212
|
+
field_table = <<~HEREDOC.chomp
|
213
|
+
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
|
214
|
+
#{field_rows.map { |row| ' ' * 10 + row }.join("\n")}
|
215
|
+
</TABLE>
|
216
|
+
HEREDOC
|
217
|
+
field_table << "\n" << " " * 6
|
218
|
+
field_table
|
219
|
+
end
|
220
|
+
|
221
|
+
def format_class(node, hide_members)
|
222
|
+
name = ["<B>#{node.name}</B>"]
|
223
|
+
name.unshift("«#{node.keyword}»") if node.keyword
|
224
|
+
name_html = <<~HEREDOC
|
225
|
+
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
|
226
|
+
#{name.map { |n| %(<TR><TD ALIGN="CENTER">#{n}</TD></TR>) }.join('\n')}
|
227
|
+
</TABLE>
|
228
|
+
HEREDOC
|
229
|
+
# name = "«abstract»<BR/><I>#{name}</I>" if node.modifier == "abstract"
|
230
|
+
# name = "«interface»<BR/>#{name}" if node.modifier == "interface"
|
231
|
+
|
232
|
+
field_table = format_member_rows(node.attributes, hide_members)
|
233
|
+
method_table = format_member_rows(node.methods, hide_members)
|
234
|
+
table_body = [name_html, field_table, method_table].map do |type|
|
235
|
+
next if type.nil?
|
236
|
+
|
237
|
+
<<~TEXT
|
238
|
+
<TR>
|
239
|
+
<TD>#{type}</TD>
|
240
|
+
</TR>
|
241
|
+
TEXT
|
242
|
+
end
|
243
|
+
|
244
|
+
<<~HEREDOC.chomp
|
245
|
+
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="10">
|
246
|
+
#{table_body.compact.join("\n")}
|
247
|
+
</TABLE>
|
248
|
+
HEREDOC
|
249
|
+
end
|
250
|
+
|
251
|
+
def format_document(node)
|
252
|
+
@fontname = node.fontname || DEFAULT_CLASS_FONT
|
253
|
+
@node["fontname"] = "#{@fontname}-bold"
|
254
|
+
|
255
|
+
if node.fidelity
|
256
|
+
hide_members = node.fidelity["hideMembers"]
|
257
|
+
hide_other_classes = node.fidelity["hideOtherClasses"]
|
258
|
+
end
|
259
|
+
classes = (node.classes + node.enums).map do |class_node|
|
260
|
+
graph_node_name = generate_graph_name(class_node.name)
|
261
|
+
|
262
|
+
<<~HEREDOC
|
263
|
+
#{graph_node_name} [
|
264
|
+
shape="plain"
|
265
|
+
fontname="#{@fontname || DEFAULT_CLASS_FONT}"
|
266
|
+
label=<#{format_class(class_node, hide_members)}>]
|
267
|
+
HEREDOC
|
268
|
+
end.join("\n")
|
269
|
+
associations = node.classes.map(&:associations).compact.flatten +
|
270
|
+
node.associations
|
271
|
+
if node.groups
|
272
|
+
associations = sort_by_document_groupping(node.groups, associations)
|
273
|
+
end
|
274
|
+
classes_names = node.classes.map(&:name)
|
275
|
+
associations = associations.map do |assoc_node|
|
276
|
+
if hide_other_classes &&
|
277
|
+
!classes_names.include?(assoc_node.member_end)
|
278
|
+
next
|
279
|
+
end
|
280
|
+
|
281
|
+
format_relationship(assoc_node)
|
282
|
+
end.join("\n")
|
283
|
+
|
284
|
+
classes = classes.lines.map { |line| " #{line}" }.join.chomp
|
285
|
+
associations = associations
|
286
|
+
.lines.map { |line| " #{line}" }.join.chomp
|
287
|
+
|
288
|
+
<<~HEREDOC
|
289
|
+
digraph G {
|
290
|
+
graph [#{@graph}]
|
291
|
+
edge [#{@edge}]
|
292
|
+
node [#{@node}]
|
293
|
+
|
294
|
+
#{classes}
|
295
|
+
|
296
|
+
#{associations}
|
297
|
+
}
|
298
|
+
HEREDOC
|
299
|
+
end
|
300
|
+
|
301
|
+
protected
|
302
|
+
|
303
|
+
def sort_by_document_groupping(groups, associations)
|
304
|
+
result = []
|
305
|
+
groups.each do |batch|
|
306
|
+
batch.each do |group_name|
|
307
|
+
associations
|
308
|
+
.select { |assc| assc.owner_end == group_name }
|
309
|
+
.each do |association|
|
310
|
+
result.push(association) unless result.include?(association)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
associations.each do |association|
|
315
|
+
result.push(association) unless result.include?(association)
|
316
|
+
end
|
317
|
+
result
|
318
|
+
end
|
319
|
+
|
320
|
+
def generate_from_dot(input)
|
321
|
+
# https://github.com/glejeune/Ruby-Graphviz/issues/78
|
322
|
+
# Ruby-Graphviz has an old bug when html labels was not displayed
|
323
|
+
# property because of `<` and `>` characters escape, add additional
|
324
|
+
# `<` and `>` symbols to workaround it
|
325
|
+
escaped_dot = input.gsub("<<", "<<<").gsub(">>", ">>>")
|
326
|
+
Lutaml::Layout::GraphVizEngine.new(input: escaped_dot).render(@type)
|
327
|
+
end
|
328
|
+
|
329
|
+
def generate_graph_name(name)
|
330
|
+
name.gsub(/[^0-9a-zA-Z]/i, "")
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|