metanorma-standoc 1.9.1 → 1.9.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -2
- data/lib/asciidoctor/standoc/blocks.rb +18 -3
- data/lib/asciidoctor/standoc/blocks_notes.rb +29 -18
- data/lib/asciidoctor/standoc/cleanup.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_block.rb +30 -12
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +23 -12
- data/lib/asciidoctor/standoc/cleanup_ref.rb +3 -2
- data/lib/asciidoctor/standoc/converter.rb +7 -2
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
- data/lib/asciidoctor/standoc/isodoc.rng +174 -0
- data/lib/asciidoctor/standoc/macros.rb +11 -11
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
- data/lib/asciidoctor/standoc/section.rb +3 -1
- data/lib/asciidoctor/standoc/terms.rb +24 -17
- data/lib/asciidoctor/standoc/utils.rb +3 -3
- data/lib/asciidoctor/standoc/validate.rb +18 -16
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor/blocks_spec.rb +829 -734
- data/spec/asciidoctor/cleanup_sections_spec.rb +38 -1
- data/spec/asciidoctor/isobib_cache_spec.rb +406 -358
- data/spec/asciidoctor/macros_spec.rb +537 -441
- data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor/section_spec.rb +367 -297
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +50 -50
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +24 -24
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
- 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 +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b789e06df237e881bdd055cfe9b90e191d781e71e82dd6a80c098f23b08934
|
4
|
+
data.tar.gz: 27f1499d7f7adccf29c2b9c9ac731e6ff1988a008530a4aa13e63adb4fbef490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72e91aac553b2e9d3151a59fde54b02ae5cb6340aeb0781dd4326d5a6bce3166e20fd2ece37d909c3e8b7f72d6d26892bd279d4256b190cf28dbe41e1bdbf3e
|
7
|
+
data.tar.gz: 8314c96a3af15b47d56c42cd040e369455616b40dafb37a3d2ee32d0ba46976293eee36f3b9ab99d3b2d94002df3f3bf0a319e98f262e0d5eb3049fb90c30d4f
|
data/.rubocop.yml
CHANGED
@@ -30,6 +30,7 @@ module Asciidoctor
|
|
30
30
|
def open(node)
|
31
31
|
role = node.role || node.attr("style")
|
32
32
|
reqt_subpart(role) and return requirement_subpart(node)
|
33
|
+
role == "form" and return form(node)
|
33
34
|
result = []
|
34
35
|
node.blocks.each do |b|
|
35
36
|
result << send(b.context, b)
|
@@ -37,6 +38,17 @@ module Asciidoctor
|
|
37
38
|
result
|
38
39
|
end
|
39
40
|
|
41
|
+
def form(node)
|
42
|
+
noko do |xml|
|
43
|
+
xml.form **attr_code(
|
44
|
+
id: Metanorma::Utils::anchor_or_uuid,
|
45
|
+
name: node.attr("name"), action: node.attr("action")
|
46
|
+
) do |f|
|
47
|
+
f << node.content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def literal_attrs(node)
|
41
53
|
attr_code(id_attr(node).merge(keep_attrs(node)))
|
42
54
|
end
|
@@ -71,11 +83,14 @@ module Asciidoctor
|
|
71
83
|
|
72
84
|
def example(node)
|
73
85
|
return term_example(node) if in_terms?
|
86
|
+
|
74
87
|
role = node.role || node.attr("style")
|
75
88
|
%w(recommendation requirement permission).include?(role) and
|
76
89
|
return requirement(node, role)
|
77
90
|
return pseudocode_example(node) if role == "pseudocode"
|
78
91
|
return svgmap_example(node) if role == "svgmap"
|
92
|
+
return form(node) if role == "form"
|
93
|
+
|
79
94
|
example_proper(node)
|
80
95
|
end
|
81
96
|
|
@@ -91,9 +106,9 @@ module Asciidoctor
|
|
91
106
|
noko do |xml|
|
92
107
|
xml.svgmap **attr_code(svgmap_attrs(node).merge(
|
93
108
|
src: node.attr("src"), alt: node.attr("alt"))) do |ex|
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
figure_title(node, ex)
|
110
|
+
ex << node.content
|
111
|
+
end
|
97
112
|
end.join("\n")
|
98
113
|
end
|
99
114
|
|
@@ -2,33 +2,41 @@ module Asciidoctor
|
|
2
2
|
module Standoc
|
3
3
|
module Blocks
|
4
4
|
def termnote_attrs(node)
|
5
|
-
attr_code(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
attr_code(
|
6
|
+
id_attr(node).merge(
|
7
|
+
unnumbered: node.attr("unnumbered"),
|
8
|
+
number: node.attr("number"),
|
9
|
+
subsequence: node.attr("subsequence"),
|
10
|
+
"keep-with-next": node.attr("keep-with-next"),
|
11
|
+
"keep-lines-together": node.attr("keep-with-next"),
|
12
|
+
"keep-separate": node.attr("keep-separate")
|
13
|
+
)
|
14
|
+
)
|
12
15
|
end
|
13
16
|
|
14
17
|
def note_attrs(node)
|
15
|
-
attr_code(
|
16
|
-
.merge(
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
attr_code(
|
19
|
+
termnote_attrs(node).merge(
|
20
|
+
type: node.attr("type"),
|
21
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
|
22
|
+
)
|
23
|
+
)
|
20
24
|
end
|
21
25
|
|
22
26
|
def sidebar_attrs(node)
|
23
|
-
todo_attrs(node).merge(
|
24
|
-
|
27
|
+
todo_attrs(node).merge(
|
28
|
+
attr_code(
|
29
|
+
from: node.attr("from"),
|
30
|
+
to: node.attr("to") || node.attr("from")
|
31
|
+
)
|
32
|
+
)
|
25
33
|
end
|
26
34
|
|
27
35
|
def sidebar(node)
|
28
36
|
return unless draft?
|
29
37
|
|
30
38
|
noko do |xml|
|
31
|
-
xml.review **
|
39
|
+
xml.review **sidebar_attrs(node) do |r|
|
32
40
|
wrap_in_para(node, r)
|
33
41
|
end
|
34
42
|
end
|
@@ -73,9 +81,12 @@ module Asciidoctor
|
|
73
81
|
a = node.attr("type") and ["danger", "safety precautions"].each do |t|
|
74
82
|
name = t if a.casecmp(t).zero?
|
75
83
|
end
|
76
|
-
attr_code(
|
77
|
-
.merge(
|
78
|
-
|
84
|
+
attr_code(
|
85
|
+
keep_attrs(node).merge(
|
86
|
+
id: Metanorma::Utils::anchor_or_uuid(node), type: name,
|
87
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
|
88
|
+
)
|
89
|
+
)
|
79
90
|
end
|
80
91
|
|
81
92
|
def admonition(node)
|
@@ -37,15 +37,15 @@ module Asciidoctor
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def insert_thead(
|
41
|
-
thead =
|
40
|
+
def insert_thead(table)
|
41
|
+
thead = table.at("./thead")
|
42
42
|
return thead unless thead.nil?
|
43
43
|
|
44
|
-
if tname =
|
44
|
+
if tname = table.at("./name")
|
45
45
|
thead = tname.add_next_sibling("<thead/>").first
|
46
46
|
return thead
|
47
47
|
end
|
48
|
-
|
48
|
+
table.children.first.add_previous_sibling("<thead/>").first
|
49
49
|
end
|
50
50
|
|
51
51
|
def header_rows_cleanup(xmldoc)
|
@@ -144,7 +144,7 @@ module Asciidoctor
|
|
144
144
|
ELEMS_ALLOW_NOTES = %w[p formula ul ol dl figure].freeze
|
145
145
|
|
146
146
|
# if a note is at the end of a section, it is left alone
|
147
|
-
# if a note is followed by a non-note block,
|
147
|
+
# if a note is followed by a non-note block,
|
148
148
|
# it is moved inside its preceding block if it is not delimited
|
149
149
|
# (so there was no way of making that block include the note)
|
150
150
|
def note_cleanup(xmldoc)
|
@@ -164,7 +164,7 @@ module Asciidoctor
|
|
164
164
|
|
165
165
|
def link_callouts_to_annotations(callouts, annotations)
|
166
166
|
callouts.each_with_index do |c, i|
|
167
|
-
c["target"] = "_
|
167
|
+
c["target"] = "_#{UUIDTools::UUID.random_create}"
|
168
168
|
annotations[i]["id"] = c["target"]
|
169
169
|
end
|
170
170
|
end
|
@@ -195,25 +195,43 @@ module Asciidoctor
|
|
195
195
|
xmldoc.xpath("//sourcecode").each do |x|
|
196
196
|
x.traverse do |n|
|
197
197
|
next unless n.text?
|
198
|
-
next unless /#{Regexp.escape(@sourcecode_markup_start)}
|
198
|
+
next unless /#{Regexp.escape(@sourcecode_markup_start)}/
|
199
|
+
.match?(n.text)
|
199
200
|
|
200
201
|
n.replace(sourcecode_markup(n))
|
201
202
|
end
|
202
203
|
end
|
203
204
|
end
|
204
205
|
|
205
|
-
def
|
206
|
+
def safe_noko(text, doc)
|
207
|
+
Nokogiri::XML::Text.new(text, doc).to_xml(
|
208
|
+
encoding: "US-ASCII",
|
209
|
+
save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
|
210
|
+
)
|
211
|
+
end
|
212
|
+
|
213
|
+
def sourcecode_markup(node)
|
206
214
|
acc = []
|
207
|
-
|
215
|
+
node.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|
|
216
|
+
#{Regexp.escape(@sourcecode_markup_end)})/x)
|
208
217
|
.each_slice(4).map do |a|
|
209
|
-
acc <<
|
210
|
-
.to_xml(encoding: "US-ASCII", save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
218
|
+
acc << safe_noko(a[0], node.document)
|
211
219
|
next unless a.size == 4
|
212
220
|
|
213
|
-
acc << Asciidoctor.convert(
|
221
|
+
acc << Asciidoctor.convert(
|
222
|
+
a[2], doctype: :inline, backend: (self&.backend&.to_sym || :standoc)
|
223
|
+
)
|
214
224
|
end
|
215
225
|
acc.join
|
216
226
|
end
|
227
|
+
|
228
|
+
def form_cleanup(xmldoc)
|
229
|
+
xmldoc.xpath("//select").each do |s|
|
230
|
+
while s&.next_element&.name == "option"
|
231
|
+
s << s.next_element
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
217
235
|
end
|
218
236
|
end
|
219
237
|
end
|
@@ -39,11 +39,15 @@ module Asciidoctor
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def norm_ref_preface(ref)
|
42
|
-
|
43
|
-
|
42
|
+
if ref.at("./note[@type = 'boilerplate']")
|
43
|
+
unwrap_boilerplate_clauses(ref, ".")
|
44
|
+
else
|
45
|
+
refs = ref.elements.select do |e|
|
46
|
+
%w(references bibitem).include? e.name
|
47
|
+
end
|
48
|
+
pref = refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref
|
49
|
+
ref.at("./title").next = "<p>#{pref}</p>"
|
44
50
|
end
|
45
|
-
pref = refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref
|
46
|
-
ref.at("./title").next = "<p>#{pref}</p>"
|
47
51
|
end
|
48
52
|
|
49
53
|
TERM_CLAUSE = "//sections/terms | "\
|
@@ -69,25 +73,32 @@ module Asciidoctor
|
|
69
73
|
xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
|
70
74
|
end
|
71
75
|
|
72
|
-
def
|
73
|
-
xmldoc.xpath(
|
74
|
-
f.xpath(".//clause[@type = 'boilerplate']
|
76
|
+
def unwrap_boilerplate_clauses(xmldoc, xpath)
|
77
|
+
xmldoc.xpath(xpath).each do |f|
|
78
|
+
f.xpath(".//clause[@type = 'boilerplate'] | "\
|
79
|
+
".//note[@type = 'boilerplate']").each do |c|
|
75
80
|
c&.at("./title")&.remove
|
76
81
|
c.replace(c.children)
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
81
|
-
def
|
82
|
-
isodoc = boilerplate_isodoc(xmldoc)
|
83
|
-
termdef_boilerplate_cleanup(xmldoc)
|
86
|
+
def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
|
84
87
|
xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
|
85
88
|
next if f.at("./clause[@type = 'boilerplate']")
|
86
89
|
|
87
|
-
term_defs_boilerplate(f.at("./title"),
|
90
|
+
term_defs_boilerplate(f.at("./title"),
|
91
|
+
xmldoc.xpath(".//termdocsource"),
|
88
92
|
f.at(".//term"), f.at(".//p"), isodoc)
|
93
|
+
break if once
|
89
94
|
end
|
90
|
-
|
95
|
+
end
|
96
|
+
|
97
|
+
def boilerplate_cleanup(xmldoc)
|
98
|
+
isodoc = boilerplate_isodoc(xmldoc)
|
99
|
+
termdef_boilerplate_cleanup(xmldoc)
|
100
|
+
termdef_boilerplate_insert(xmldoc, isodoc)
|
101
|
+
unwrap_boilerplate_clauses(xmldoc, self.class::TERM_CLAUSE)
|
91
102
|
f = xmldoc.at(self.class::NORM_REF) and norm_ref_preface(f)
|
92
103
|
initial_boilerplate(xmldoc, isodoc)
|
93
104
|
end
|
@@ -74,8 +74,9 @@ module Asciidoctor
|
|
74
74
|
|
75
75
|
def normref_cleanup(xmldoc)
|
76
76
|
r = xmldoc.at(self.class::NORM_REF) || return
|
77
|
-
preface = r.xpath("./title/following-sibling::*") & # intersection
|
78
|
-
|
77
|
+
preface = ((r.xpath("./title/following-sibling::*") & # intersection
|
78
|
+
r.xpath("./bibitem[1]/preceding-sibling::*")) -
|
79
|
+
r.xpath("./note[@type = 'boilerplate']/descendant-or-self::*"))
|
79
80
|
preface.each(&:remove)
|
80
81
|
end
|
81
82
|
|
@@ -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
|
|