relaton-render 1.4.0.pre.alpha.2 → 1.4.0.pre.alpha.3
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 +4 -4
- data/lib/relaton/render/general.rb +74 -1
- data/lib/relaton/render/iso690/i18n.rb +13 -1
- data/lib/relaton/render/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f944c1a5f1a26e1ec5c4d1cceae37ea7420257034c87b31eaa6ea0c8e46269e6
|
|
4
|
+
data.tar.gz: 5bcd504fbf58c890f778d4f492d70bbabe9b8a974837c838752fbf367129c67c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0032e8464f6d1731e4aef47a69dfca0e646df0d6c52d85dfa16b72194357f5a5b01f513ffe65498b08e5b6ae4f3e83ef8f6819c6e87e6d1b5a361787a1ce7495
|
|
7
|
+
data.tar.gz: ab3af5ef2028428f712fca4727fe126cf56cccfb33fac0d523190536b237616d0207d2363aa2f422fc48e2c3fa78e4a9922ade6f7ad6df6c5738e1be8dc02098
|
|
@@ -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:
|
|
30
|
+
lang: @lang,
|
|
20
31
|
script: options[:script] || "Latn",
|
|
21
32
|
labels: options[:i18nhash] || {},
|
|
22
33
|
)
|
|
@@ -31,8 +42,70 @@ 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
|
+
def facade_docids(doc)
|
|
99
|
+
node = doc
|
|
100
|
+
unless node.respond_to?(:xpath)
|
|
101
|
+
require "moxml"
|
|
102
|
+
node = Moxml.parse(doc.to_s).root
|
|
103
|
+
end
|
|
104
|
+
return [] unless node
|
|
105
|
+
|
|
106
|
+
node.xpath("./docidentifier").map(&:text)
|
|
107
|
+
end
|
|
108
|
+
|
|
36
109
|
def warn_general_config
|
|
37
110
|
return if General.config_warned
|
|
38
111
|
|
|
@@ -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
|
-
|
|
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
|
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.
|
|
4
|
+
version: 1.4.0.pre.alpha.3
|
|
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-
|
|
11
|
+
date: 2026-10-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|