isodoc 3.7.17 → 3.7.18

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: 0b77176d43a8c38415974322593e3f8645fe4f557c8066ab18b262751d50f142
4
- data.tar.gz: '096b610bf213fabddc97290f01ac7dcb902a0bb046d7a258da8ce4b8a4f41054'
3
+ metadata.gz: 78cb90e0e0fea60ab1ebfc166b51618d39abf17d345de2237a2b841acf9e0dff
4
+ data.tar.gz: 4a3828eb99a8e58d62ce6a77a26adceee9e40e5ac58d16c5501d17fdbbb861b5
5
5
  SHA512:
6
- metadata.gz: b0faf187fee391701f81d12b6e44fe1314366efab0d3e4d59714fc9ca8807e53683394684d380d10945cfc3b41eb7f61e20b9780a33f63cd6f8845d34296cf7a
7
- data.tar.gz: 1b34a74664814e28781c5226b67d4fb4b94b6d26d9dc8edb8719f69b4e2f3cbb0120e81800a4413de107e4412660624cee25e6851cc61c0c1e4d58710c715d8e
6
+ metadata.gz: f81f19086e763fca68dc8b1ad70b325592eeac99945628f81e16fadebed2b6e010df91cccf0b27d8232a62d769514a1bcbac2a9f907bbda3f0a2e3ed39fcd73f
7
+ data.tar.gz: 6349cad368a56fe08aad86ea77825ef72aff7947828dcb955cec2aadec17911df52607ef0a3c1a57f6742157654025e0b4aa71146682354b8d80c32dd18a461c
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "moxml"
4
+ require "relaton"
5
+ require "relaton/bib"
6
+
7
+ module IsoDoc
8
+ # Bibdata ingestion through relaton's library surface, not Relaton::Cli.
9
+ #
10
+ # Same pattern as Metanorma::Collection::Config::BibdataParser
11
+ # (metanorma/metanorma#716), which mirrors the flavor dispatch of
12
+ # relaton cli.rb parse_xml: the processor is named by the first
13
+ # docidentifier's type, else by the leading word of its text. It takes
14
+ # an XML String, so it behaves the same on relaton releases before and
15
+ # after 3.1.6, where Cli.parse_xml changed from a Nokogiri document to a
16
+ # String argument.
17
+ module BibdataParser
18
+ class << self
19
+ # @param xml [String] serialized bibdata or bibitem XML
20
+ # @return [Relaton::Bib::ItemData, nil] nil when the source is not
21
+ # parseable XML
22
+ def from_xml(xml)
23
+ return unless xml
24
+
25
+ doc = Moxml.new.parse(xml)
26
+ plain = without_namespaces(doc)
27
+ processor = processor_for_xml(doc)
28
+ processor ? processor.from_xml(plain) : generic_from_xml(plain)
29
+ rescue Moxml::ParseError
30
+ nil
31
+ end
32
+
33
+ private
34
+
35
+ # No-flavor fallback: unparseable sources degrade to a nil bibdata,
36
+ # as in the mirrored Cli method.
37
+ def generic_from_xml(plain)
38
+ Relaton::Bib::Item.from_xml(plain)
39
+ rescue StandardError
40
+ nil
41
+ end
42
+
43
+ # The processor named by the first docidentifier's type, else by
44
+ # the first word of its text.
45
+ def processor_for_xml(doc)
46
+ docid = doc.xpath("//*[local-name()='docidentifier']").first
47
+ return unless docid
48
+
49
+ get_proc(docid) ||
50
+ Relaton::Db::Registry.instance.by_type(docid.text[/^\w+/])
51
+ end
52
+
53
+ def get_proc(docid)
54
+ type = docid["type"]
55
+ return unless type
56
+
57
+ Relaton::Db::Registry.instance.by_type(type)
58
+ end
59
+
60
+ # The root element as XML, with every element and attribute in no
61
+ # namespace (`xml:` attributes keep their prefix). The lutaml-model
62
+ # mappings are namespace-free, and Moxml cannot drop a namespace in
63
+ # place, so this builds a copy.
64
+ def without_namespaces(doc)
65
+ plain = Moxml.new.create_document
66
+ plain.add_child plain_element(plain, doc.root)
67
+ plain.root.to_xml
68
+ end
69
+
70
+ def plain_element(doc, src)
71
+ elm = doc.create_element(src.name)
72
+ # An attribute in no namespace wins over a prefixed one of the
73
+ # same local name (`type` over `a:type`).
74
+ src.attributes.sort_by { |a| a.namespace ? 0 : 1 }.each do |attr|
75
+ elm[plain_name(attr)] = attr.value
76
+ end
77
+ src.children.each { |child| elm.add_child plain_node(doc, child) }
78
+ elm
79
+ end
80
+
81
+ # The local name; an `xml:` attribute keeps its prefix.
82
+ def plain_name(attr)
83
+ attr.namespace&.prefix == "xml" ? "xml:#{attr.name}" : attr.name
84
+ end
85
+
86
+ # An entity reference (`&nbsp;`) stays as its text: lutaml-model
87
+ # cannot read an entity it has no declaration for. A processing
88
+ # instruction becomes an empty text.
89
+ def plain_node(doc, src)
90
+ case src
91
+ when Moxml::Element then plain_element(doc, src)
92
+ when Moxml::Cdata then doc.create_cdata(src.content)
93
+ when Moxml::Text then doc.create_text(src.content)
94
+ when Moxml::Comment then doc.create_comment(src.content)
95
+ when Moxml::EntityReference then doc.create_text("&#{src.name};")
96
+ else doc.create_text("")
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,6 +1,6 @@
1
1
  require "relaton"
2
2
  require "relaton/bib"
3
- require "relaton/cli"
3
+ require_relative "bibdata_parser"
4
4
 
5
5
  module IsoDoc
6
6
  class BibdataConfig < ::Lutaml::Model::Serializable
@@ -16,12 +16,12 @@ module IsoDoc
16
16
  to: :bibdata_to_xml }
17
17
  end
18
18
 
19
+ # Through relaton's library surface, as metanorma#716 does for
20
+ # collections. Under the moxml/leptris adapter the mapping node's
21
+ # native is not Nokogiri, so go through markup.
19
22
  def bibdata_from_xml(model, node)
20
23
  node or return
21
- # Cli.parse_xml's contract is a Nokogiri::XML::Document
22
- # (remove_namespaces!, at); under the moxml/leptris adapter the
23
- # mapping node's native is not Nokogiri. Convert via markup.
24
- model.bibdata = Relaton::Cli.parse_xml(Nokogiri::XML(node.to_xml))
24
+ model.bibdata = BibdataParser.from_xml(node.to_xml)
25
25
  end
26
26
 
27
27
  def bibdata_to_xml(model, parent, doc); end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "3.7.17".freeze
2
+ VERSION = "3.7.18".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.17
4
+ version: 3.7.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-16 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -270,6 +270,7 @@ files:
270
270
  - lib/isodoc/base_style/scripts.html
271
271
  - lib/isodoc/base_style/typography.css
272
272
  - lib/isodoc/base_style/typography.scss
273
+ - lib/isodoc/bibdata_parser.rb
273
274
  - lib/isodoc/class_utils.rb
274
275
  - lib/isodoc/common.rb
275
276
  - lib/isodoc/convert.rb