metanorma-standoc 3.5.28 → 3.5.29

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: 5e258b0c768ef6f5703373820938b6196facf725af40aa5b8f73949c66083bff
4
- data.tar.gz: 40bd940cf5f369be23a0460a8fb3a30f6f988eebe9ba0e78c61a62f74cd29f4b
3
+ metadata.gz: cd644e14545ddd034770bfa7cbaedd6dfa03e0d965747f9e785e3c8d35bed0b0
4
+ data.tar.gz: 027e65ca1ce3c58e0263d31060d14948be953567841d615be8d2e4df7d15afdb
5
5
  SHA512:
6
- metadata.gz: d97ef04e2d89902661fd31749297604d6094b02fca32301991a8bf45fbb31ac875db7e3f2a89b41a718dc17b82ea8c9d2be0d0c70ab9f7993d42a4ffda4161f1
7
- data.tar.gz: 65f1a4ab130d59241a09ff4cf56bd8e63e5ae2cde8307b28fe211589a0e4948b70f0e856252a8e21cc8edced9172cd427cbaf92380bc1079bc79b709b9d0363b
6
+ metadata.gz: 43cb4721ce0f090f1d1bc04f82cabb72f32892582b6049b2841ddde12ebcaa471fa1fb907bd1ad959f29c77253c5d8444da43f308957fab08b53c86cc012ac85
7
+ data.tar.gz: 7ad4bd3554f62d9404b2df08a8555585f455614c7732de6a0c458a1b482265ce1401a48b5456a3def1db85507c9745a60e0dbdcb795a21044dcaa709ec9da3ff
@@ -7,23 +7,89 @@ module Metanorma
7
7
  def ref_dl_cleanup(xmldoc)
8
8
  xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
9
9
  bib = dl_bib_extract(c) or next
10
+ normalize_asciibib_contact(bib, c)
10
11
  validate_ref_dl(bib, c)
11
12
  xml = Relaton::Bib::ItemData.new(
12
13
  **Relaton::Bib::HashParserV1.hash_to_bib(bib),
13
14
  ).to_xml or next
14
15
  bibitem = Nokogiri::XML(xml)
15
- ref_dl_cleanup_id(bibitem.root, c)
16
+ ref_dl_cleanup_id(bibitem.root, c, bib["id"])
17
+ wrap_asciibib_contact(bibitem.root)
18
+ default_asciibib_role(bibitem.root, c)
16
19
  c.replace(bibitem.root)
17
20
  end
18
21
  end
19
22
 
20
- def ref_dl_cleanup_id(bibitem, clause)
23
+ # metanorma-standoc#1412: the citation target is the authored
24
+ # id::, but the legacy Relaton hash parser strips non-word
25
+ # characters from the id (ANSI.X9.95 becomes ANSIX995), leaving
26
+ # cross-references dangling. The anchor is set from the authored
27
+ # string instead.
28
+ def ref_dl_cleanup_id(bibitem, clause, authored_id = nil)
21
29
  bibitem["anchor"] = bibitem["id"]
30
+ authored_id && !authored_id.empty? and
31
+ bibitem["anchor"] = authored_id
22
32
  clause["anchor"] && !/^_/.match(clause["anchor"]) and
23
33
  bibitem["anchor"] = clause["anchor"]
24
34
  add_id(bibitem)
25
35
  end
26
36
 
37
+ LEGACY_ASCIIDIB_CONTACT_KEYS =
38
+ %w(street city state country postcode).freeze
39
+
40
+ # metanorma-standoc#1413: the legacy AsciiBib syntax puts street/
41
+ # city/state/country/postcode directly under contact; the
42
+ # canonical form nests them under contact.address, which is what
43
+ # the Relaton hash parser reads. Accept the legacy keys with a
44
+ # deprecation warning naming the canonical form.
45
+ def normalize_asciibib_contact(bib, clause)
46
+ contributors = bib["contributor"]
47
+ contributors = [contributors] unless contributors.is_a?(Array)
48
+ contributors.each do |c|
49
+ org = c.is_a?(Hash) && c["organization"]
50
+ next unless org.is_a?(Hash)
51
+ contacts = org["contact"]
52
+ next unless contacts.is_a?(Hash)
53
+
54
+ legacy = contacts.slice(*LEGACY_ASCIIDIB_CONTACT_KEYS)
55
+ next if legacy.empty?
56
+
57
+ @log.add("STANDOC_73", clause, params: [legacy.keys.join(", ")])
58
+ contacts["address"] = contacts["address"] ? contacts["address"].merge(legacy) : legacy
59
+ LEGACY_ASCIIDIB_CONTACT_KEYS.each { |k| contacts.delete(k) }
60
+ end
61
+ end
62
+
63
+ # metanorma-standoc#1413: the Relaton exporter emits address/
64
+ # phone/email/uri directly under organization; the Metanorma
65
+ # schema nests them in a contact element.
66
+ def wrap_asciibib_contact(bibitem)
67
+ bibitem.xpath(".//organization").each do |org|
68
+ direct = org.xpath("./address | ./phone | ./email | ./uri")
69
+ next if direct.empty?
70
+
71
+ contact = Nokogiri::XML::Node.new("contact", org.document)
72
+ logo = org.at_xpath("./logo")
73
+ logo&.before(contact) || org << contact
74
+ direct.each { |n| contact << n }
75
+ end
76
+ end
77
+
78
+ # metanorma-standoc#1413: the schema requires a role on every
79
+ # contributor; a role-less AsciiBib contributor renders as
80
+ # author (the released 1.15.3 behaviour) with a warning naming
81
+ # the explicit key.
82
+ def default_asciibib_role(org, clause)
83
+ org.xpath("./contributor").each do |c|
84
+ next if c.at("./role")
85
+
86
+ @log.add("STANDOC_74", clause, params: [])
87
+ role = Nokogiri::XML::Node.new("role", org.document)
88
+ role["type"] = "author"
89
+ c.before(role)
90
+ end
91
+ end
92
+
27
93
  # do not accept implicit id
28
94
  def validate_ref_dl(bib, clause)
29
95
  id = bib["id"]
@@ -227,6 +227,15 @@ module Metanorma
227
227
  STANDOC_72: { category: "Update Units",
228
228
  error: "Update records file %s is malformed: %s",
229
229
  severity: 0 },
230
+ STANDOC_73: { category: "Bibliography",
231
+ error: "Legacy AsciiBib contact keys %s are deprecated; " \
232
+ "nest them under contact.address (e.g. " \
233
+ "contact.address.street)",
234
+ severity: 1 },
235
+ STANDOC_74: { category: "Bibliography",
236
+ error: "Contributor is missing a role; defaulting to " \
237
+ "author. Set contributor.role:: explicitly",
238
+ severity: 1 },
230
239
  RELATON_1: { category: "Relaton",
231
240
  error: "(Error from Relaton) %s",
232
241
  severity: 0 },
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.5.28".freeze
22
+ VERSION = "3.5.29".freeze
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.28
4
+ version: 3.5.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.