metanorma-standoc 1.9.0 → 1.10.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/rake.yml +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -8
- data/lib/asciidoctor/standoc/base.rb +31 -35
- data/lib/asciidoctor/standoc/biblio.rng +1 -0
- data/lib/asciidoctor/standoc/blocks.rb +25 -9
- data/lib/asciidoctor/standoc/blocks_notes.rb +41 -24
- data/lib/asciidoctor/standoc/cleanup.rb +59 -84
- data/lib/asciidoctor/standoc/cleanup_block.rb +63 -85
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -15
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
- data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
- data/lib/asciidoctor/standoc/cleanup_ref.rb +31 -15
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +77 -135
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
- data/lib/asciidoctor/standoc/converter.rb +7 -2
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
- data/lib/asciidoctor/standoc/front.rb +35 -18
- data/lib/asciidoctor/standoc/front_contributor.rb +70 -45
- data/lib/asciidoctor/standoc/inline.rb +45 -34
- data/lib/asciidoctor/standoc/isodoc.rng +209 -4
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +11 -11
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- data/lib/asciidoctor/standoc/macros_plantuml.rb +19 -21
- data/lib/asciidoctor/standoc/macros_terms.rb +33 -23
- data/lib/asciidoctor/standoc/ref.rb +87 -112
- data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
- data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
- data/lib/asciidoctor/standoc/section.rb +3 -1
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +40 -27
- data/lib/asciidoctor/standoc/terms.rb +25 -18
- data/lib/asciidoctor/standoc/utils.rb +35 -9
- data/lib/asciidoctor/standoc/validate.rb +48 -33
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/asciidoctor/base_spec.rb +701 -508
- data/spec/asciidoctor/blocks_spec.rb +831 -738
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +889 -682
- data/spec/asciidoctor/inline_spec.rb +62 -14
- data/spec/asciidoctor/isobib_cache_spec.rb +404 -358
- data/spec/asciidoctor/lists_spec.rb +149 -137
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +923 -503
- data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +1528 -1533
- data/spec/asciidoctor/section_spec.rb +405 -299
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +342 -304
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -54
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +16 -15
- data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
- data/lib/liquid/custom_filters/values.rb +0 -7
@@ -0,0 +1,75 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def get_or_make_title(node)
|
5
|
+
unless node.at("./title")
|
6
|
+
if node.children.empty?
|
7
|
+
node << "<title/>"
|
8
|
+
else
|
9
|
+
node.children.first.previous = "<title/>"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
node.at("./title")
|
13
|
+
end
|
14
|
+
|
15
|
+
def replace_title(doc, xpath, text, first = false)
|
16
|
+
return unless text
|
17
|
+
|
18
|
+
doc.xpath(xpath).each_with_index do |node, i|
|
19
|
+
next if first && !i.zero?
|
20
|
+
|
21
|
+
title = get_or_make_title(node)
|
22
|
+
fn = title.xpath("./fn")
|
23
|
+
fn.each(&:remove)
|
24
|
+
title.content = text
|
25
|
+
fn.each { |n| title << n }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sections_names_cleanup(xml)
|
30
|
+
replace_title(xml, "//clause[@type = 'scope']", @i18n&.scope)
|
31
|
+
replace_title(xml, "//preface//abstract", @i18n&.abstract)
|
32
|
+
replace_title(xml, "//foreword", @i18n&.foreword)
|
33
|
+
replace_title(xml, "//introduction", @i18n&.introduction)
|
34
|
+
replace_title(xml, "//acknowledgements", @i18n&.acknowledgements)
|
35
|
+
section_names_refs_cleanup(xml)
|
36
|
+
section_names_terms_cleanup(xml)
|
37
|
+
end
|
38
|
+
|
39
|
+
def section_names_refs_cleanup(xml)
|
40
|
+
replace_title(xml, "//references[@normative = 'true']",
|
41
|
+
@i18n&.normref, true)
|
42
|
+
replace_title(xml, "//references[@normative = 'false']",
|
43
|
+
@i18n&.bibliography, true)
|
44
|
+
end
|
45
|
+
|
46
|
+
NO_SYMABBR = "[.//definitions[not(@type)]]".freeze
|
47
|
+
SYMABBR = "[.//definitions[@type = 'symbols']]"\
|
48
|
+
"[.//definitions[@type = 'abbreviated_terms']]".freeze
|
49
|
+
SYMnoABBR = "[.//definitions[@type = 'symbols']]"\
|
50
|
+
"[not(.//definitions[@type = 'abbreviated_terms'])]".freeze
|
51
|
+
ABBRnoSYM = "[.//definitions[@type = 'abbreviated_terms']]"\
|
52
|
+
"[not(.//definitions[@type = 'symbols'])]".freeze
|
53
|
+
|
54
|
+
def section_names_terms_cleanup(x)
|
55
|
+
replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
|
56
|
+
replace_title(x, "//definitions[@type = 'abbreviated_terms']",
|
57
|
+
@i18n&.abbrev)
|
58
|
+
replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
|
59
|
+
replace_title(x, "//terms#{SYMnoABBR} | //clause[.//terms]#{SYMnoABBR}",
|
60
|
+
@i18n&.termsdefsymbols, true)
|
61
|
+
replace_title(x, "//terms#{ABBRnoSYM} | //clause[.//terms]#{ABBRnoSYM}",
|
62
|
+
@i18n&.termsdefabbrev, true)
|
63
|
+
replace_title(x, "//terms#{SYMABBR} | //clause[.//terms]#{SYMABBR}",
|
64
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
65
|
+
replace_title(x, "//terms#{NO_SYMABBR} | //clause[.//terms]#{NO_SYMABBR}",
|
66
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
67
|
+
replace_title(
|
68
|
+
x,
|
69
|
+
"//terms[not(.//definitions)] | //clause[.//terms][not(.//definitions)]",
|
70
|
+
@i18n&.termsdef, true
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -60,15 +60,15 @@ module Asciidoctor
|
|
60
60
|
|
61
61
|
def term_children_cleanup(xmldoc)
|
62
62
|
xmldoc.xpath("//term").each do |t|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
%w(termnote termexample termsource).each do |w|
|
64
|
+
t.xpath("./#{w}").each { |n| t << n.remove }
|
65
|
+
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
68
68
|
|
69
69
|
def termdef_from_termbase(xmldoc)
|
70
70
|
xmldoc.xpath("//term").each do |x|
|
71
|
-
if c = x.at("./origin/termref")
|
71
|
+
if (c = x.at("./origin/termref")) && !x.at("./definition")
|
72
72
|
x.at("./origin").previous = fetch_termbase(c["base"], c.text)
|
73
73
|
end
|
74
74
|
end
|
@@ -93,33 +93,34 @@ module Asciidoctor
|
|
93
93
|
termdomain1_cleanup(xmldoc)
|
94
94
|
termnote_example_cleanup(xmldoc)
|
95
95
|
termdef_subclause_cleanup(xmldoc)
|
96
|
-
term_children_cleanup(xmldoc)
|
96
|
+
term_children_cleanup(xmldoc)
|
97
97
|
termdocsource_cleanup(xmldoc)
|
98
|
-
end
|
98
|
+
end
|
99
99
|
|
100
100
|
# Indices sort after letter but before any following
|
101
101
|
# letter (x, x_m, x_1, xa); we use colon to force that sort order.
|
102
102
|
# Numbers sort *after* letters; we use thorn to force that sort order.
|
103
|
-
def symbol_key(
|
104
|
-
key =
|
103
|
+
def symbol_key(sym)
|
104
|
+
key = sym.dup
|
105
105
|
key.traverse do |n|
|
106
106
|
next unless n.name == "math"
|
107
|
+
|
107
108
|
n.replace(grkletters(MathML2AsciiMath.m2a(n.to_xml)))
|
108
109
|
end
|
109
110
|
ret = Nokogiri::XML(key.to_xml)
|
110
|
-
HTMLEntities.new.decode(ret.text.downcase)
|
111
|
-
gsub(/[\[\]
|
112
|
-
gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
|
113
|
-
gsub(/[0-9]+/, "þ\\0")
|
111
|
+
HTMLEntities.new.decode(ret.text.downcase)
|
112
|
+
.gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
|
113
|
+
.gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
|
114
|
+
.gsub(/[0-9]+/, "þ\\0")
|
114
115
|
end
|
115
|
-
|
116
|
+
|
116
117
|
def grkletters(x)
|
117
118
|
x.gsub(/\b(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)\b/i, "&\\1;")
|
118
119
|
end
|
119
120
|
|
120
|
-
def extract_symbols_list(
|
121
|
+
def extract_symbols_list(dlist)
|
121
122
|
dl_out = []
|
122
|
-
|
123
|
+
dlist.xpath("./dt | ./dd").each do |dtd|
|
123
124
|
if dtd.name == "dt"
|
124
125
|
dl_out << { dt: dtd.remove, key: symbol_key(dtd) }
|
125
126
|
else
|
@@ -128,7 +129,7 @@ module Asciidoctor
|
|
128
129
|
end
|
129
130
|
dl_out
|
130
131
|
end
|
131
|
-
|
132
|
+
|
132
133
|
def symbols_cleanup(docxml)
|
133
134
|
docxml.xpath("//definitions/dl").each do |dl|
|
134
135
|
dl_out = extract_symbols_list(dl)
|
@@ -136,7 +137,7 @@ module Asciidoctor
|
|
136
137
|
dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n")
|
137
138
|
end
|
138
139
|
docxml
|
139
|
-
end
|
140
|
+
end
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
@@ -41,6 +41,11 @@ module Asciidoctor
|
|
41
41
|
inline_macro Asciidoctor::Standoc::IndexRangeInlineMacro
|
42
42
|
inline_macro Asciidoctor::Standoc::AddMacro
|
43
43
|
inline_macro Asciidoctor::Standoc::DelMacro
|
44
|
+
inline_macro Asciidoctor::Standoc::FormInputMacro
|
45
|
+
inline_macro Asciidoctor::Standoc::FormLabelMacro
|
46
|
+
inline_macro Asciidoctor::Standoc::FormTextareaMacro
|
47
|
+
inline_macro Asciidoctor::Standoc::FormSelectMacro
|
48
|
+
inline_macro Asciidoctor::Standoc::FormOptionMacro
|
44
49
|
block Asciidoctor::Standoc::ToDoAdmonitionBlock
|
45
50
|
treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
|
46
51
|
block Asciidoctor::Standoc::PlantUMLBlockMacro
|
@@ -78,8 +83,8 @@ module Asciidoctor
|
|
78
83
|
attr_accessor :_file
|
79
84
|
end
|
80
85
|
|
81
|
-
def self.inherited(
|
82
|
-
|
86
|
+
def self.inherited(konv) # rubocop:disable Lint/MissingSuper
|
87
|
+
konv._file = caller_locations(1..1).first.absolute_path
|
83
88
|
end
|
84
89
|
|
85
90
|
# path to isodoc assets in child gems
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "erb"
|
4
4
|
|
5
5
|
module Asciidoctor
|
6
6
|
module Datamodel
|
7
7
|
class PlantumlRenderer
|
8
|
-
TEMPLATES_PATH = File.expand_path(
|
8
|
+
TEMPLATES_PATH = File.expand_path("../views/datamodel", __dir__).freeze
|
9
9
|
|
10
10
|
attr_reader :yml, :plantuml_path
|
11
11
|
|
@@ -15,23 +15,23 @@ module Asciidoctor
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def join_as_plantuml(*ary)
|
18
|
-
ary.compact.join("\n").sub(/\s+\Z/,
|
18
|
+
ary.compact.join("\n").sub(/\s+\Z/, "")
|
19
19
|
end
|
20
20
|
|
21
21
|
def render
|
22
22
|
ERB.new(
|
23
23
|
File.read(
|
24
|
-
File.join(TEMPLATES_PATH,
|
24
|
+
File.join(TEMPLATES_PATH, "plantuml_representation.adoc.erb")
|
25
25
|
)
|
26
26
|
).result(binding)
|
27
27
|
end
|
28
28
|
|
29
29
|
def diagram_caption
|
30
|
-
yml[
|
30
|
+
yml["caption"]
|
31
31
|
end
|
32
32
|
|
33
33
|
def imports_yml_to_plantuml
|
34
|
-
return if empty?(yml,
|
34
|
+
return if empty?(yml, "imports")
|
35
35
|
|
36
36
|
<<~TEMPLATE
|
37
37
|
'******* IMPORTS ******************************************************
|
@@ -40,7 +40,7 @@ module Asciidoctor
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def class_defs_yml_to_plantuml
|
43
|
-
return if empty?(yml,
|
43
|
+
return if empty?(yml, "classes") && empty?(yml, "enums")
|
44
44
|
|
45
45
|
<<~TEMPLATE
|
46
46
|
'******* CLASS DEFINITIONS ********************************************
|
@@ -52,7 +52,7 @@ module Asciidoctor
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def class_groups_yml_to_plantuml
|
55
|
-
return if empty?(yml,
|
55
|
+
return if empty?(yml, "groups")
|
56
56
|
|
57
57
|
<<~TEMPLATE
|
58
58
|
'******* CLASS GROUPS *************************************************
|
@@ -63,7 +63,7 @@ module Asciidoctor
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def class_relations_yml_to_plantuml
|
66
|
-
return if empty?(yml,
|
66
|
+
return if empty?(yml, "classes") && empty?(yml, "relations")
|
67
67
|
|
68
68
|
<<~TEMPLATE
|
69
69
|
'******* CLASS RELATIONS **********************************************
|
@@ -75,7 +75,7 @@ module Asciidoctor
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def diagram_options_yml_to_plantuml
|
78
|
-
return if empty?(yml,
|
78
|
+
return if empty?(yml, "diagram_options")
|
79
79
|
|
80
80
|
<<~TEMPLATE
|
81
81
|
'******* DIAGRAM SPECIFIC CONFIG **************************************
|
@@ -86,7 +86,7 @@ module Asciidoctor
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def bottom_yml_to_plantuml
|
89
|
-
return if empty?(yml,
|
89
|
+
return if empty?(yml, "bottom")
|
90
90
|
|
91
91
|
<<~TEMPLATE
|
92
92
|
'******* BOTTOM OVERRIDE CONFIG **************************************
|
@@ -95,7 +95,7 @@ module Asciidoctor
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def fidelity_yml_to_plantuml
|
98
|
-
return if empty?(yml,
|
98
|
+
return if empty?(yml, "fidelity")
|
99
99
|
|
100
100
|
<<~TEMPLATE
|
101
101
|
'******* FIDELITY *****************************************************
|
@@ -133,7 +133,7 @@ module Asciidoctor
|
|
133
133
|
|
134
134
|
attributes.map do |(attr_name, attr_hash)|
|
135
135
|
attribute_to_plantuml(attr_name, attr_hash)
|
136
|
-
end.join(
|
136
|
+
end.join("").sub(/\n\Z/, "")
|
137
137
|
end
|
138
138
|
|
139
139
|
def attribute_to_plantuml(attr_name, attr_hash)
|
@@ -143,9 +143,10 @@ module Asciidoctor
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def attribute_cardinality_plantuml(cardinality, with_bracket = true)
|
146
|
-
return
|
147
|
-
|
148
|
-
|
146
|
+
return "" if cardinality.nil? ||
|
147
|
+
(cardinality["min"] == cardinality["max"] &&
|
148
|
+
cardinality["min"] == 1)
|
149
|
+
|
149
150
|
card = "#{cardinality['min']}..#{cardinality['max']}"
|
150
151
|
return card unless with_bracket
|
151
152
|
|
@@ -172,7 +173,7 @@ module Asciidoctor
|
|
172
173
|
def classes_to_relations_plantuml(classes)
|
173
174
|
output_ary = classes.map do |(class_name, class_hash)|
|
174
175
|
class_hash ||= {}
|
175
|
-
relations = class_hash[
|
176
|
+
relations = class_hash["relations"]
|
176
177
|
relations_to_plantuml(class_name, relations)
|
177
178
|
end
|
178
179
|
|
@@ -183,9 +184,9 @@ module Asciidoctor
|
|
183
184
|
return unless relations
|
184
185
|
|
185
186
|
output_ary = relations.map do |relation|
|
186
|
-
source = class_name || relation[
|
187
|
+
source = class_name || relation["source"]
|
187
188
|
relation_to_plantuml(source,
|
188
|
-
relation[
|
189
|
+
relation["target"],
|
189
190
|
relation)
|
190
191
|
end
|
191
192
|
|
@@ -194,41 +195,41 @@ module Asciidoctor
|
|
194
195
|
|
195
196
|
def relation_arrow(relationship, relation)
|
196
197
|
[
|
197
|
-
relationship_type_to_plantuml(
|
198
|
-
relationship[
|
199
|
-
(relation[
|
200
|
-
relationship_type_to_plantuml(
|
201
|
-
relationship[
|
202
|
-
].compact.join(
|
198
|
+
relationship_type_to_plantuml("source",
|
199
|
+
relationship["source"]["type"]),
|
200
|
+
(relation["direction"]).to_s,
|
201
|
+
relationship_type_to_plantuml("target",
|
202
|
+
relationship["target"]["type"]),
|
203
|
+
].compact.join("-")
|
203
204
|
end
|
204
205
|
|
205
206
|
def relation_label(action)
|
206
|
-
return
|
207
|
+
return "" unless action
|
207
208
|
|
208
|
-
case action[
|
209
|
-
when
|
209
|
+
case action["direction"]
|
210
|
+
when "source"
|
210
211
|
" : < #{action['verb']}"
|
211
|
-
when
|
212
|
+
when "target"
|
212
213
|
" : #{action['verb']} >"
|
213
214
|
else
|
214
|
-
|
215
|
+
""
|
215
216
|
end
|
216
217
|
end
|
217
218
|
|
218
219
|
def source_arrow_end(source, relationship)
|
219
220
|
source_attribute = relationship_cardinality_to_plantuml(
|
220
|
-
relationship[
|
221
|
+
relationship["source"]["attribute"]
|
221
222
|
)
|
222
|
-
[source, source_attribute].join(
|
223
|
+
[source, source_attribute].join(" ")
|
223
224
|
end
|
224
225
|
|
225
226
|
def target_arrow_end(target, relationship, action)
|
226
227
|
target_attribute = relationship_cardinality_to_plantuml(
|
227
|
-
relationship[
|
228
|
+
relationship["target"]["attribute"]
|
228
229
|
)
|
229
230
|
[
|
230
|
-
[target_attribute, target].join(
|
231
|
-
relation_label(action)
|
231
|
+
[target_attribute, target].join(" "),
|
232
|
+
relation_label(action),
|
232
233
|
].join
|
233
234
|
end
|
234
235
|
|
@@ -239,9 +240,9 @@ module Asciidoctor
|
|
239
240
|
end
|
240
241
|
|
241
242
|
def relation_to_plantuml(source, target, relation)
|
242
|
-
relationship = relation[
|
243
|
-
relationship[
|
244
|
-
relationship[
|
243
|
+
relationship = relation["relationship"] || {}
|
244
|
+
relationship["source"] ||= {}
|
245
|
+
relationship["target"] ||= {}
|
245
246
|
relation_output_lines(source, target, relation, relationship)
|
246
247
|
end
|
247
248
|
|
@@ -249,22 +250,22 @@ module Asciidoctor
|
|
249
250
|
output_lines = [
|
250
251
|
source_arrow_end(source, relationship),
|
251
252
|
relation_arrow(relationship, relation),
|
252
|
-
target_arrow_end(target, relationship, relation[
|
253
|
-
relation_association(source, target, relationship[
|
254
|
-
].join(
|
253
|
+
target_arrow_end(target, relationship, relation["action"]),
|
254
|
+
relation_association(source, target, relationship["association"]),
|
255
|
+
].join(" ")
|
255
256
|
|
256
257
|
join_as_plantuml(*output_lines)
|
257
258
|
end
|
258
259
|
|
259
260
|
def relationship_type_to_plantuml(relation_end, relationship_type)
|
260
|
-
is_source = (relation_end ==
|
261
|
+
is_source = (relation_end == "source")
|
261
262
|
mappings = {
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
263
|
+
"direct" => is_source ? "<" : ">",
|
264
|
+
"inheritance" => is_source ? "<|" : "|>",
|
265
|
+
"composition" => "*",
|
266
|
+
"aggregation" => "o",
|
266
267
|
}
|
267
|
-
mappings.fetch(relationship_type,
|
268
|
+
mappings.fetch(relationship_type, "")
|
268
269
|
end
|
269
270
|
|
270
271
|
def relationship_cardinality_to_plantuml(attribute)
|
@@ -273,12 +274,12 @@ module Asciidoctor
|
|
273
274
|
return unless attribute_name
|
274
275
|
|
275
276
|
attribute_hash = attribute[attribute_name] || {}
|
276
|
-
card = attribute_cardinality(attribute_hash[
|
277
|
+
card = attribute_cardinality(attribute_hash["cardinality"])
|
277
278
|
"\"+#{attribute_name}#{card}\""
|
278
279
|
end
|
279
280
|
|
280
281
|
def attribute_cardinality(attribute_cardinality)
|
281
|
-
cardinality =
|
282
|
+
cardinality = ""
|
282
283
|
if attribute_cardinality
|
283
284
|
cardinality = attribute_cardinality_plantuml(
|
284
285
|
attribute_cardinality,
|
@@ -308,7 +309,7 @@ module Asciidoctor
|
|
308
309
|
end
|
309
310
|
|
310
311
|
def model_stereotype_to_plantuml(model_stereotype)
|
311
|
-
return
|
312
|
+
return "" unless model_stereotype
|
312
313
|
|
313
314
|
" <<#{model_stereotype}>>"
|
314
315
|
end
|
@@ -325,7 +326,7 @@ module Asciidoctor
|
|
325
326
|
groups ||= []
|
326
327
|
return if groups.empty?
|
327
328
|
|
328
|
-
groups.reduce(
|
329
|
+
groups.reduce("") do |output, group|
|
329
330
|
output += "\ntogether {\n"
|
330
331
|
group.each do |class_name|
|
331
332
|
output += "\nclass #{class_name}\n"
|
@@ -350,9 +351,9 @@ module Asciidoctor
|
|
350
351
|
end
|
351
352
|
|
352
353
|
def format_hidden_class(accum, fidelity_classes, class_hash)
|
353
|
-
return accum if class_hash[
|
354
|
+
return accum if class_hash["relations"].nil?
|
354
355
|
|
355
|
-
class_hash[
|
356
|
+
class_hash["relations"].each_with_object(accum) do |relation, acc|
|
356
357
|
format_source_target_relation(relation, fidelity_classes, acc)
|
357
358
|
format_association_relation(relation, fidelity_classes, acc)
|
358
359
|
end
|
@@ -367,36 +368,36 @@ module Asciidoctor
|
|
367
368
|
end
|
368
369
|
|
369
370
|
def format_association_relation(relation, fidelity_classes, acc)
|
370
|
-
return unless relation[
|
371
|
-
|
371
|
+
return unless relation["relationship"] &&
|
372
|
+
relation["relationship"]["association"]
|
372
373
|
|
373
|
-
association = relation[
|
374
|
+
association = relation["relationship"]["association"]
|
374
375
|
return unless association && !fidelity_classes.key?(association)
|
375
376
|
|
376
377
|
acc.merge!(association => true)
|
377
378
|
end
|
378
379
|
|
379
380
|
def hide_other_classes(fidelity)
|
380
|
-
return
|
381
|
+
return "" if fidelity.nil? || fidelity["classes"].nil?
|
381
382
|
|
382
|
-
output =
|
383
|
-
hidden_classes = fidelity[
|
384
|
-
|
385
|
-
format_hidden_class(acc, fidelity[
|
383
|
+
output = ""
|
384
|
+
hidden_classes = fidelity["classes"]
|
385
|
+
.reduce({}) do |acc, (_class_name, class_hash)|
|
386
|
+
format_hidden_class(acc, fidelity["classes"], class_hash)
|
386
387
|
end
|
387
388
|
|
388
|
-
hidden_classes.
|
389
|
+
hidden_classes.each_key do |hidden_class_name|
|
389
390
|
output += "\nhide #{hidden_class_name}\n"
|
390
391
|
end
|
391
392
|
output
|
392
393
|
end
|
393
394
|
|
394
395
|
def fidelity_to_plantuml(fidelity)
|
395
|
-
return
|
396
|
+
return "" if fidelity.nil?
|
396
397
|
|
397
|
-
output =
|
398
|
-
output += hide_other_classes(fidelity) if fidelity[
|
399
|
-
output += "\nhide members\n" if fidelity[
|
398
|
+
output = ""
|
399
|
+
output += hide_other_classes(fidelity) if fidelity["hideOtherClasses"]
|
400
|
+
output += "\nhide members\n" if fidelity["hideMembers"]
|
400
401
|
output
|
401
402
|
end
|
402
403
|
|