metanorma-standoc 1.11.3 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -31
  3. data/.gitignore +23 -0
  4. data/Gemfile +0 -1
  5. data/lib/asciidoctor/standoc/base.rb +2 -145
  6. data/lib/asciidoctor/standoc/blocks.rb +2 -238
  7. data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
  8. data/lib/asciidoctor/standoc/cleanup.rb +2 -208
  9. data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +2 -172
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -212
  12. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
  13. data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -189
  15. data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
  16. data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
  17. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -103
  18. data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
  19. data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
  20. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
  21. data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
  22. data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
  23. data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -139
  24. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -192
  25. data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
  26. data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
  27. data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
  28. data/lib/asciidoctor/standoc/converter.rb +2 -123
  29. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
  30. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
  31. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
  32. data/lib/asciidoctor/standoc/deprecated.rb +5 -0
  33. data/lib/asciidoctor/standoc/front.rb +2 -219
  34. data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
  35. data/lib/asciidoctor/standoc/inline.rb +2 -231
  36. data/lib/asciidoctor/standoc/lists.rb +2 -119
  37. data/lib/asciidoctor/standoc/macros.rb +2 -203
  38. data/lib/asciidoctor/standoc/macros_form.rb +2 -62
  39. data/lib/asciidoctor/standoc/macros_note.rb +2 -44
  40. data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
  41. data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
  42. data/lib/asciidoctor/standoc/ref.rb +2 -251
  43. data/lib/asciidoctor/standoc/ref_sect.rb +2 -153
  44. data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
  45. data/lib/asciidoctor/standoc/render.rb +2 -116
  46. data/lib/asciidoctor/standoc/reqt.rb +2 -89
  47. data/lib/asciidoctor/standoc/section.rb +2 -194
  48. data/lib/asciidoctor/standoc/table.rb +2 -84
  49. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
  50. data/lib/asciidoctor/standoc/terms.rb +2 -153
  51. data/lib/asciidoctor/standoc/utils.rb +2 -100
  52. data/lib/asciidoctor/standoc/validate.rb +2 -157
  53. data/lib/asciidoctor/standoc/validate_section.rb +2 -54
  54. data/lib/isodoc/html/htmlstyle.css +44 -29
  55. data/lib/isodoc/html/htmlstyle.scss +17 -12
  56. data/lib/metanorma/standoc/base.rb +163 -0
  57. data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
  58. data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +2 -2
  59. data/lib/metanorma/standoc/blocks.rb +239 -0
  60. data/lib/metanorma/standoc/blocks_notes.rb +101 -0
  61. data/lib/metanorma/standoc/cleanup.rb +157 -0
  62. data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
  63. data/lib/metanorma/standoc/cleanup_block.rb +173 -0
  64. data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
  65. data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
  66. data/lib/metanorma/standoc/cleanup_image.rb +70 -0
  67. data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
  68. data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
  69. data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
  70. data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
  71. data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
  72. data/lib/metanorma/standoc/cleanup_section.rb +212 -0
  73. data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
  74. data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
  75. data/lib/metanorma/standoc/cleanup_table.rb +68 -0
  76. data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
  77. data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
  78. data/lib/metanorma/standoc/cleanup_text.rb +74 -0
  79. data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
  80. data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
  81. data/lib/metanorma/standoc/converter.rb +126 -0
  82. data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
  83. data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
  84. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
  85. data/lib/metanorma/standoc/front.rb +224 -0
  86. data/lib/metanorma/standoc/front_contributor.rb +192 -0
  87. data/lib/metanorma/standoc/inline.rb +232 -0
  88. data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +104 -3
  89. data/lib/metanorma/standoc/lists.rb +120 -0
  90. data/lib/metanorma/standoc/macros.rb +205 -0
  91. data/lib/metanorma/standoc/macros_embed.rb +72 -0
  92. data/lib/metanorma/standoc/macros_form.rb +63 -0
  93. data/lib/metanorma/standoc/macros_note.rb +45 -0
  94. data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
  95. data/lib/metanorma/standoc/macros_terms.rb +194 -0
  96. data/lib/metanorma/standoc/ref.rb +243 -0
  97. data/lib/metanorma/standoc/ref_sect.rb +153 -0
  98. data/lib/{asciidoctor/standoc/ref_date_id.rb → metanorma/standoc/ref_utility.rb} +43 -5
  99. data/lib/metanorma/standoc/render.rb +115 -0
  100. data/lib/metanorma/standoc/reqt.rb +90 -0
  101. data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
  102. data/lib/metanorma/standoc/section.rb +209 -0
  103. data/lib/metanorma/standoc/table.rb +85 -0
  104. data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
  105. data/lib/metanorma/standoc/terms.rb +160 -0
  106. data/lib/metanorma/standoc/utils.rb +101 -0
  107. data/lib/metanorma/standoc/validate.rb +158 -0
  108. data/lib/metanorma/standoc/validate_section.rb +55 -0
  109. data/lib/metanorma/standoc/version.rb +1 -1
  110. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
  111. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
  112. data/lib/metanorma-standoc.rb +1 -1
  113. data/metanorma-standoc.gemspec +1 -1
  114. data/spec/assets/a1.adoc +8 -0
  115. data/spec/assets/a2.adoc +8 -0
  116. data/spec/assets/a3.adoc +9 -0
  117. data/spec/assets/a4.adoc +4 -0
  118. data/spec/{asciidoctor → metanorma}/base_spec.rb +499 -407
  119. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  120. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
  121. data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +1 -1
  122. data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +1 -1
  123. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +5 -5
  124. data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +227 -119
  125. data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +1 -1
  126. data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +1 -1
  127. data/spec/{asciidoctor → metanorma}/inline_spec.rb +170 -1
  128. data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +1 -1
  129. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  130. data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
  131. data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
  132. data/spec/{asciidoctor → metanorma}/macros_spec.rb +97 -6
  133. data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
  134. data/spec/metanorma/refs_dl_spec.rb +863 -0
  135. data/spec/{asciidoctor → metanorma}/refs_spec.rb +522 -15
  136. data/spec/{asciidoctor → metanorma}/section_spec.rb +59 -1
  137. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  138. data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
  139. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +46 -46
  140. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  141. data/spec/vcr_cassettes/hide_refs.yml +599 -0
  142. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  143. data/spec/vcr_cassettes/isobib_get_123_1.yml +24 -24
  144. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
  145. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  146. data/spec/vcr_cassettes/isobib_get_124.yml +10 -10
  147. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
  148. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  149. metadata +88 -32
  150. data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -0,0 +1,409 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ module Metanorma
6
+ module Datamodel
7
+ class PlantumlRenderer
8
+ TEMPLATES_PATH = File.expand_path("../views/datamodel", __dir__).freeze
9
+
10
+ attr_reader :yml, :plantuml_path
11
+
12
+ def initialize(yml, plantuml_path)
13
+ @yml = yml
14
+ @plantuml_path = plantuml_path
15
+ end
16
+
17
+ def join_as_plantuml(*ary)
18
+ ary.compact.join("\n").sub(/\s+\Z/, "")
19
+ end
20
+
21
+ def render
22
+ ERB.new(
23
+ File.read(
24
+ File.join(TEMPLATES_PATH, "plantuml_representation.adoc.erb")
25
+ )
26
+ ).result(binding)
27
+ end
28
+
29
+ def diagram_caption
30
+ yml["caption"]
31
+ end
32
+
33
+ def imports_yml_to_plantuml
34
+ return if empty?(yml, "imports")
35
+
36
+ <<~TEMPLATE
37
+ '******* IMPORTS ******************************************************
38
+ !include #{plantuml_path}/style.uml.inc
39
+ TEMPLATE
40
+ end
41
+
42
+ def class_defs_yml_to_plantuml
43
+ return if empty?(yml, "classes") && empty?(yml, "enums")
44
+
45
+ <<~TEMPLATE
46
+ '******* CLASS DEFINITIONS ********************************************
47
+ #{join_as_plantuml(
48
+ classes_to_classes_plantuml(yml['classes']),
49
+ enums_to_enums_plantuml(yml['enums'])
50
+ )}
51
+ TEMPLATE
52
+ end
53
+
54
+ def class_groups_yml_to_plantuml
55
+ return if empty?(yml, "groups")
56
+
57
+ <<~TEMPLATE
58
+ '******* CLASS GROUPS *************************************************
59
+ #{join_as_plantuml(
60
+ groups_to_plantuml(yml['groups'])
61
+ )}
62
+ TEMPLATE
63
+ end
64
+
65
+ def class_relations_yml_to_plantuml
66
+ return if empty?(yml, "classes") && empty?(yml, "relations")
67
+
68
+ <<~TEMPLATE
69
+ '******* CLASS RELATIONS **********************************************
70
+ #{join_as_plantuml(
71
+ classes_to_relations_plantuml(yml['classes']),
72
+ relations_to_plantuml(nil, yml['relations'])
73
+ )}
74
+ TEMPLATE
75
+ end
76
+
77
+ def diagram_options_yml_to_plantuml
78
+ return if empty?(yml, "diagram_options")
79
+
80
+ <<~TEMPLATE
81
+ '******* DIAGRAM SPECIFIC CONFIG **************************************
82
+ #{join_as_plantuml(
83
+ diagram_options_to_plantuml(yml['diagram_options'])
84
+ )}
85
+ TEMPLATE
86
+ end
87
+
88
+ def bottom_yml_to_plantuml
89
+ return if empty?(yml, "bottom")
90
+
91
+ <<~TEMPLATE
92
+ '******* BOTTOM OVERRIDE CONFIG **************************************
93
+ #{join_as_plantuml(bottom_to_plantuml(yml['bottom']))}
94
+ TEMPLATE
95
+ end
96
+
97
+ def fidelity_yml_to_plantuml
98
+ return if empty?(yml, "fidelity")
99
+
100
+ <<~TEMPLATE
101
+ '******* FIDELITY *****************************************************
102
+ #{join_as_plantuml(fidelity_to_plantuml(yml['fidelity']))}
103
+ TEMPLATE
104
+ end
105
+
106
+ def classes_to_classes_plantuml(classes)
107
+ classes ||= {}
108
+
109
+ return if classes.empty?
110
+
111
+ classes.map do |(class_name, class_hash)|
112
+ class_to_plantuml(class_name, class_hash)
113
+ end.join("\n")
114
+ end
115
+
116
+ def class_to_plantuml(class_name, class_hash)
117
+ return unless class_name
118
+
119
+ class_hash ||= {}
120
+
121
+ <<~TEMPLATE
122
+ class #{class_name}#{model_stereotype_to_plantuml(class_hash['type'])} {
123
+ #{join_as_plantuml(
124
+ attributes_to_plantuml(class_hash['attributes']),
125
+ constraints_to_plantuml(class_hash['constraints'])
126
+ )}
127
+ }
128
+ TEMPLATE
129
+ end
130
+
131
+ def attributes_to_plantuml(attributes)
132
+ return unless attributes
133
+
134
+ attributes.map do |(attr_name, attr_hash)|
135
+ attribute_to_plantuml(attr_name, attr_hash)
136
+ end.join("").sub(/\n\Z/, "")
137
+ end
138
+
139
+ def attribute_to_plantuml(attr_name, attr_hash)
140
+ <<~TEMPLATE
141
+ +#{attr_name}: #{attr_hash['type']}#{attribute_cardinality_plantuml(attr_hash['cardinality'])}
142
+ TEMPLATE
143
+ end
144
+
145
+ def attribute_cardinality_plantuml(cardinality, with_bracket = true)
146
+ return "" if cardinality.nil? ||
147
+ (cardinality["min"] == cardinality["max"] &&
148
+ cardinality["min"] == 1)
149
+
150
+ card = "#{cardinality['min']}..#{cardinality['max']}"
151
+ return card unless with_bracket
152
+
153
+ "[#{card}]"
154
+ end
155
+
156
+ def constraints_to_plantuml(constraints)
157
+ constraints ||= []
158
+
159
+ return if constraints.empty?
160
+
161
+ constraints_output = constraints.map do |constraint|
162
+ " {#{constraint}}"
163
+ end
164
+
165
+ <<~TEMPLATE
166
+ __ constraints __
167
+ #{join_as_plantuml(
168
+ *constraints_output
169
+ )}
170
+ TEMPLATE
171
+ end
172
+
173
+ def classes_to_relations_plantuml(classes)
174
+ output_ary = classes.map do |(class_name, class_hash)|
175
+ class_hash ||= {}
176
+ relations = class_hash["relations"]
177
+ relations_to_plantuml(class_name, relations)
178
+ end
179
+
180
+ join_as_plantuml(*output_ary)
181
+ end
182
+
183
+ def relations_to_plantuml(class_name, relations)
184
+ return unless relations
185
+
186
+ output_ary = relations.map do |relation|
187
+ source = class_name || relation["source"]
188
+ relation_to_plantuml(source,
189
+ relation["target"],
190
+ relation)
191
+ end
192
+
193
+ join_as_plantuml(*output_ary)
194
+ end
195
+
196
+ def relation_arrow(relationship, relation)
197
+ [
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("-")
204
+ end
205
+
206
+ def relation_label(action)
207
+ return "" unless action
208
+
209
+ case action["direction"]
210
+ when "source"
211
+ " : < #{action['verb']}"
212
+ when "target"
213
+ " : #{action['verb']} >"
214
+ else
215
+ ""
216
+ end
217
+ end
218
+
219
+ def source_arrow_end(source, relationship)
220
+ source_attribute = relationship_cardinality_to_plantuml(
221
+ relationship["source"]["attribute"]
222
+ )
223
+ [source, source_attribute].join(" ")
224
+ end
225
+
226
+ def target_arrow_end(target, relationship, action)
227
+ target_attribute = relationship_cardinality_to_plantuml(
228
+ relationship["target"]["attribute"]
229
+ )
230
+ [
231
+ [target_attribute, target].join(" "),
232
+ relation_label(action),
233
+ ].join
234
+ end
235
+
236
+ def relation_association(source, target, association)
237
+ return unless association
238
+
239
+ "\n(#{source}, #{target}) . #{association}"
240
+ end
241
+
242
+ def relation_to_plantuml(source, target, relation)
243
+ relationship = relation["relationship"] || {}
244
+ relationship["source"] ||= {}
245
+ relationship["target"] ||= {}
246
+ relation_output_lines(source, target, relation, relationship)
247
+ end
248
+
249
+ def relation_output_lines(source, target, relation, relationship)
250
+ output_lines = [
251
+ source_arrow_end(source, relationship),
252
+ relation_arrow(relationship, relation),
253
+ target_arrow_end(target, relationship, relation["action"]),
254
+ relation_association(source, target, relationship["association"]),
255
+ ].join(" ")
256
+
257
+ join_as_plantuml(*output_lines)
258
+ end
259
+
260
+ def relationship_type_to_plantuml(relation_end, relationship_type)
261
+ is_source = (relation_end == "source")
262
+ mappings = {
263
+ "direct" => is_source ? "<" : ">",
264
+ "inheritance" => is_source ? "<|" : "|>",
265
+ "composition" => "*",
266
+ "aggregation" => "o",
267
+ }
268
+ mappings.fetch(relationship_type, "")
269
+ end
270
+
271
+ def relationship_cardinality_to_plantuml(attribute)
272
+ attribute_name = (attribute || {}).keys.first
273
+
274
+ return unless attribute_name
275
+
276
+ attribute_hash = attribute[attribute_name] || {}
277
+ card = attribute_cardinality(attribute_hash["cardinality"])
278
+ "\"+#{attribute_name}#{card}\""
279
+ end
280
+
281
+ def attribute_cardinality(attribute_cardinality)
282
+ cardinality = ""
283
+ if attribute_cardinality
284
+ cardinality = attribute_cardinality_plantuml(
285
+ attribute_cardinality,
286
+ false
287
+ )
288
+ cardinality = " #{cardinality}"
289
+ end
290
+ cardinality
291
+ end
292
+
293
+ def enums_to_enums_plantuml(enums)
294
+ enums ||= {}
295
+
296
+ enums.map do |(enum_name, enum_hash)|
297
+ enum_to_plantuml(enum_name, enum_hash)
298
+ end.join("\n\n")
299
+ end
300
+
301
+ def enum_to_plantuml(enum_name, enum_hash)
302
+ enum_hash ||= {}
303
+
304
+ <<~TEMPLATE
305
+ enum #{enum_name}#{model_stereotype_to_plantuml(enum_hash['type'])} {
306
+ #{join_as_plantuml(enum_values_to_plantuml(enum_hash['values']))}
307
+ }
308
+ TEMPLATE
309
+ end
310
+
311
+ def model_stereotype_to_plantuml(model_stereotype)
312
+ return "" unless model_stereotype
313
+
314
+ " <<#{model_stereotype}>>"
315
+ end
316
+
317
+ def enum_values_to_plantuml(enum_values)
318
+ output_ary = enum_values.map do |(enum_value, _enum_value_hash)|
319
+ " #{enum_value}"
320
+ end
321
+
322
+ join_as_plantuml(*output_ary)
323
+ end
324
+
325
+ def groups_to_plantuml(groups)
326
+ groups ||= []
327
+ return if groups.empty?
328
+
329
+ groups.reduce("") do |output, group|
330
+ output += "\ntogether {\n"
331
+ group.each do |class_name|
332
+ output += "\nclass #{class_name}\n"
333
+ end
334
+ output += "\n}\n"
335
+ output
336
+ end
337
+ end
338
+
339
+ def diagram_options_to_plantuml(diagram_options)
340
+ diagram_options ||= []
341
+ return if diagram_options.empty?
342
+
343
+ "#{diagram_options.join("\n")}\n"
344
+ end
345
+
346
+ def bottom_to_plantuml(bottom)
347
+ bottom ||= []
348
+ return if bottom.empty?
349
+
350
+ "#{bottom.join("\n")}\n"
351
+ end
352
+
353
+ def format_hidden_class(accum, fidelity_classes, class_hash)
354
+ return accum if class_hash["relations"].nil?
355
+
356
+ class_hash["relations"].each_with_object(accum) do |relation, acc|
357
+ format_source_target_relation(relation, fidelity_classes, acc)
358
+ format_association_relation(relation, fidelity_classes, acc)
359
+ end
360
+ end
361
+
362
+ def format_source_target_relation(relation, fidelity_classes, acc)
363
+ %w[source target].each do |type|
364
+ next unless relation[type] && !fidelity_classes.key?(relation[type])
365
+
366
+ acc.merge!(relation[type] => true)
367
+ end
368
+ end
369
+
370
+ def format_association_relation(relation, fidelity_classes, acc)
371
+ return unless relation["relationship"] &&
372
+ relation["relationship"]["association"]
373
+
374
+ association = relation["relationship"]["association"]
375
+ return unless association && !fidelity_classes.key?(association)
376
+
377
+ acc.merge!(association => true)
378
+ end
379
+
380
+ def hide_other_classes(fidelity)
381
+ return "" if fidelity.nil? || fidelity["classes"].nil?
382
+
383
+ output = ""
384
+ hidden_classes = fidelity["classes"]
385
+ .reduce({}) do |acc, (_class_name, class_hash)|
386
+ format_hidden_class(acc, fidelity["classes"], class_hash)
387
+ end
388
+
389
+ hidden_classes.each_key do |hidden_class_name|
390
+ output += "\nhide #{hidden_class_name}\n"
391
+ end
392
+ output
393
+ end
394
+
395
+ def fidelity_to_plantuml(fidelity)
396
+ return "" if fidelity.nil?
397
+
398
+ output = ""
399
+ output += hide_other_classes(fidelity) if fidelity["hideOtherClasses"]
400
+ output += "\nhide members\n" if fidelity["hideMembers"]
401
+ output
402
+ end
403
+
404
+ def empty?(yml, prop)
405
+ yml[prop].nil? || yml[prop].length.zero?
406
+ end
407
+ end
408
+ end
409
+ end
@@ -0,0 +1,224 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "htmlentities"
4
+ require "pathname"
5
+ require_relative "./front_contributor"
6
+
7
+ module Metanorma
8
+ module Standoc
9
+ module Front
10
+ def metadata_id(node, xml)
11
+ part, subpart = node&.attr("partnumber")&.split(/-/)
12
+ id = node.attr("docnumber") || ""
13
+ id += "-#{part}" if part
14
+ id += "-#{subpart}" if subpart
15
+ xml.docidentifier id
16
+ xml.docnumber node.attr("docnumber")
17
+ end
18
+
19
+ def metadata_other_id(node, xml)
20
+ a = node.attr("isbn") and xml.docidentifier a, type: "ISBN"
21
+ a = node.attr("isbn10") and xml.docidentifier a, type: "ISBN10"
22
+ end
23
+
24
+ def metadata_version(node, xml)
25
+ xml.edition node.attr("edition") if node.attr("edition")
26
+ xml.version do |v|
27
+ v.revision_date node.attr("revdate") if node.attr("revdate")
28
+ v.draft node.attr("draft") if node.attr("draft")
29
+ end
30
+ end
31
+
32
+ def metadata_status(node, xml)
33
+ xml.status do |s|
34
+ s.stage (node.attr("status") || node.attr("docstage") || "published")
35
+ node.attr("docsubstage") and s.substage node.attr("docsubstage")
36
+ node.attr("iteration") and s.iteration node.attr("iteration")
37
+ end
38
+ end
39
+
40
+ def metadata_committee(node, xml)
41
+ return unless node.attr("technical-committee")
42
+
43
+ xml.editorialgroup do |a|
44
+ committee_component("technical-committee", node, a)
45
+ end
46
+ end
47
+
48
+ def metadata_ics(node, xml)
49
+ ics = node.attr("library-ics")
50
+ ics&.split(/,\s*/)&.each do |i|
51
+ xml.ics { |elem| elem.code i }
52
+ end
53
+ end
54
+
55
+ def metadata_source(node, xml)
56
+ node.attr("uri") && xml.uri(node.attr("uri"))
57
+ node.attr("xml-uri") && xml.uri(node.attr("xml-uri"), type: "xml")
58
+ node.attr("html-uri") && xml.uri(node.attr("html-uri"), type: "html")
59
+ node.attr("pdf-uri") && xml.uri(node.attr("pdf-uri"), type: "pdf")
60
+ node.attr("doc-uri") && xml.uri(node.attr("doc-uri"), type: "doc")
61
+ node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"),
62
+ type: "relaton")
63
+ end
64
+
65
+ def metadata_date1(node, xml, type)
66
+ date = node.attr("#{type}-date")
67
+ date and xml.date **{ type: type } do |d|
68
+ d.on date
69
+ end
70
+ end
71
+
72
+ def datetypes
73
+ %w{ published accessed created implemented obsoleted
74
+ confirmed updated issued circulated unchanged received
75
+ vote-started vote-ended announced }
76
+ end
77
+
78
+ def metadata_date(node, xml)
79
+ datetypes.each { |t| metadata_date1(node, xml, t) }
80
+ node.attributes.each_key do |a|
81
+ next unless a == "date" || /^date_\d+$/.match(a)
82
+
83
+ type, date = node.attr(a).split(/ /, 2)
84
+ type or next
85
+ xml.date **{ type: type } do |d|
86
+ d.on date
87
+ end
88
+ end
89
+ end
90
+
91
+ def metadata_language(node, xml)
92
+ xml.language (node.attr("language") || "en")
93
+ end
94
+
95
+ def metadata_script(node, xml)
96
+ xml.script (node.attr("script") ||
97
+ Metanorma::Utils.default_script(node.attr("language")))
98
+ end
99
+
100
+ def relaton_relations
101
+ %w(part-of translated-from)
102
+ end
103
+
104
+ def relaton_relation_descriptions
105
+ {}
106
+ end
107
+
108
+ def metadata_relations(node, xml)
109
+ relaton_relations.each do |t|
110
+ metadata_getrelation(node, xml, t)
111
+ end
112
+ relaton_relation_descriptions.each do |k, v|
113
+ metadata_getrelation(node, xml, v, k)
114
+ end
115
+ end
116
+
117
+ def relation_normalise(type)
118
+ type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
119
+ .sub(/-in$/, "In")
120
+ end
121
+
122
+ def metadata_getrelation(node, xml, type, desc = nil)
123
+ docs = node.attr(desc || type) or return
124
+ HTMLEntities.new.decode(docs).split(/;\s*/).each do |d|
125
+ metadata_getrelation1(d, xml, type, desc)
126
+ end
127
+ end
128
+
129
+ def metadata_getrelation1(doc, xml, type, desc)
130
+ id = doc.split(/,\s*/)
131
+ xml.relation **{ type: relation_normalise(type) } do |r|
132
+ desc.nil? or r.description desc.gsub(/-/, " ")
133
+ fetch_ref(r, doc, nil, **{}) or r.bibitem do |b|
134
+ b.title id[1] || "--"
135
+ b.docidentifier id[0]
136
+ end
137
+ end
138
+ end
139
+
140
+ def metadata_keywords(node, xml)
141
+ return unless node.attr("keywords")
142
+
143
+ node.attr("keywords").split(/,\s*/).each do |kw|
144
+ xml.keyword kw
145
+ end
146
+ end
147
+
148
+ def metadata_classifications(node, xml)
149
+ csv_split(node.attr("classification"), ",")&.each do |c|
150
+ vals = c.split(/:/, 2)
151
+ vals.size == 1 and vals = ["default", vals[0]]
152
+ xml.classification vals[1], type: vals[0]
153
+ end
154
+ end
155
+
156
+ def metadata(node, xml)
157
+ title node, xml
158
+ metadata_source(node, xml)
159
+ metadata_id(node, xml)
160
+ metadata_other_id(node, xml)
161
+ metadata_date(node, xml)
162
+ metadata_author(node, xml)
163
+ metadata_publisher(node, xml)
164
+ metadata_version(node, xml)
165
+ metadata_note(node, xml)
166
+ metadata_language(node, xml)
167
+ metadata_script(node, xml)
168
+ metadata_status(node, xml)
169
+ metadata_copyright(node, xml)
170
+ metadata_relations(node, xml)
171
+ metadata_series(node, xml)
172
+ metadata_classifications(node, xml)
173
+ metadata_keywords(node, xml)
174
+ xml.ext do
175
+ metadata_ext(node, xml)
176
+ end
177
+ end
178
+
179
+ def metadata_ext(node, ext)
180
+ metadata_doctype(node, ext)
181
+ metadata_subdoctype(node, ext)
182
+ metadata_committee(node, ext)
183
+ metadata_ics(node, ext)
184
+ end
185
+
186
+ def metadata_doctype(node, xml)
187
+ xml.doctype doctype(node)
188
+ end
189
+
190
+ def metadata_subdoctype(node, xml)
191
+ s = node.attr("docsubtype") and xml.subdoctype s
192
+ end
193
+
194
+ def metadata_note(node, xml); end
195
+
196
+ def metadata_series(node, xml); end
197
+
198
+ def title(node, xml)
199
+ title_english(node, xml)
200
+ title_otherlangs(node, xml)
201
+ end
202
+
203
+ def title_english(node, xml)
204
+ ["en"].each do |lang|
205
+ at = { language: lang, format: "text/plain" }
206
+ xml.title **attr_code(at) do |t|
207
+ t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
208
+ node.attr("title-en")) ||
209
+ node.title)
210
+ end
211
+ end
212
+ end
213
+
214
+ def title_otherlangs(node, xml)
215
+ node.attributes.each do |k, v|
216
+ next unless /^title-(?<titlelang>.+)$/ =~ k
217
+ next if titlelang == "en"
218
+
219
+ xml.title v, { language: titlelang, format: "text/plain" }
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end