lutaml-uml 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9390b74fbba2e8c8ee424d8aecd2efd9d507d157e6a63cc64c115b821878ef01
4
- data.tar.gz: e8d2466349d6b622ae0a3d46b1eeca87f0f3996d155fbf5bed75e90bc14a3b48
3
+ metadata.gz: 988b726887b8bd5f85e4cff7f56bfac405c6ea287f80d0a2222adf994ced4f70
4
+ data.tar.gz: 2d2aa85fcc8c25fc64ecd2a4cecbe028e54eeebe79f78e6615298ef095de667e
5
5
  SHA512:
6
- metadata.gz: 2d4a974174f13d690205e9d5f887745ec1268e16c8d031a137ca492fca24617a004d4ede0e72ed074b02694895d81b4128f7695811436e4d4a746676bacbb834
7
- data.tar.gz: 8dbe1883d2ea7c910e48b4c0f9191559aaa7a6ee02c598b5a0b05a7fb3cd33407edc37101a9fec4297f9110be3fb9243625370b140c5a0fc36adc9d909a6b4ae
6
+ metadata.gz: 6d068ec140b4a284c0a1f0f7762c86b03bdaa1ad667c96a614f1009007e9fb064a8b5df787bf0d06185169ca0b0b8afebda70d82ae62bfd52fcb01c4f79f012f
7
+ data.tar.gz: bdebc9b1068f9f98eb2fc2da7b03d3d389231440064964e518169e1acd4c73d1f5e509ed53aad92d734afa58bddd0882cbc63802d6280068d400784e773105f3
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
- Gemfile.lock
12
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ script_full_path=$(dirname "$0")
2
+
3
+ for i in $1/*.yml
4
+ do
5
+ $script_full_path/yaml2lutaml $i > "$1/$(basename -s .yml $i).lutaml"
6
+ done
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Script to convert plantuml files into LutaML syntax
6
+ # Usage: bin/plantuml2lutaml /path/to/plantuml.wsd
7
+
8
+ file_path = ARGV[0]
9
+ FILE_NAME = File.basename(file_path, '.wsd')
10
+ wsd_file = File.new(ARGV[0])
11
+
12
+ def sync_puts(line, level = 0)
13
+ $stdout.puts("#{''.rjust(level)}#{line}")
14
+ $stdout.flush
15
+ end
16
+
17
+ SKIPPED_LINES_REGEXP = /^(@startuml|'\*{7}|note|@enduml|\!|'\/)/
18
+ COMMENT_START = /\/'/
19
+ COMMENT_END = /'\//
20
+ ASSOCIATION_MAPPINGS = {
21
+ /-\|>/ => ',inheritance',
22
+ /<\|-/ => 'inheritance,',
23
+ /->/ => ',direct',
24
+ /<-/ => 'direct,'
25
+ }
26
+
27
+ in_comment_block = false
28
+
29
+ def transform_line(line)
30
+ return sync_puts(line, 2) if ASSOCIATION_MAPPINGS.keys.none? { |key| line =~ key }
31
+
32
+ owner_type, member_type = ASSOCIATION_MAPPINGS.find { |(key,value)| line =~ key }.last.split(',')
33
+ blocks = line.split(' ')
34
+ owner = blocks.first
35
+ member = blocks.last
36
+ sync_puts("association {", 2)
37
+ sync_puts("owner #{owner}", 4)
38
+ sync_puts("member #{member}", 4)
39
+ sync_puts("owner_type #{owner_type}", 4) if owner_type.to_s.length > 0
40
+ sync_puts("member_type #{member_type}", 4) if member_type.to_s.length > 0
41
+ sync_puts("}", 2)
42
+ end
43
+
44
+ sync_puts("diagram #{FILE_NAME} {")
45
+ wsd_file.readlines.each do |line|
46
+ if line =~ COMMENT_START
47
+ in_comment_block = true
48
+ end
49
+
50
+ if line =~ COMMENT_END
51
+ in_comment_block = false
52
+ end
53
+
54
+ next if in_comment_block || line =~ SKIPPED_LINES_REGEXP
55
+
56
+ transform_line(line)
57
+ end
58
+ sync_puts("}")
@@ -45,7 +45,7 @@ def process_association(owner, values, encountered_relations)
45
45
  if source["attribute"]
46
46
  source_attribute_name = source["attribute"].keys.first
47
47
  owner += "##{source_attribute_name}"
48
- if source["attribute"][source_attribute_name]["cardinality"]
48
+ if source["attribute"][source_attribute_name] && source["attribute"][source_attribute_name]["cardinality"]
49
49
  cardinality = source["attribute"][source_attribute_name]["cardinality"]
50
50
  owner += " [#{cardinality['min']}..#{cardinality['max']}]"
51
51
  end
@@ -61,7 +61,7 @@ def process_association(owner, values, encountered_relations)
61
61
  if target["attribute"]
62
62
  target_attribute_name = target["attribute"].keys.first
63
63
  member += "##{target_attribute_name}"
64
- if target["attribute"][target_attribute_name]["cardinality"]
64
+ if target["attribute"][target_attribute_name] && target["attribute"][target_attribute_name]["cardinality"]
65
65
  cardinality = target["attribute"][target_attribute_name]["cardinality"]
66
66
  member += " [#{cardinality['min']}..#{cardinality['max']}]"
67
67
  end
@@ -83,9 +83,9 @@ end
83
83
 
84
84
  view_yaml["imports"].keys.each do |entry|
85
85
  import = YAML.safe_load(File.read(File.join(models_path, "#{entry}.yml")))
86
- import_name = import["name"]
86
+ import_name = import["name"] || File.basename(entry)
87
87
  # Class notation
88
- sync_puts("#{import['modelType']} #{import['name']} {", 2)
88
+ sync_puts("#{import['modelType']} #{import_name} {", 2)
89
89
  import["values"]&.each_pair do |key, values|
90
90
  sync_puts("#{key}", 4)
91
91
  end
@@ -7,10 +7,22 @@ module Lutaml
7
7
  module Layout
8
8
  class GraphVizEngine < Engine
9
9
  def render(type)
10
- GraphViz
11
- .parse_string(input)
10
+ parse_graphviz_string
12
11
  .output(type => String)
13
12
  end
13
+
14
+ private
15
+
16
+ # GraphViz#parse_string and GraphViz#parse crush with no reason
17
+ # with seg fault, this lead to nil return value.
18
+ # Try to recall method several time
19
+ def parse_graphviz_string(attempts = 10)
20
+ raise('Cannot parse input string, `gvpr` segmentation fault?') if attempts == 0
21
+ res = GraphViz.parse_string(input)
22
+ return res if res
23
+
24
+ parse_graphviz_string(attempts - 1)
25
+ end
14
26
  end
15
27
  end
16
28
  end
@@ -181,8 +181,10 @@ module Lutaml
181
181
  end
182
182
  # swap labels and arrows if `dir` eq to `back`
183
183
  if attributes["dir"] == "back"
184
- attributes["arrowhead"], attributes["arrowtail"] = [attributes["arrowtail"], attributes["arrowhead"]]
185
- attributes["headlabel"], attributes["taillabel"] = [attributes["taillabel"], attributes["headlabel"]]
184
+ attributes["arrowhead"], attributes["arrowtail"] =
185
+ [attributes["arrowtail"], attributes["arrowhead"]]
186
+ attributes["headlabel"], attributes["taillabel"] =
187
+ [attributes["taillabel"], attributes["headlabel"]]
186
188
  end
187
189
  attributes
188
190
  end
@@ -226,8 +228,6 @@ module Lutaml
226
228
  #{name.map { |n| %(<TR><TD ALIGN="CENTER">#{n}</TD></TR>) }.join('\n')}
227
229
  </TABLE>
228
230
  HEREDOC
229
- # name = "«abstract»<BR/><I>#{name}</I>" if node.modifier == "abstract"
230
- # name = "«interface»<BR/>#{name}" if node.modifier == "interface"
231
231
 
232
232
  field_table = format_member_rows(node.attributes, hide_members)
233
233
  method_table = format_member_rows(node.methods, hide_members)
@@ -256,7 +256,10 @@ module Lutaml
256
256
  hide_members = node.fidelity["hideMembers"]
257
257
  hide_other_classes = node.fidelity["hideOtherClasses"]
258
258
  end
259
- classes = (node.classes + node.enums).map do |class_node|
259
+ classes = (node.classes +
260
+ node.enums +
261
+ node.data_types +
262
+ node.primitives).map do |class_node|
260
263
  graph_node_name = generate_graph_name(class_node.name)
261
264
 
262
265
  <<~HEREDOC
@@ -269,7 +272,8 @@ module Lutaml
269
272
  associations = node.classes.map(&:associations).compact.flatten +
270
273
  node.associations
271
274
  if node.groups
272
- associations = sort_by_document_groupping(node.groups, associations)
275
+ associations = sort_by_document_groupping(node.groups,
276
+ associations)
273
277
  end
274
278
  classes_names = node.classes.map(&:name)
275
279
  associations = associations.map do |assoc_node|
@@ -61,7 +61,9 @@ module Lutaml
61
61
 
62
62
  rule(:spaces) { match("\s").repeat(1) }
63
63
  rule(:spaces?) { spaces.maybe }
64
- rule(:whitespace) { (match("\s") | match("\n") | str(";")).repeat(1) }
64
+ rule(:whitespace) do
65
+ (match("\s") | match("\r?\n") | match("\r") | str(";")).repeat(1)
66
+ end
65
67
  rule(:whitespace?) { whitespace.maybe }
66
68
  rule(:name) { match["a-zA-Z0-9 _-"].repeat(1) }
67
69
  rule(:newline) { str("\n") >> str("\r").maybe }
@@ -104,7 +106,7 @@ module Lutaml
104
106
  rule(:method_abstract) { (kw_abstract.as(:abstract) >> spaces).maybe }
105
107
  rule(:attribute_keyword) do
106
108
  str("<<") >>
107
- match['a-zA-Z0-9_\-'].repeat(1).as(:keyword) >>
109
+ match['a-zA-Z0-9_\-\/'].repeat(1).as(:keyword) >>
108
110
  str(">>")
109
111
  end
110
112
  rule(:attribute_keyword?) { attribute_keyword.maybe }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Uml
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
@@ -29,10 +29,10 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency "parslet", "~> 1.7.1"
30
30
  spec.add_runtime_dependency "ruby-graphviz", "~> 1.2"
31
31
  spec.add_runtime_dependency "thor", "~> 1.0"
32
+
32
33
  spec.add_development_dependency "byebug"
33
34
  spec.add_development_dependency "nokogiri", "~> 1.10"
34
35
  spec.add_development_dependency "rubocop", "~> 0.54.0"
35
-
36
36
  spec.add_development_dependency "bundler", "~> 2.0"
37
37
  spec.add_development_dependency "pry", "~> 0.12.2"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-uml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-12 00:00:00.000000000 Z
11
+ date: 2020-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -194,12 +194,12 @@ files:
194
194
  - ".travis.yml"
195
195
  - CODE_OF_CONDUCT.md
196
196
  - Gemfile
197
- - Gemfile.lock
198
197
  - LUTAML.adoc
199
198
  - README.adoc
200
199
  - Rakefile
201
200
  - bin/console
202
- - bin/lutaml2dotpng
201
+ - bin/folder_yaml2lutaml.sh
202
+ - bin/plantuml2lutaml
203
203
  - bin/setup
204
204
  - bin/yaml2lutaml
205
205
  - exe/lutaml-uml
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # Script to convert lutaml files into dot and png files
6
- # Usage: bin/lutaml2dotpng /path/to/lutaml/folder/
7
- require "bundler/setup"
8
- require "lutaml/uml"
9
-
10
- basedir = ARGV[0]
11
- Dir["#{basedir}/*.lutaml"].each do |filename|
12
- puts(filename)
13
- base_filename = File.basename(filename, '.lutaml')
14
- File.open("#{basedir}/#{base_filename}.dot", 'w') do |file|
15
- file
16
- .puts(Lutaml::Uml::Formatter::Graphviz
17
- .new
18
- .format_document(
19
- Lutaml::Uml::Parsers::Dsl
20
- .parse(File.read("#{basedir}/#{base_filename}.lutaml"))))
21
- end
22
- `dot -T png #{"#{basedir}/#{base_filename}.dot"} > "#{basedir}/#{base_filename}.png"`
23
- end