relaton-render 1.4.0.pre.alpha.1 → 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 +124 -0
- data/lib/relaton/render/iso690/i18n.rb +26 -1
- data/lib/relaton/render/iso690/renderer.rb +3 -1
- data/lib/relaton/render/iso690/style.rb +2 -0
- data/lib/relaton/render/iso690.rb +4 -0
- data/lib/relaton/render/version.rb +1 -1
- metadata +3 -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
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
module Render
|
|
5
|
+
# Compatibility entry point (relaton-render#90).
|
|
6
|
+
#
|
|
7
|
+
# The v2 engine replaced the liquid/config/i18n machinery with the
|
|
8
|
+
# template evaluator over CitationStyle instances
|
|
9
|
+
# (Relaton::Render::Iso690). isodoc main's render-isodoc subclasses
|
|
10
|
+
# this constant, so it must exist for all-git-main stacks to boot.
|
|
11
|
+
# This facade delegates rendering to the v2 engine; the retired
|
|
12
|
+
# options (config:, template overrides in liquid syntax) are ignored
|
|
13
|
+
# with one warning — migrate to a CitationStyle instance, which
|
|
14
|
+
# expresses everything the old config.yml did (see the citation
|
|
15
|
+
# module in relaton-models).
|
|
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
|
+
|
|
27
|
+
def initialize(options = {})
|
|
28
|
+
@lang = options[:language] || options[:lang] || "en"
|
|
29
|
+
@renderer = Iso690::Renderer.new(
|
|
30
|
+
lang: @lang,
|
|
31
|
+
script: options[:script] || "Latn",
|
|
32
|
+
labels: options[:i18nhash] || {},
|
|
33
|
+
)
|
|
34
|
+
warn_general_config if options[:config]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def render(model, **opts)
|
|
38
|
+
@renderer.render(model, **opts)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def citation(model, **opts)
|
|
42
|
+
@renderer.citation(model, **opts)
|
|
43
|
+
end
|
|
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
|
+
|
|
75
|
+
private
|
|
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
|
+
|
|
109
|
+
def warn_general_config
|
|
110
|
+
return if General.config_warned
|
|
111
|
+
|
|
112
|
+
General.config_warned = true
|
|
113
|
+
warn "relaton-render: Relaton::Render::General is a compatibility " \
|
|
114
|
+
"facade over the v2 engine; the liquid config option is " \
|
|
115
|
+
"retired and ignored. Author a CitationStyle instance " \
|
|
116
|
+
"(relaton-models citation module) for custom rendering."
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
class << self
|
|
120
|
+
attr_accessor :config_warned
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -36,16 +36,41 @@ module Relaton
|
|
|
36
36
|
self
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# Runtime label overrides (a caller's i18n hash): the pack's label
|
|
40
|
+
# names win as the key mapping; unknown keys are ignored.
|
|
41
|
+
def overlay_hash!(hash)
|
|
42
|
+
known = %w[
|
|
43
|
+
edition series_no report_no available_from in and oxford_comma
|
|
44
|
+
ed eds date_range others no_date no_author at
|
|
45
|
+
]
|
|
46
|
+
hash.each do |key, value|
|
|
47
|
+
labels[key.to_s] = value if known.include?(key.to_s) && !value.nil?
|
|
48
|
+
end
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
|
|
39
52
|
class << self
|
|
40
53
|
def load(lang = "en")
|
|
41
54
|
code = lang.to_s.empty? ? "en" : lang
|
|
42
55
|
path = File.join(__dir__, "i18n", "#{code}.yml")
|
|
43
56
|
unless File.file?(path)
|
|
44
|
-
|
|
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)
|
|
45
63
|
end
|
|
46
64
|
|
|
47
65
|
from_yaml(File.read(path))
|
|
48
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
|
|
49
74
|
end
|
|
50
75
|
end
|
|
51
76
|
end
|
|
@@ -24,9 +24,11 @@ module Relaton
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def initialize(style: DEFAULT_STYLE, lang: "en", script: "Latn"
|
|
27
|
+
def initialize(style: DEFAULT_STYLE, lang: "en", script: "Latn",
|
|
28
|
+
labels: {})
|
|
28
29
|
@style = Style.load(style)
|
|
29
30
|
@i18n = I18n.load(lang).overlay!(@style.scheme.locale)
|
|
31
|
+
@i18n.overlay_hash!(labels) unless labels.empty?
|
|
30
32
|
@script = script
|
|
31
33
|
end
|
|
32
34
|
|
|
@@ -6,6 +6,10 @@ module Relaton
|
|
|
6
6
|
# places the inventory's data elements (clause 7) in each resource
|
|
7
7
|
# kind's order (clause 8); the engine is a template evaluator over a
|
|
8
8
|
# field resolver and holds no styles, no vocabularies, no i18n.
|
|
9
|
+
# The v1 compatibility facade (relaton-render#90): isodoc's
|
|
10
|
+
# render-isodoc subclasses Relaton::Render::General.
|
|
11
|
+
autoload :General, "relaton/render/general"
|
|
12
|
+
|
|
9
13
|
module Iso690
|
|
10
14
|
autoload :Element, "relaton/render/iso690/element"
|
|
11
15
|
autoload :Elements, "relaton/render/iso690/elements"
|
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
|
|
@@ -54,6 +54,7 @@ files:
|
|
|
54
54
|
- lib/isodoc-yaml/i18n-zh-Hant.yaml
|
|
55
55
|
- lib/isodoc/i18n.rb
|
|
56
56
|
- lib/relaton-render.rb
|
|
57
|
+
- lib/relaton/render/general.rb
|
|
57
58
|
- lib/relaton/render/iso690.rb
|
|
58
59
|
- lib/relaton/render/iso690/element.rb
|
|
59
60
|
- lib/relaton/render/iso690/elements.rb
|