relaton-render 1.4.0.pre.alpha.2 → 1.4.0.pre.alpha.4

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: 51375c04860a0856ea38e357f01398a65e2b8d32b8d2626e014d46110ae710fe
4
- data.tar.gz: e684c82bd7d48d1a2763adf42c692b8a980c9f80c1cb35334bf6f40fcd4324b4
3
+ metadata.gz: 50d68785ac0e26c28b114b0080e9d2057f701801d641baf0fa955819edaaa7f3
4
+ data.tar.gz: 2c150fa61c2c5a073c372ab8492f897a25294f02f104cc5a442b17cd8efe4104
5
5
  SHA512:
6
- metadata.gz: c3c7fb5f5ffc57913d83f8f99ceb01d50e234059a68731a5e32ab84e22e47c69cb1c7faf4f1248cdaf9954dcca2295bf7843cb47a55a63b940d361cad87673f0
7
- data.tar.gz: a3c8a7e0127f3d1dddaad363802a2f882ce7cffa51beccd3fd7e72724ef0ff894b746b86d08386c75644b812f95c666f09d41b821ea7e10d6ebb9f8cf9517f4c
6
+ metadata.gz: 2206dd123a1cab3a5ae0602e4de1cc71b71aaaac67f1a68474db7c367b10a29a52d08dc477770770295b48d89cfbae263bd314818d9cf5bcb1f722576a479f7c
7
+ data.tar.gz: 7270b105580e34e9637172aa3953d50b6bf9bdb51a9d9d9dfe55f6438bb9d026cf2d891b2c6f3b74add5b9bca73b4c8916fd6d33369e972b9ae87207398d33b1
@@ -14,9 +14,20 @@ module Relaton
14
14
  # expresses everything the old config.yml did (see the citation
15
15
  # module in relaton-models).
16
16
  class General
17
+ # The eref `style=` vocabulary metanorma-standoc validates against
18
+ # (cleanup/xref.rb reads citetemplate.template_raw's keys) — the
19
+ # 1.x default config's top-level citation styles.
20
+ CITE_STYLES = %i[
21
+ author_date author_date_br author date reference_tag title
22
+ title_reference_tag short
23
+ ].freeze
24
+
25
+ CiteTemplate = Struct.new(:template_raw)
26
+
17
27
  def initialize(options = {})
28
+ @lang = options[:language] || options[:lang] || "en"
18
29
  @renderer = Iso690::Renderer.new(
19
- lang: options[:language] || options[:lang] || "en",
30
+ lang: @lang,
20
31
  script: options[:script] || "Latn",
21
32
  labels: options[:i18nhash] || {},
22
33
  )
@@ -31,8 +42,109 @@ module Relaton
31
42
  @renderer.citation(model, **opts)
32
43
  end
33
44
 
45
+ # isodoc's references rendering: renderings[id][:formattedref]
46
+ # feeds the <formattedref> of every bibitem (isodoc
47
+ # presentation_function/refs.rb).
48
+ def render_all(bib, type: "author-date")
49
+ items = facade_bibitems(bib) or return nil
50
+ items.each_with_object({}).with_index do |(item, m), i|
51
+ ref = @renderer.render(item)
52
+ m[item.id] = {
53
+ id: item.id, ord: i, formattedref: ref,
54
+ citation: {
55
+ full: ref,
56
+ default: item.docidentifier.first&.content.to_s,
57
+ short: @renderer.citation(item),
58
+ },
59
+ }
60
+ end
61
+ end
62
+
63
+ # isodoc's pref_ref_code_parse reads
64
+ # data[:authoritative_identifier] to build biblio-tag identifiers
65
+ # (presentation_function/docid.rb). Returns [data, self] as the
66
+ # 1.x signature did.
67
+ def parse(doc)
68
+ [{ authoritative_identifier: facade_docids(doc) }, self]
69
+ end
70
+
71
+ def citetemplate
72
+ CiteTemplate.new(CITE_STYLES.to_h { |s| [s, ""] })
73
+ end
74
+
34
75
  private
35
76
 
77
+ # 1.x accepted a <references> XML string (isodoc strips namespaces
78
+ # before building it) or a ready array of models.
79
+ def facade_bibitems(bib)
80
+ case bib
81
+ when Array then bib
82
+ when String
83
+ require "moxml"
84
+ root = Moxml.parse(bib).root
85
+ return nil unless root&.name == "references"
86
+
87
+ klass = facade_bibitem_class
88
+ root.xpath("./bibitem").filter_map { |b| klass.from_xml(b.to_xml) }
89
+ end
90
+ end
91
+
92
+ def facade_bibitem_class
93
+ Relaton::Bib::Bibitem
94
+ rescue NameError
95
+ Relaton::Bib::Item
96
+ end
97
+
98
+ # 1.x Parse#authoritative_identifier semantics: the
99
+ # primary/language cascade, the excluded types (URN, DOI, ISBN...)
100
+ # dropped, and scoped ids (biblio-tag duplicates, IEEE trademark)
101
+ # demoted within their type group. isodoc hands the live bibitem
102
+ # node with the document's default namespace still attached, so the
103
+ # element queries must be namespace-agnostic.
104
+ EXCLUDED_ID_TYPES = %w(METANORMA METANORMA-ORDINAL AUTHOR-DATE TITLE
105
+ URN ISO-REFERENCE ISSN ISBN DOI).freeze
106
+
107
+ def facade_docids(doc)
108
+ node = doc
109
+ unless node.respond_to?(:xpath)
110
+ require "moxml"
111
+ node = Moxml.parse(doc.to_s).root
112
+ end
113
+ return [] unless node
114
+
115
+ ids = node.xpath("./*[local-name() = 'docidentifier']")
116
+ ids = facade_scope_filter(ids)
117
+ out = nil
118
+ [
119
+ ->(x) { x["language"] == @lang && x["primary"] },
120
+ ->(x) { x["primary"] },
121
+ ->(x) { x["language"] == @lang },
122
+ ->(_x) { true },
123
+ ].each do |p|
124
+ out = ids.select do |x|
125
+ p.call(x) && !EXCLUDED_ID_TYPES.include?(facade_id_type(x))
126
+ end
127
+ out.empty? or break
128
+ end
129
+ out.map { |x| x.text.strip }
130
+ end
131
+
132
+ def facade_id_type(id)
133
+ t = id["type"] or return nil
134
+ m = /\A(ISBN|ISSN)\..*/i.match(t) or return t.upcase
135
+ m[1].upcase
136
+ end
137
+
138
+ def facade_scope_filter(ids)
139
+ ids.detect { |i| i["scope"] } or return ids
140
+ ids.group_by { |i| i["type"] }.flat_map do |type, group|
141
+ grouped = group.group_by { |i| i["scope"] }
142
+ if type == "IEEE" then grouped["trademark"] || grouped[nil] || []
143
+ else grouped[nil] || []
144
+ end
145
+ end
146
+ end
147
+
36
148
  def warn_general_config
37
149
  return if General.config_warned
38
150
 
@@ -54,11 +54,23 @@ module Relaton
54
54
  code = lang.to_s.empty? ? "en" : lang
55
55
  path = File.join(__dir__, "i18n", "#{code}.yml")
56
56
  unless File.file?(path)
57
- raise ArgumentError, "no i18n declarations for language #{code}"
57
+ # 1.x carried declarations for every locale isodoc uses; the
58
+ # v2 packs are per-style data. Unknown languages fall back to
59
+ # the English pack rather than killing the whole conversion.
60
+ fallback_warn(code)
61
+ path = File.join(__dir__, "i18n", "en.yml")
62
+ raise ArgumentError, "no i18n declarations for language #{code}" unless File.file?(path)
58
63
  end
59
64
 
60
65
  from_yaml(File.read(path))
61
66
  end
67
+
68
+ def fallback_warn(code)
69
+ (@fallback_warned ||= {})[code] and return
70
+ @fallback_warned[code] = true
71
+ warn "relaton-render: no i18n declarations for language " \
72
+ "#{code}; falling back to en"
73
+ end
62
74
  end
63
75
  end
64
76
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "1.4.0.pre.alpha.2".freeze
3
+ VERSION = "1.4.0.pre.alpha.4".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-render
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.pre.alpha.2
4
+ version: 1.4.0.pre.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-01 00:00:00.000000000 Z
11
+ date: 2026-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model