metanorma-generic 3.0.3 → 3.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84ebc0f57d2adc50481a82940e80e0d2f89972c088df6677744719d717f6495b
4
- data.tar.gz: 6e8b384f78ec51468642c1dd0d308a56f5e7f326927a58a0e8ed48800b3d2289
3
+ metadata.gz: e884aa729dddf661d330c4788cd464554e00ff09c8666e9a86cd96c8da9b627f
4
+ data.tar.gz: 8502e2a0f09b31126952b0d16e4d919bac0c072806242476365ebb212bfcdba7
5
5
  SHA512:
6
- metadata.gz: 8f54dde566062f0f1e52dc32764f5dbd288d092acf366ae2279cf74c52b76a584329efd5e6bb666bac4f54e5f7b15c1d70a268c600904ac37d68d35442f6a5dd
7
- data.tar.gz: cc4d7755a5eae79d1150e45cae14a87086df65609217fd015e9c2901c8142223c124f2f4512a41eb2bed6ba42a1b081d09126b17785d155e05f73a528418d224
6
+ metadata.gz: 189f3cb40d41e8e6b0e060baeb47deda8ea4e7eb7db97324f9c85f1d2f930e7f7061c03ee3c2d9827c0d0b95d574a9bc0b86f0e39a9d9f72a8ed0bf901a39707
7
+ data.tar.gz: 858646781e6f509702a268736a79b7663f47b346adf0cb99b66dc0863542882bdf5cc867ecc827a3be2ccfb42b00e1799dfcccb5438c08a10dbfb1a42088ef1c
@@ -198,14 +198,14 @@ Applicable to modify and delete</a:documentation>
198
198
  </zeroOrMore>
199
199
  </element>
200
200
  </optional>
201
- <optional>
201
+ <zeroOrMore>
202
202
  <element name="description">
203
- <a:documentation>Description of the change described in this block</a:documentation>
204
- <zeroOrMore>
203
+ <a:documentation>Description(s) of the change described in this block</a:documentation>
204
+ <oneOrMore>
205
205
  <ref name="BasicBlock"/>
206
- </zeroOrMore>
206
+ </oneOrMore>
207
207
  </element>
208
- </optional>
208
+ </zeroOrMore>
209
209
  <optional>
210
210
  <element name="newcontent">
211
211
  <a:documentation>New content to be added to the document; applicable to add and modify</a:documentation>
@@ -0,0 +1,24 @@
1
+ module Metanorma
2
+ module Generic
3
+ class BibdataConfig < ::Lutaml::Model::Serializable
4
+ class Bibdata < ::Lutaml::Model::Serializable
5
+ model ::RelatonBib::BibliographicItem
6
+ end
7
+
8
+ attribute :bibdata, Bibdata
9
+
10
+ xml do
11
+ root "metanorma"
12
+ map_element "bibdata", to: :bibdata, with: { from: :bibdata_from_xml,
13
+ to: :bibdata_to_xml }
14
+ end
15
+
16
+ def bibdata_from_xml(model, node)
17
+ node or return
18
+ model.bibdata = Relaton::Cli.parse_xml(node.adapter_node)
19
+ end
20
+
21
+ def bibdata_to_xml(model, parent, doc); end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,7 @@ require "asciidoctor"
2
2
  require "metanorma/standoc/converter"
3
3
  require "fileutils"
4
4
  require_relative "front"
5
+ require_relative "bibdata_config"
5
6
  require "metanorma"
6
7
  require "pathname"
7
8
 
@@ -16,23 +17,25 @@ module Metanorma
16
17
  end
17
18
 
18
19
  def docidentifier_cleanup(xmldoc)
20
+ docid = xmldoc.at("//bibdata/docidentifier") or return
21
+ docid.text.empty? or return
22
+ id = docidentifier_from_template(xmldoc) or return
23
+ (id.empty? and docid.remove) or docid.children = id
24
+ end
25
+
26
+ def docidentifier_from_template(xmldoc)
19
27
  b = boilerplate_isodoc(xmldoc) or return
20
28
  template = configuration.docid_template ||
21
29
  "{{ organization_name_short }} {{ docnumeric }}"
22
- docid = xmldoc.at("//bibdata/docidentifier")
23
- docid&.text&.empty? or return
24
- id = b.populate_template(template, nil)
25
- (id.empty? and docid.remove) or docid.children = id
30
+ b.populate_template(template, nil)
26
31
  end
27
32
 
28
33
  def doctype(node)
29
34
  d = super
30
35
  node.attr("doctype") == "article" and d = "article"
31
36
  a = configuration.default_doctype and @default_doctype = a
32
- unless configuration.doctypes
33
- d == "article" and return @default_doctype
34
- return d
35
- end
37
+ configuration.doctypes or
38
+ return d == "article" ? @default_doctype : d
36
39
  type = @default_doctype || configuration.doctypes.keys[0]
37
40
  if !configuration.doctypes.key?(d)
38
41
  node.attr("doctype") && node.attr("doctype") != "article" and # factory default
@@ -162,9 +165,16 @@ module Metanorma
162
165
  Metanorma::Generic::Configuration::CONFIG_ATTRS.each do |a|
163
166
  conv.meta.set(a, configuration.send(a))
164
167
  end
168
+ conv.meta.set(:bibdata, bibdata_hash(xmldoc))
165
169
  conv
166
170
  end
167
171
 
172
+ def bibdata_hash(xmldoc)
173
+ b = xmldoc.at("//bibdata") || xmldoc.at("//xmlns:bibdata")
174
+ BibdataConfig.from_xml("<metanorma>#{b.to_xml}</metanorma>")
175
+ .bibdata.to_hash
176
+ end
177
+
168
178
  def boilerplate_file(xmldoc)
169
179
  f = configuration.boilerplate
170
180
  f.nil? and return super
@@ -172,18 +182,6 @@ module Metanorma
172
182
  f.is_a? Hash and f[@lang] and return baselocation(f[@lang])
173
183
  super
174
184
  end
175
-
176
- def cleanup(xmldoc)
177
- super
178
- empty_metadata_cleanup(xmldoc)
179
- xmldoc
180
- end
181
-
182
- def empty_metadata_cleanup(xmldoc)
183
- xmldoc.xpath("//bibdata/ext//*").each do |x|
184
- x.remove if x.children.empty?
185
- end
186
- end
187
185
  end
188
186
  end
189
187
  end
@@ -60,6 +60,22 @@ module Metanorma
60
60
  a = node.attr(e) and ext.send e, a
61
61
  end
62
62
  end
63
+ empty_metadata_cleanup(ext.parent)
64
+ end
65
+
66
+ # Keep cleaning until no more elements are removed (recursive depth-first)
67
+ # Process elements in reverse doc order to handle nested removals properly
68
+ def empty_metadata_cleanup(ext)
69
+ loop do
70
+ removed_count = 0
71
+ ext.xpath(".//*").reverse_each do |element|
72
+ element.children.empty? && element.attributes.empty? or next
73
+ element.remove
74
+ removed_count += 1
75
+ end
76
+ removed_count.zero? and break # Stop when no elems removed this pass
77
+
78
+ end
63
79
  end
64
80
 
65
81
  def metadata_doctype(node, xml)
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
- <!-- VERSION v2.0.6 -->
3
+ <!-- VERSION v2.1.0 -->
4
4
 
5
5
  <!--
6
6
  ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437
@@ -72,10 +72,51 @@ but to `@anchor`, the user-supplied cross-reference</a:documentation>
72
72
  </oneOrMore>
73
73
  </element>
74
74
  </define>
75
+ <define name="review">
76
+ <a:documentation>Generalise BasicDoc element from just review comments, to general annotations;
77
+ the type attribute defaults to `review` for reviews</a:documentation>
78
+ <element name="annotation">
79
+ <ref name="RequiredId"/>
80
+ <ref name="ReviewAttributes"/>
81
+ <oneOrMore>
82
+ <ref name="paragraph">
83
+ <a:documentation>Reviewer comments content</a:documentation>
84
+ </ref>
85
+ </oneOrMore>
86
+ </element>
87
+ </define>
88
+ <define name="ruby_pronunciation">
89
+ <a:documentation>Ruby annotation giving pronunciation of text: change tag from BasicDoc for disambiguation</a:documentation>
90
+ <element name="ruby-pronunciation">
91
+ <attribute name="value">
92
+ <a:documentation>Ruby annotation value</a:documentation>
93
+ </attribute>
94
+ <ref name="LocalizedStringAttributes"/>
95
+ </element>
96
+ </define>
97
+ <define name="ruby_annotation">
98
+ <a:documentation>Ruby annotation giving information other than pronunciation of text: change tag from BasicDoc for disambiguation</a:documentation>
99
+ <element name="ruby-annotation">
100
+ <attribute name="value">
101
+ <a:documentation>Ruby annotation value</a:documentation>
102
+ </attribute>
103
+ <ref name="LocalizedStringAttributes"/>
104
+ </element>
105
+ </define>
106
+ <define name="annotation">
107
+ <a:documentation>Source code annotation, corresponding to a callout</a:documentation>
108
+ <element name="callout-annotation">
109
+ <ref name="RequiredId"/>
110
+ <oneOrMore>
111
+ <ref name="paragraph"/>
112
+ </oneOrMore>
113
+ </element>
114
+ </define>
75
115
  <define name="section-title">
76
116
  <a:documentation>Title(s) of a clause</a:documentation>
77
117
  <element name="title">
78
118
  <a:documentation>Title proper for a clause</a:documentation>
119
+ <ref name="RequiredId"/>
79
120
  <zeroOrMore>
80
121
  <ref name="TextElement"/>
81
122
  </zeroOrMore>
@@ -83,10 +124,19 @@ but to `@anchor`, the user-supplied cross-reference</a:documentation>
83
124
  <zeroOrMore>
84
125
  <element name="variant-title">
85
126
  <a:documentation>Alternate title for a clause</a:documentation>
127
+ <ref name="RequiredId"/>
86
128
  <ref name="TypedTitleString"/>
87
129
  </element>
88
130
  </zeroOrMore>
89
131
  </define>
132
+ <define name="tname">
133
+ <element name="name">
134
+ <ref name="RequiredId"/>
135
+ <oneOrMore>
136
+ <ref name="NestedTextElement"/>
137
+ </oneOrMore>
138
+ </element>
139
+ </define>
90
140
  <define name="UlBody">
91
141
  <optional>
92
142
  <ref name="tname">
@@ -475,6 +525,7 @@ normative or informative references, some split references into sections organiz
475
525
  <!-- exclude figures? -->
476
526
  <define name="dd">
477
527
  <element name="dd">
528
+ <ref name="OptionalId"/>
478
529
  <zeroOrMore>
479
530
  <!-- exclude figures? -->
480
531
  <ref name="BasicBlock"/>
@@ -526,9 +577,10 @@ normative or informative references, some split references into sections organiz
526
577
  </choice>
527
578
  </define>
528
579
  <define name="TrAttributes">
580
+ <ref name="OptionalId"/>
529
581
  <optional>
530
582
  <attribute name="style">
531
- <a:documentation>CSS style: only background-color supported</a:documentation>
583
+ <a:documentation>CSS style: only background-color, color, border supported</a:documentation>
532
584
  </attribute>
533
585
  </optional>
534
586
  </define>
@@ -595,6 +647,7 @@ gives an explicit page orientation</a:documentation>
595
647
  </include>
596
648
  <!-- end overrides -->
597
649
  <define name="FnAttributes" combine="interleave">
650
+ <ref name="RequiredId"/>
598
651
  <optional>
599
652
  <attribute name="hiddenref">
600
653
  <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
@@ -604,9 +657,10 @@ This is done if the footnote reference is already presented in some other form,
604
657
  </optional>
605
658
  </define>
606
659
  <define name="TdAttributes" combine="interleave">
660
+ <ref name="RequiredId"/>
607
661
  <optional>
608
662
  <attribute name="style">
609
- <a:documentation>CSS style: only background-color supported</a:documentation>
663
+ <a:documentation>CSS style: only background-color, color, border supported</a:documentation>
610
664
  </attribute>
611
665
  </optional>
612
666
  </define>
@@ -681,11 +735,22 @@ titlecase, or lowercase</a:documentation>
681
735
  <ref name="BlockAttributes"/>
682
736
  </define>
683
737
  <define name="TableAttributes" combine="interleave">
738
+ <optional>
739
+ <attribute name="plain">
740
+ <a:documentation>Render as a plain attribute, with no shading or borders</a:documentation>
741
+ <data type="boolean"/>
742
+ </attribute>
743
+ </optional>
684
744
  <optional>
685
745
  <attribute name="width">
686
746
  <a:documentation>Width of the table block in rendering</a:documentation>
687
747
  </attribute>
688
748
  </optional>
749
+ <optional>
750
+ <attribute name="style">
751
+ <a:documentation>CSS style: only background-color, color, border supported</a:documentation>
752
+ </attribute>
753
+ </optional>
689
754
  <ref name="BlockAttributes"/>
690
755
  </define>
691
756
  <define name="FigureAttributes" combine="interleave">
@@ -1403,7 +1468,7 @@ numbers</a:documentation>
1403
1468
  </optional>
1404
1469
  <ref name="DocumentBody"/>
1405
1470
  <optional>
1406
- <ref name="review-container">
1471
+ <ref name="annotation-container">
1407
1472
  <a:documentation>Annotations to the document</a:documentation>
1408
1473
  </ref>
1409
1474
  </optional>
@@ -1447,8 +1512,8 @@ numbers</a:documentation>
1447
1512
  </oneOrMore>
1448
1513
  </element>
1449
1514
  </define>
1450
- <define name="review-container">
1451
- <element name="review-container">
1515
+ <define name="annotation-container">
1516
+ <element name="annotation-container">
1452
1517
  <oneOrMore>
1453
1518
  <ref name="review"/>
1454
1519
  </oneOrMore>
@@ -1821,7 +1886,7 @@ used in document amendments</a:documentation>
1821
1886
  </element>
1822
1887
  </define>
1823
1888
  <define name="TermAttributes">
1824
- <ref name="OptionalId"/>
1889
+ <ref name="RequiredId"/>
1825
1890
  <ref name="LocalizedStringAttributes"/>
1826
1891
  <ref name="BlockAttributes"/>
1827
1892
  </define>
@@ -2164,6 +2229,7 @@ used in document amendments</a:documentation>
2164
2229
  <define name="termdefinition">
2165
2230
  <a:documentation>The definition of a term applied in the current document</a:documentation>
2166
2231
  <element name="definition">
2232
+ <ref name="RequiredId"/>
2167
2233
  <optional>
2168
2234
  <attribute name="type">
2169
2235
  <a:documentation>Type of definition, used to differentiate it from other definitions of the same term if present</a:documentation>
@@ -2185,6 +2251,7 @@ used in document amendments</a:documentation>
2185
2251
  </define>
2186
2252
  <define name="verbaldefinition">
2187
2253
  <element name="verbal-definition">
2254
+ <ref name="RequiredId"/>
2188
2255
  <oneOrMore>
2189
2256
  <choice>
2190
2257
  <a:documentation>Content of the verbal representation of the term</a:documentation>
@@ -2205,6 +2272,7 @@ used in document amendments</a:documentation>
2205
2272
  <define name="nonverbalrep">
2206
2273
  <a:documentation>Non-verbal representation of the term</a:documentation>
2207
2274
  <element name="non-verbal-representation">
2275
+ <ref name="RequiredId"/>
2208
2276
  <oneOrMore>
2209
2277
  <choice>
2210
2278
  <a:documentation>Content of the non-verbal representation of the term</a:documentation>
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Generic
3
- VERSION = "3.0.3".freeze
3
+ VERSION = "3.1.0".freeze
4
4
  end
5
5
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
  spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
29
29
 
30
- spec.add_dependency "metanorma-standoc", "~> 3.0.0"
30
+ spec.add_dependency "metanorma-standoc", "~> 3.1.0"
31
31
 
32
32
  spec.add_development_dependency "debug"
33
33
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-generic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-26 00:00:00.000000000 Z
11
+ date: 2025-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 3.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 3.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: debug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +237,7 @@ files:
237
237
  - lib/metanorma-generic.rb
238
238
  - lib/metanorma/generic.rb
239
239
  - lib/metanorma/generic/basicdoc.rng
240
+ - lib/metanorma/generic/bibdata_config.rb
240
241
  - lib/metanorma/generic/biblio-standoc.rng
241
242
  - lib/metanorma/generic/biblio.rng
242
243
  - lib/metanorma/generic/converter.rb