metanorma-standoc 3.1.3 → 3.1.5

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/biblio-standoc.rng +0 -49
  3. data/lib/metanorma/standoc/biblio.rng +11 -1
  4. data/lib/metanorma/standoc/blocks_notes.rb +1 -0
  5. data/lib/metanorma/standoc/cleanup.rb +4 -1
  6. data/lib/metanorma/standoc/cleanup_bibdata.rb +16 -1
  7. data/lib/metanorma/standoc/cleanup_boilerplate.rb +62 -16
  8. data/lib/metanorma/standoc/cleanup_maths.rb +2 -1
  9. data/lib/metanorma/standoc/cleanup_section_names.rb +8 -8
  10. data/lib/metanorma/standoc/converter.rb +2 -3
  11. data/lib/metanorma/standoc/front.rb +0 -8
  12. data/lib/metanorma/standoc/front_committee.rb +140 -0
  13. data/lib/metanorma/standoc/front_contributor.rb +14 -3
  14. data/lib/metanorma/standoc/front_organisation.rb +24 -18
  15. data/lib/metanorma/standoc/isodoc.rng +24 -1
  16. data/lib/metanorma/standoc/macros.rb +1 -3
  17. data/lib/metanorma/standoc/ref_queue.rb +1 -1
  18. data/lib/metanorma/standoc/ref_utility.rb +27 -2
  19. data/lib/metanorma/standoc/regex.rb +6 -5
  20. data/lib/metanorma/standoc/sectiontype.rb +1 -0
  21. data/lib/metanorma/standoc/utils.rb +11 -1
  22. data/lib/metanorma/standoc/validate.rb +1 -1
  23. data/lib/metanorma/standoc/validate_section.rb +12 -2
  24. data/lib/metanorma/standoc/validate_table.rb +3 -1
  25. data/lib/metanorma/standoc/version.rb +1 -1
  26. data/metanorma-standoc.gemspec +1 -0
  27. metadata +17 -12
  28. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +0 -3
  29. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +0 -3
  30. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +0 -8
  31. data/lib/asciidoctor/standoc/macros_plantuml.rb +0 -2
  32. data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +0 -57
  33. data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +0 -103
  34. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +0 -409
  35. data/lib/metanorma/standoc/macros_plantuml.rb +0 -143
  36. data/lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb +0 -30
  37. data/lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b781bd30313479321cf23297d77787c8500bda06c74a76028853f9b28d30510
4
- data.tar.gz: bbdf82ad80d7a6b9f1f21582d7ab6eeb58b365d4aea706a49046d74b4e6309ad
3
+ metadata.gz: 101539eb3a9ab93dced9b971970f3ff3901d7d85de59be1cac19e92495b0e9d3
4
+ data.tar.gz: f628e233575e4b13e92aeb6980fd42c9b97e05256f8e859f892fbb71643247f1
5
5
  SHA512:
6
- metadata.gz: 398ae3eaa49e8d22a4612adecf703cc4d3d7ae1b4a056f29289e5e9517be690253a1fadabf67ef1d030763992c5d97b405cc8296275df5a98eb5fc40386b93da
7
- data.tar.gz: 994a1d4820b1a68e2768ca5c189788f89a7487c1e9dd63f09178aed9c1dfd558f416a1c8521834c5e8d39b294f9a488a61778f3490e5e3aad04b10d7b5bcc386
6
+ metadata.gz: '0943020cfe1c2a7a7947f470c0443ff200cbb5ca894b8268dda16e66e8e310f810cb0c0dc64d495b544c987d14995bd5e57d69ac25e61432a3b563bf1b8f2036'
7
+ data.tar.gz: 1d68cd3ebd13e2681442a65975201ce39bdcf84eaa6f7b299345716e0b091129babaea12eb6faf5af207415af45a5d4a39cf59c362659156fcdf635f8f9b86f4
@@ -76,12 +76,6 @@ from other documents in the same doctype</a:documentation>
76
76
  <ref name="flavor">
77
77
  <a:documentation>Flavour of Metanorma used to process this document</a:documentation>
78
78
  </ref>
79
- <optional>
80
- <ref name="editorialgroup">
81
- <a:documentation>Groups associated with the production of the standards document, typically within
82
- a standards definition organization</a:documentation>
83
- </ref>
84
- </optional>
85
79
  <zeroOrMore>
86
80
  <ref name="ics">
87
81
  <a:documentation>Classification of the document contents taken from the International Classification of Standards</a:documentation>
@@ -130,49 +124,6 @@ a standards definition organization</a:documentation>
130
124
  However we prefer not to hardcode it, given ongoing extension.</a:documentation>
131
125
  <text/>
132
126
  </define>
133
- <define name="editorialgroup">
134
- <a:documentation>A group associated with the production of the standards document, typically within
135
- a standards definition organization</a:documentation>
136
- <element name="editorialgroup">
137
- <oneOrMore>
138
- <ref name="technical-committee">
139
- <a:documentation>A technical committee associated with the production of the standards document</a:documentation>
140
- </ref>
141
- </oneOrMore>
142
- </element>
143
- </define>
144
- <define name="technical-committee">
145
- <a:documentation>Technical committee associated with the production of a standards document</a:documentation>
146
- <element name="technical-committee">
147
- <ref name="IsoWorkgroup"/>
148
- </element>
149
- </define>
150
- <define name="IsoWorkgroup">
151
- <optional>
152
- <attribute name="number">
153
- <a:documentation>Numeric identifier of the technical committee</a:documentation>
154
- </attribute>
155
- </optional>
156
- <optional>
157
- <attribute name="type">
158
- <a:documentation>Type of the technical committee, used in identifying the technical committee</a:documentation>
159
- </attribute>
160
- </optional>
161
- <optional>
162
- <attribute name="identifier">
163
- <a:documentation>Non-numeric, complete identifier of the technical committee</a:documentation>
164
- </attribute>
165
- </optional>
166
- <optional>
167
- <attribute name="prefix">
168
- <a:documentation>Disambiguating prefix added to number to form the identifier of the technical committee,
169
- typically indicating its type</a:documentation>
170
- </attribute>
171
- </optional>
172
- <text>
173
- <a:documentation>Name of the technical committee</a:documentation>
174
- </text>
175
- </define>
176
127
  <define name="ics">
177
128
  <a:documentation>Classification taken from the International Classification of Standards.
178
129
  ICS is defined by ISO here -- https://www.iso.org/publication/PUB100033.html</a:documentation>
@@ -242,6 +242,8 @@ Detailed in https://www.relaton.org/model/creator/</a:documentation>
242
242
  </choice>
243
243
  </define>
244
244
  <define name="roledescription">
245
+ <a:documentation>A more detailed description of the role of the contributor
246
+ Some descriptions are reserved words; in particular, the editorial committee of a standard has the role description "committee"</a:documentation>
245
247
  <element name="description">
246
248
  <ref name="LocalizedMarkedUpString"/>
247
249
  </element>
@@ -443,7 +445,10 @@ real names (if the person is named with a pseudonym or user name); previous lega
443
445
  </oneOrMore>
444
446
  <zeroOrMore>
445
447
  <ref name="subdivision">
446
- <a:documentation>The subdivision of the organization directly involved with the production of the bibliographic item</a:documentation>
448
+ <a:documentation>The subdivision of the organization directly involved with the production of the bibliographic item.
449
+ Multiple subdivisions can be specified for an organization, with no implication of hierarchical
450
+ relation between them
451
+ Editorial and advisory groups are represented as consecutive subdivisions of the SDO</a:documentation>
447
452
  </ref>
448
453
  </zeroOrMore>
449
454
  <optional>
@@ -485,6 +490,11 @@ real names (if the person is named with a pseudonym or user name); previous lega
485
490
  <a:documentation>The type of subdivision</a:documentation>
486
491
  </attribute>
487
492
  </optional>
493
+ <optional>
494
+ <attribute name="subtype">
495
+ <a:documentation>The subtype of subdivision; e.g. different types of technical committee</a:documentation>
496
+ </attribute>
497
+ </optional>
488
498
  <ref name="OrganizationType">
489
499
  <a:documentation>The subdivision, modelled recursively as an organization</a:documentation>
490
500
  </ref>
@@ -6,6 +6,7 @@ module Metanorma
6
6
  .merge(
7
7
  "keep-separate": node.attr("keep-separate"),
8
8
  keepasterm: node.option?("termnote") ? "true" : nil,
9
+ type: node.attr("type")
9
10
  )))
10
11
  end
11
12
 
@@ -33,7 +33,8 @@ module Metanorma
33
33
  passthrough_cleanup(xmldoc) # feeds: smartquotes_cleanup
34
34
  unnumbered_blocks_cleanup(xmldoc)
35
35
  termdocsource_cleanup(xmldoc) # feeds: metadata_cleanup
36
- metadata_cleanup(xmldoc) # feeds: boilerplate_cleanup
36
+ metadata_cleanup(xmldoc) # feeds: boilerplate_cleanup, bibdata_cleanup,
37
+ # docidentifier_cleanup (in generic: template)
37
38
  misccontainer_cleanup(xmldoc)
38
39
  sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup,
39
40
  # floatingtitle_cleanup
@@ -202,6 +203,8 @@ module Metanorma
202
203
  end
203
204
 
204
205
  def metadata_cleanup(xmldoc)
206
+ bibdata_published(xmldoc) # feeds: bibdata_cleanup,
207
+ # docidentifier_cleanup (in generic: template)
205
208
  (@metadata_attrs.nil? || @metadata_attrs.empty?) and return
206
209
  ins = add_misc_container(xmldoc)
207
210
  ins << @metadata_attrs
@@ -59,7 +59,7 @@ module Metanorma
59
59
  end
60
60
  end
61
61
 
62
- def indirect_eref_to_xref(eref, ident, id_map=nil)
62
+ def indirect_eref_to_xref(eref, ident, id_map = nil)
63
63
  loc = eref.at("./localityStack[locality[@type = 'anchor']]") ||
64
64
  eref.at("./locality[@type = 'anchor']")
65
65
  loc = loc&.remove&.text || ident
@@ -72,6 +72,7 @@ module Metanorma
72
72
  else
73
73
  eref.document.at("//*[@anchor = '#{loc}']") and return
74
74
  end
75
+
75
76
  eref.children = %(** Missing target #{loc})
76
77
  eref["target"] = ident
77
78
  end
@@ -181,6 +182,20 @@ module Metanorma
181
182
  ins.next = c
182
183
  end
183
184
  end
185
+
186
+ def bibdata_published(xmldoc)
187
+ ins = add_misc_container(xmldoc)
188
+ ins ||= add_misc_container(xmldoc)
189
+ ins.at("./semantic-metadata/stage-published") and return
190
+ p = published?(xmldoc.at("bibdata/status/stage")&.text, xmldoc)
191
+ ins << <<~XML
192
+ <semantic-metadata><stage-published>#{p}</stage-published></semantic-metadata>
193
+ XML
194
+ end
195
+
196
+ def published?(stage, _xmldoc)
197
+ stage.casecmp("published").zero?
198
+ end
184
199
  end
185
200
  end
186
201
  end
@@ -162,25 +162,64 @@ module Metanorma
162
162
  end
163
163
  end
164
164
 
165
- # Asciidoc macro, e.g. span:publisher[...]
166
- # May contain one or more {{ }} in target, with spaces in them
167
- # Does not end in \]
168
- ADOC_MACRO_START =
169
- '\S+:(?:[^\[\] ]+|\{\{[^{}]+\}\})*\[.*?(?<!\\\\)\]'.freeze
170
-
171
- # Replace {{ ... }} with {{ pass:[...]}} to preserve any XML markup
172
- # use pass:[...\] if {{}} is already inside an Asciidoc macro
173
- # Do not use pass: if this is a macro target: mailto:{{x}}[]
174
- # or body: mailto:[{{x}}]
165
+ # The boilerplate file is in Liquid AsciiDoc format
166
+ # (technically, `boilerplate.adoc.liquid`).
167
+ #
168
+ # This file is processed separately from the main Metanorma document and
169
+ # therefore is oblivious of the `{{ concept-mention }}` syntax.
170
+ #
171
+ # Due to historic reasons, the Liquid objects being evaluated in the
172
+ # boilerplate document are XML strings. Notably these are the document
173
+ # metadata, that are extracted from the already generated Metanorma XML.
174
+ #
175
+ # These XML strings are then passed into the AsciiDoc macros such as
176
+ # `span:publisher[...]`.
177
+ #
178
+ # Here, we need to interpolate the XML strings into the AsciiDoc macros
179
+ # without breaking the AsciiDoc syntax.
180
+ #
181
+ # EXAMPLE 1: `mailto:{{ pub_email }}[]`, we need to
182
+ # convert it to:
183
+ # `mailto:{{ pass-format:metanorma[++pub_email_xml++] }}[]`
184
+ #
185
+ # EXAMPLE 2: `link:{{ pub_uri}}[{{ pub_address }}, {{ pub_uri }}]`
186
+ # We need to convert it to:
187
+ # `link:{{ pass-format:metanorma[++pub_uri_xml++] }}[{{
188
+ # pass-format:metanorma[++pub_address_xml++] }}, {{
189
+ # pass-format:metanorma[++pub_uri_xml++] }}]`
190
+ #
191
+ # NOTE: The boilerplate may use macros that contain one or more
192
+ # `{{ ... }}` in the target, and can contain spaces in them.
193
+ #
194
+ # NOTE: The routine needs to handle cases where the content
195
+ # contains an escaped closing bracket `\]`.
196
+
197
+ ADOC_MACRO_PATTERN = /\S+:[^\[\n]*\[[^\]\\]*(?:\\.[^\]\\]*)*\]/
198
+
199
+ # Replace {{ ... }} with {{ pass-format:metanorma:[...] }} to preserve any
200
+ # XML markup provided by Metanorma XML Metadata content, through the
201
+ # `pass-format:metanorma` command.
202
+ #
203
+ # * If `{{ ... }}` is inside an Asciidoc macro, we have to wrap with
204
+ # pass-format:metanorma:[...\].
205
+ # * If this is a macro target (e.g. `mailto:{{x}}[]`, body: mailto:[{{x}}])
206
+ # then do not use pass-format:metanorma.
207
+
175
208
  def boilerplate_read(file)
176
209
  ret = File.read(file, encoding: "UTF-8")
177
- /\.adoc$/.match?(file) or return ret
178
- ret.split(/(#{ADOC_MACRO_START}|\])/o).map do |r|
179
- if /^#{ADOC_MACRO_START}$/o.match?(r)
180
- r
210
+ /\.adoc(\.liquid)?$/.match?(file) or return ret
211
+
212
+ # Split content into macro and non-macro parts
213
+ parts = ret.split(/(#{ADOC_MACRO_PATTERN})/)
214
+
215
+ parts.map.with_index do |part, index|
216
+ if index.odd? && is_valid_macro?(part)
217
+ # This is a macro - leave unchanged
218
+ part
181
219
  else
182
- r.gsub(/(?<!\{)(\{\{[^{}]+\}\})(?!\})/,
183
- "pass-format:metanorma[++\\1++]")
220
+ # Not a macro - wrap {{ }} patterns
221
+ part.gsub(/(?<!\{)(\{\{[^{}]+\}\})(?!\})/,
222
+ "pass-format:metanorma[++\\1++]")
184
223
  end
185
224
  end.join
186
225
  end
@@ -199,6 +238,13 @@ module Metanorma
199
238
  ret
200
239
  end
201
240
 
241
+ private
242
+
243
+ def is_valid_macro?(text)
244
+ # Simple validation - does it look like a macro?
245
+ text.match?(/^\S+:[^\[]*\[.*\]$/)
246
+ end
247
+
202
248
  # remove Metanorma namespace, so generated doc containing boilerplate
203
249
  # can be queried consistently
204
250
  # _\d+ anchor is assigned to titleless clauses, will clash with main doc
@@ -96,7 +96,8 @@ module Metanorma
96
96
 
97
97
  def add_misc_container(xmldoc)
98
98
  unless ins = xmldoc.at("//metanorma-extension")
99
- a = xmldoc.xpath("//termdocsource")&.last || xmldoc.at("//bibdata")
99
+ a = xmldoc.xpath("//termdocsource")&.last || xmldoc.at("//bibdata") ||
100
+ xmldoc.root.children.first
100
101
  a.next = "<metanorma-extension/>"
101
102
  ins = xmldoc.at("//metanorma-extension")
102
103
  end
@@ -51,9 +51,9 @@ module Metanorma
51
51
  NO_SYMABBR = "[.//definitions[not(@type)]]".freeze
52
52
  SYMABBR = "[.//definitions[@type = 'symbols']]" \
53
53
  "[.//definitions[@type = 'abbreviated_terms']]".freeze
54
- SYMnoABBR = "[.//definitions[@type = 'symbols']]" \
54
+ SYM_NO_ABBR = "[.//definitions[@type = 'symbols']]" \
55
55
  "[not(.//definitions[@type = 'abbreviated_terms'])]".freeze
56
- ABBRnoSYM = "[.//definitions[@type = 'abbreviated_terms']]" \
56
+ ABBR_NO_SYM = "[.//definitions[@type = 'abbreviated_terms']]" \
57
57
  "[not(.//definitions[@type = 'symbols'])]".freeze
58
58
 
59
59
  def section_names_terms_cleanup(xml)
@@ -81,9 +81,9 @@ module Metanorma
81
81
 
82
82
  def section_names_terms1_cleanup(xml)
83
83
  auto_name_terms(xml) or return
84
- replace_title(xml, "//terms#{SYMnoABBR} | //clause[@type = 'terms']#{SYMnoABBR}",
84
+ replace_title(xml, "//terms#{SYM_NO_ABBR} | //clause[@type = 'terms']#{SYM_NO_ABBR}",
85
85
  @i18n&.termsdefsymbols, true)
86
- replace_title(xml, "//terms#{ABBRnoSYM} | //clause[@type = 'terms']#{ABBRnoSYM}",
86
+ replace_title(xml, "//terms#{ABBR_NO_SYM} | //clause[@type = 'terms']#{ABBR_NO_SYM}",
87
87
  @i18n&.termsdefabbrev, true)
88
88
  replace_title(xml, "//terms#{SYMABBR} | //clause[@type = 'terms']#{SYMABBR}",
89
89
  @i18n&.termsdefsymbolsabbrev, true)
@@ -124,12 +124,12 @@ module Metanorma
124
124
  unless acc[:parent] == :term # don't count Term > Term twice
125
125
  :term
126
126
  end
127
- elsif hasterm && node.at("./self::*#{SYMnoABBR}") then :tsna
128
- elsif hasterm && node.at("./self::*#{ABBRnoSYM}") then :tans
127
+ elsif hasterm && node.at("./self::*#{SYM_NO_ABBR}") then :tsna
128
+ elsif hasterm && node.at("./self::*#{ABBR_NO_SYM}") then :tans
129
129
  elsif hasterm && node.at("./self::*#{SYMABBR}") then :tsa
130
130
  elsif hasterm && node.at("./self::*#{NO_SYMABBR}") then :tnsa
131
- elsif node.at("./self::*#{SYMnoABBR}") then :sna
132
- elsif node.at("./self::*#{ABBRnoSYM}") then :ans
131
+ elsif node.at("./self::*#{SYM_NO_ABBR}") then :sna
132
+ elsif node.at("./self::*#{ABBR_NO_SYM}") then :ans
133
133
  elsif node.at("./self::*#{SYMABBR}") then :sa
134
134
  elsif node.at("./self::*#{NO_SYMABBR}") then :nsa
135
135
  elsif node.name == "definitions" # ignore
@@ -33,11 +33,11 @@ module Metanorma
33
33
  block_macro Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlockMacro
34
34
  block Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlock
35
35
  block_macro Metanorma::Plugin::Lutaml::LutamlKlassTableBlockMacro
36
+ block_macro Metanorma::Plugin::Lutaml::LutamlEnumTableBlockMacro
37
+ block Metanorma::Plugin::Plantuml::BlockProcessor
36
38
  preprocessor Metanorma::Standoc::EmbedIncludeProcessor
37
39
  preprocessor Metanorma::Standoc::LinkProtectPreprocessor
38
40
  preprocessor Metanorma::Standoc::PassProtectPreprocessor
39
- preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
40
- preprocessor Metanorma::Standoc::Datamodel::DiagramPreprocessor
41
41
  preprocessor Metanorma::Plugin::Lutaml::Json2TextPreprocessor
42
42
  preprocessor Metanorma::Plugin::Lutaml::Yaml2TextPreprocessor
43
43
  preprocessor Metanorma::Plugin::Lutaml::Data2TextPreprocessor
@@ -80,7 +80,6 @@ module Metanorma
80
80
  inline_macro Metanorma::Standoc::SourceIncludeInlineMacro
81
81
  block Metanorma::Standoc::ToDoAdmonitionBlock
82
82
  block Metanorma::Standoc::EditorAdmonitionBlock
83
- block Metanorma::Standoc::PlantUMLBlockMacro
84
83
  block Metanorma::Standoc::PseudocodeBlockMacro
85
84
  block_macro Metanorma::Standoc::ColumnBreakBlockMacro
86
85
  end
@@ -53,13 +53,6 @@ module Metanorma
53
53
  end
54
54
  end
55
55
 
56
- def metadata_committee(node, xml)
57
- node.attr("technical-committee") or return
58
- xml.editorialgroup do |a|
59
- committee_component("technical-committee", node, a)
60
- end
61
- end
62
-
63
56
  def metadata_ics(node, xml)
64
57
  ics = node.attr("library-ics")
65
58
  ics&.split(/,\s*/)&.each do |i|
@@ -194,7 +187,6 @@ module Metanorma
194
187
  metadata_doctype(node, ext)
195
188
  metadata_subdoctype(node, ext)
196
189
  metadata_flavor(node, ext)
197
- metadata_committee(node, ext)
198
190
  metadata_ics(node, ext)
199
191
  structured_id(node, ext)
200
192
  metadata_coverpage_images(node, ext)
@@ -0,0 +1,140 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Front
4
+ def committee_number_or_name?(node, type, suffix)
5
+ node.attr("#{type}-number#{suffix}") || node.attr("#{type}#{suffix}")
6
+ end
7
+
8
+ def committee_contributors(node, xml, agency, _opts)
9
+ t = metadata_committee_types(node)
10
+ v = t.first
11
+ if committee_number_or_name?(node, v, "")
12
+ node.attr(v) or node.set_attr(v, "")
13
+ o = committee_contrib_org_prep(node, v, agency, _opts)
14
+ o[:groups] = t
15
+ org_contributor(node, xml, o)
16
+ end
17
+ end
18
+
19
+ def metadata_committee_types(_node)
20
+ %w(technical-committee)
21
+ end
22
+
23
+ def committee_contrib_org_prep(node, type, agency, _opts)
24
+ agency_arr, agency_abbrev =
25
+ committee_org_prep_agency(node, type, agency, [], [])
26
+ { source: [type], role: "author", desc: "committee",
27
+ default_org: false, committee: true,
28
+ agency: agency_arr, agency_abbrev:,
29
+ subdivtype: type.sub(/^approval-/, "").tr("-", " ").capitalize }.compact
30
+ end
31
+
32
+ def committee_org_prep_agency(node, type, agency, agency_arr, agency_abbr)
33
+ i = 1
34
+ suffix = ""
35
+ while committee_number_or_name?(node, type, suffix)
36
+ agency_arr << (node.attr("#{type}-agency#{suffix}") || agency)
37
+ agency_abbr << node.attr("#{type}-agency-abbr#{suffix}")
38
+ i += 1
39
+ suffix = "_#{i}"
40
+ end
41
+ [agency_arr, agency_abbr]
42
+ end
43
+
44
+ def contrib_committee_build(xml, agency, committee)
45
+ if name = org_abbrev.invert[agency]
46
+ committee[:agency_abbrev] = agency
47
+ agency = name
48
+ end
49
+ xml.name agency
50
+ s = committee
51
+ loop do
52
+ contrib_committee_subdiv(xml, s)
53
+ s = s[:subdiv] or break
54
+ end
55
+ abbr = committee[:agency_abbrev] and xml.abbreviation abbr
56
+ full_committee_id(xml.parent)
57
+ end
58
+
59
+ def contrib_committee_subdiv(xml, committee)
60
+ contributors_committees_filter_empty?(committee) and return
61
+ xml.subdivision **attr_code(type: committee[:subdivtype],
62
+ subtype: committee[:type]) do |o|
63
+ o.name committee[:name]
64
+ committee[:abbr] and o.abbreviation committee[:abbr]
65
+ committee[:ident] and o.identifier committee[:ident]
66
+ end
67
+ end
68
+
69
+ def full_committee_id(contrib)
70
+ ret = full_committee_agency_id(contrib)
71
+ ids = contrib.xpath("./subdivision").map do |x|
72
+ x.at("./identifier")&.text
73
+ end.compact
74
+ ins = contrib.at("./subdivision/identifier") and
75
+ ins.next = "<identifier type='full'>#{ret}#{ids.join('/')}</identifier>"
76
+ end
77
+
78
+ def full_committee_agency_id(contrib)
79
+ agency = contrib.at("./abbreviation")&.text
80
+ ret = agency == default_publisher ? "" : "#{agency} "
81
+ /^\s+/.match?(ret) and ret = ""
82
+ ret
83
+ end
84
+
85
+ def org_attrs_parse(node, opts)
86
+ opts_orig = opts.dup
87
+ ret = []
88
+ ret << org_attrs_parse_core(node, opts)&.map&.with_index do |x, i|
89
+ x.merge(agency: opts.dig(:agency, i), subdivtype: opts[:subdivtype],
90
+ agency_abbrev: opts.dig(:agency_abbrev, i), abbr: opts[:abbr],
91
+ committee: opts[:committee], default_org: opts[:default_org])
92
+ end
93
+ if !opts_orig[:groups] || opts_orig[:groups].empty? then ret.first
94
+ else org_attrs_add_committees(node, ret, opts, opts_orig)
95
+ end
96
+ end
97
+
98
+ def org_attrs_add_committees(node, ret, opts, opts_orig)
99
+ opts_orig[:groups].each_with_index do |g, i|
100
+ i.zero? and next
101
+ contributors_committees_pad_multiples(ret.first, node, g)
102
+ opts = committee_contrib_org_prep(node, g, nil, opts_orig)
103
+ ret << org_attrs_parse_core(node, opts).map do |x|
104
+ x.merge(subdivtype: opts[:subdivtype])
105
+ end
106
+ end
107
+ contributors_committees_nest1(ret)
108
+ end
109
+
110
+ # ensure there is subcommittee, workgroup -number_2, -number_3 etc
111
+ # to parse multiple tech committees
112
+ def contributors_committees_pad_multiples(committees, node, group)
113
+ committees.each_with_index do |_r, j|
114
+ suffix = j.zero? ? "" : "_#{j + 1}"
115
+ node.attr("#{group}#{suffix}") or
116
+ node.set_attr("#{group}#{suffix}", "")
117
+ node.attr("#{group}-number#{suffix}") or
118
+ node.set_attr("#{group}-number#{suffix}", "")
119
+ end
120
+ end
121
+
122
+ def contributors_committees_filter_empty?(committee)
123
+ (committee[:name].nil? || committee[:name].empty?) &&
124
+ committee[:ident].nil?
125
+ end
126
+
127
+ def contributors_committees_nest1(committees)
128
+ committees.empty? and return committees
129
+ committees = committees.reverse
130
+ committees.each_with_index do |m, i|
131
+ i.zero? and next
132
+ m.each_with_index do |m1, j|
133
+ m1[:subdiv] = committees[i - 1][j]
134
+ end
135
+ end
136
+ committees[-1]
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,13 +1,24 @@
1
1
  require_relative "./front_organisation"
2
+ require_relative "./front_committee"
2
3
 
3
4
  module Metanorma
4
5
  module Standoc
5
6
  module Front
6
7
  def metadata_author(node, xml)
7
- org_contributor(node, xml,
8
- { source: ["publisher", "pub"], role: "author",
9
- default: default_publisher })
8
+ org_author(node, xml)
10
9
  personal_author(node, xml)
10
+ committee_contributors(node, xml, default_publisher, {})
11
+ end
12
+
13
+ def org_author(node, xml)
14
+ if node.attr("corporate-author")
15
+ org_contributor(node, xml, { source: ["corporate-author"],
16
+ role: "author" })
17
+ else
18
+ org_contributor(node, xml,
19
+ { source: ["publisher", "pub"], role: "author",
20
+ default: default_publisher })
21
+ end
11
22
  end
12
23
 
13
24
  def personal_author(node, xml)
@@ -1,18 +1,6 @@
1
1
  module Metanorma
2
2
  module Standoc
3
3
  module Front
4
- def committee_component(compname, node, out)
5
- i = 1
6
- suffix = ""
7
- while node.attr(compname + suffix)
8
- out.send compname.gsub(/-/, "_"), node.attr(compname + suffix),
9
- **attr_code(number: node.attr("#{compname}-number#{suffix}"),
10
- type: node.attr("#{compname}-type#{suffix}"))
11
- i += 1
12
- suffix = "_#{i}"
13
- end
14
- end
15
-
16
4
  def organization(org, orgname, node = nil, default_org = nil, attrs = {})
17
5
  orgname, abbr = org_name_and_abbrev(attrs, orgname)
18
6
  org.name orgname
@@ -147,12 +135,16 @@ module Metanorma
147
135
  end
148
136
 
149
137
  def org_organization(node, xml, org)
150
- organization(xml, org[:name], node, !node.attr("publisher"), org)
151
- org_address(org, xml)
152
- org_logo(xml, org[:logo])
138
+ if org[:committee]
139
+ contrib_committee_build(xml, org[:agency], org)
140
+ else
141
+ organization(xml, org[:name], node, !node.attr("publisher"), org)
142
+ org_address(org, xml)
143
+ org_logo(xml, org[:logo])
144
+ end
153
145
  end
154
146
 
155
- def org_attrs_parse(node, opts)
147
+ def org_attrs_parse_core(node, opts)
156
148
  source = opts[:source]&.detect { |s| node.attr(s) }
157
149
  org_attrs_simple_parse(node, opts, source) ||
158
150
  org_attrs_complex_parse(node, opts, source)
@@ -178,7 +170,7 @@ module Metanorma
178
170
  i = 1
179
171
  suffix = ""
180
172
  ret = []
181
- while node.attr(source + suffix)
173
+ while committee_number_or_name?(node, source, suffix)
182
174
  ret << extract_org_attrs_complex(node, opts, source, suffix)
183
175
  i += 1
184
176
  suffix = "_#{i}"
@@ -187,14 +179,28 @@ module Metanorma
187
179
  end
188
180
 
189
181
  def extract_org_attrs_complex(node, opts, source, suffix)
190
- { name: node.attr(source + suffix),
182
+ n = node.attr("#{source}-number#{suffix}") # for committees
183
+ t = committee_ident(node.attr("#{source}-type#{suffix}"), n, source)
184
+ { name: node.attr(source + suffix), ident: t,
191
185
  abbrev: node.attr("#{source}_abbr#{suffix}"),
192
186
  role: opts[:role], desc: opts[:desc],
187
+ type: node.attr("#{source}-type#{suffix}"),
193
188
  subdiv: node.attr("#{source}_subdivision#{suffix}"),
194
189
  logo: node.attr("#{source}_logo#{suffix}") }.compact
195
190
  .merge(extract_org_attrs_address(node, opts, suffix))
196
191
  end
197
192
 
193
+ def committee_abbrevs
194
+ { "technical-committee" => "TC" }
195
+ end
196
+
197
+ def committee_ident(type, number, level)
198
+ number.nil? || number.empty? and return
199
+ type ||= committee_abbrevs[level]
200
+ type == "Other" and type = ""
201
+ "#{type} #{number}".strip
202
+ end
203
+
198
204
  def extract_org_attrs_address(node, opts, suffix)
199
205
  %w(address phone fax email uri).each_with_object({}) do |a, m|
200
206
  opts[:source]&.each do |s|