metanorma 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90bf0ce070f2311504682547eb3024210586686123020f92a776fc590fe478a9
4
- data.tar.gz: 330f7930f8c1bfd3972fff06b59d1a31bdd78893a849d4b01f377051c7137089
3
+ metadata.gz: 8c62d15c313b6595ca184016faa8f0996de7d1d8f1321e932e6adc89d230682d
4
+ data.tar.gz: f13f182618c3fec66f42e412bfe3d4baa142b877421458fb2555912ce077f8e5
5
5
  SHA512:
6
- metadata.gz: 878e9d88ee70e5bfeda7198d596b77d4785f0c4aab345aedf7eabf67d5a28dddfb04df560376376b2137aa20f330986efee59d3f456ccf15d4fbca64ce45d1c8
7
- data.tar.gz: 69f19f897413b45d7111fcabeba645a2aaffe48900230b18f08eef4977219d009ac91a5952f9c1afb985fb31ccb936f25b169ebc1c29e46256852d358869a6d8
6
+ metadata.gz: 3d7e934fa1d1f0348a9877f25e037294e09513a3df04873ec6394b908d443cb2152480bd14c3e5948071657a6c4bcee2907964b8a2b408c7bb0d67a3f99e37c5
7
+ data.tar.gz: e1e626b4795c18b5a934262bc37faf0c4fe997832661f73e27e852f6bf66f67bde8c2b2edc86343463e3fde70eefd722e9af19fca186957761048193c70fc29b
@@ -38,10 +38,8 @@ module Metanorma
38
38
 
39
39
  # @param bib [Nokogiri::XML::Element]
40
40
  # @param identifier [String]
41
- def update_bibitem(bib, identifier) # rubocop:disable Metrics/AbcSize
42
- docid = bib&.at(ns("./docidentifier"))&.children&.to_xml
43
- return fail_update_bibitem(docid, identifier) unless @files[docid]
44
-
41
+ def update_bibitem(bib, identifier)
42
+ docid = get_bibitem_docid(bib, identifier) or return
45
43
  newbib = dup_bibitem(docid, bib)
46
44
  bib.replace(newbib)
47
45
  _file, url = targetfile(@files[docid], relative: true, read: false,
@@ -52,6 +50,19 @@ module Metanorma
52
50
  newbib.at(ns("./docidentifier")).previous = uri_node
53
51
  end
54
52
 
53
+ def get_bibitem_docid(bib, identifier)
54
+ # IDs for repo references are untyped by default
55
+ docid = bib.at(ns("./docidentifier[not(@type)]")) ||
56
+ bib.at(ns("./docidentifier"))
57
+ docid &&= docid.children.to_xml
58
+ if @files[docid]
59
+ docid
60
+ else
61
+ fail_update_bibitem(docid, identifier)
62
+ nil
63
+ end
64
+ end
65
+
55
66
  def fail_update_bibitem(docid, identifier)
56
67
  error = "[metanorma] Cannot find crossreference to document #{docid} "\
57
68
  "in document #{identifier}."
@@ -75,7 +86,8 @@ module Metanorma
75
86
  # in another file in the collection)
76
87
  # @param file [String] XML content
77
88
  # @param identifier [String] docid
78
- # @param internal_refs [Hash{String=>Hash{String=>String}] schema name to anchor to filename
89
+ # @param internal_refs [Hash{String=>Hash{String=>String}] schema name to
90
+ # anchor to filename
79
91
  # @return [String] XML content
80
92
  def update_xrefs(file, identifier, internal_refs)
81
93
  docxml = Nokogiri::XML(file) { |config| config.huge }
@@ -142,11 +154,12 @@ module Metanorma
142
154
  def update_direct_refs_to_docs(docxml, identifier)
143
155
  erefs = collect_erefs(docxml)
144
156
  docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
145
- docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
157
+ docid = b.at(ns("./docidentifier[@type = 'repository']"))&.text
146
158
  next unless docid && %r{^current-metanorma-collection/}.match(docid)
147
159
 
148
160
  update_bibitem(b, identifier)
149
- docid = b&.at(ns("./docidentifier"))&.children&.to_xml or next
161
+ docid = b.at(ns("./docidentifier")) or next
162
+ docid = docid.children.to_xml
150
163
  erefs[:citeas][docid] and update_anchors(b, docxml, docid)
151
164
  end
152
165
  end
@@ -211,9 +224,9 @@ module Metanorma
211
224
  # anchor given the locality, and insert it into the crossref
212
225
  def update_anchor_create_loc(_bib, eref, docid)
213
226
  ins = eref.at(ns("./localityStack")) or return
214
- type = ins&.at(ns("./locality/@type"))&.text
227
+ type = ins.at(ns("./locality/@type"))&.text
215
228
  type = "clause" if type == "annex"
216
- ref = ins&.at(ns("./locality/referenceFrom"))&.text
229
+ ref = ins.at(ns("./locality/referenceFrom"))&.text
217
230
  anchor = @files[docid][:anchors].dig(type, ref) or return
218
231
  ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}"\
219
232
  "</referenceFrom></locality>"
@@ -40,9 +40,9 @@ module Metanorma
40
40
  end
41
41
 
42
42
  def attachment_bibitem(identifier)
43
- Nokogiri::XML(
44
- "<bibdata><docidentifier>#{identifier}</docidentifier></bibdata>",
45
- )
43
+ Nokogiri::XML <<~DOCUMENT
44
+ <bibdata><docidentifier>#{identifier}</docidentifier></bibdata>
45
+ DOCUMENT
46
46
  end
47
47
 
48
48
  private
@@ -94,9 +94,10 @@ module Metanorma
94
94
 
95
95
  # @return [String]
96
96
  def type
97
- @type ||= (@bibitem.docidentifier.first&.type&.downcase ||
98
- @bibitem.docidentifier.first&.id&.match(/^[^\s]+/)&.to_s)&.downcase ||
99
- "standoc"
97
+ first = @bibitem.docidentifier.first
98
+ @type ||= (first&.type&.downcase ||
99
+ first&.id&.match(/^[^\s]+/)&.to_s)&.downcase ||
100
+ "standoc"
100
101
  end
101
102
 
102
103
  private
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.5.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor