relaton-render 1.0.3 → 1.0.5
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/fields/fields.rb +4 -2
- data/lib/relaton/render/general/citations.rb +19 -9
- data/lib/relaton/render/general/config.yml +3 -3
- data/lib/relaton/render/general/render.rb +1 -1
- data/lib/relaton/render/template/subclasses.rb +8 -2
- data/lib/relaton/render/template/template.rb +17 -9
- 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: b834b958e0a0c893b641087a171141972d18626cd01c66bce85e29a898d4fa40
|
|
4
|
+
data.tar.gz: 44b06318fdd7c00cca50fb0b309a84faaa26f914bade814f2a4389998076e7a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd66e65e6a282d5926701f28965bcb6e857acc4fb675936effd18e7c40b957c9ec645522bdbea2ff50f7f12b5db44bddb1a3d66b1ca986b113b9cba38bd0a8fc
|
|
7
|
+
data.tar.gz: ad226183da8ff58d03f8b8cc75e9795b20a503f5c73adb6df6210f5c95382da1992a51d86a19acd526c38977d010437bc64171943704ce15f8c7586af9558af1
|
|
@@ -82,11 +82,13 @@ module Relaton
|
|
|
82
82
|
@r.i18n.select(hash).get.dig("stage", status) || status
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# date => disambiguated_date, the disambiguation happens in citations/
|
|
85
86
|
def date_fields_format(hash)
|
|
86
|
-
[%i(date date), %i(
|
|
87
|
+
[%i(date date), %i(disambiguated_date date),
|
|
88
|
+
%i(date_updated date_updated),
|
|
87
89
|
%i(date_accessed date_accessed)].each do |k|
|
|
88
90
|
hash[k[0]] = dateformat(hash[k[1]], hash, k)
|
|
89
|
-
k[
|
|
91
|
+
k[1] == :date &&
|
|
90
92
|
!%w(standard webresource website).include?(hash[:type]) and
|
|
91
93
|
hash[k[0]] ||= @r.i18n.select(nil).get["no_date"]
|
|
92
94
|
end
|
|
@@ -94,8 +94,8 @@ module Relaton
|
|
|
94
94
|
i = @i18n.select(b[:data])
|
|
95
95
|
b[:citation][:default] =
|
|
96
96
|
i.l10n(b[:data][:authoritative_identifier]&.first || "")
|
|
97
|
-
b[:
|
|
98
|
-
|
|
97
|
+
d = b[:data].merge(citestyle: "short")
|
|
98
|
+
b[:citation][:short] = i.l10n(renderer(b).citeshorttemplate.render(d, d))
|
|
99
99
|
citations_iterate_cite_styles(b, i)
|
|
100
100
|
end
|
|
101
101
|
ret
|
|
@@ -135,20 +135,29 @@ module Relaton
|
|
|
135
135
|
def suffix_date(ret)
|
|
136
136
|
ret.each do |k, v|
|
|
137
137
|
v.each do |k1, v1|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
suffix_date1(ret, k, k1)
|
|
138
|
+
s = v1.reject { |b| b[:date].nil? }.size
|
|
139
|
+
s.zero? || k.nil? and next
|
|
140
|
+
suffix_date1(ret, k, k1, s)
|
|
141
|
+
copy_date_fields(ret, k, k1)
|
|
141
142
|
end
|
|
142
143
|
end
|
|
143
144
|
ret
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def suffix_date1(ret, key1, key2)
|
|
147
|
-
|
|
147
|
+
def suffix_date1(ret, key1, key2, size)
|
|
148
|
+
size > 1 or return
|
|
148
149
|
ret[key1][key2].each_with_index do |b, i|
|
|
149
150
|
b[:date].nil? and next
|
|
150
|
-
b[:date]
|
|
151
|
+
b[:disambiguated_date] = b[:date] + ("a".ord + i).chr.to_s
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def copy_date_fields(ret, key1, key2)
|
|
156
|
+
ret[key1][key2].each do |b|
|
|
157
|
+
b[:date].nil? and next
|
|
151
158
|
b[:data][:date] = b[:date]
|
|
159
|
+
b[:disambiguated_date] ||= b[:date]
|
|
160
|
+
b[:data][:disambiguated_date] = b[:disambiguated_date]
|
|
152
161
|
end
|
|
153
162
|
end
|
|
154
163
|
|
|
@@ -157,7 +166,8 @@ module Relaton
|
|
|
157
166
|
v.each_value do |v1|
|
|
158
167
|
v1.each do |b|
|
|
159
168
|
m[b[:id]] = { author: @i18n.select(b[:data]).l10n(b[:author]),
|
|
160
|
-
date: b[:
|
|
169
|
+
date: b[:disambiguated_date] || b[:date],
|
|
170
|
+
citation: {},
|
|
161
171
|
data: b[:data], type: b[:type] }
|
|
162
172
|
end
|
|
163
173
|
end
|
|
@@ -37,10 +37,10 @@ language: en
|
|
|
37
37
|
script: Latn
|
|
38
38
|
|
|
39
39
|
citetemplate:
|
|
40
|
-
author_date: "{{ author }} {{
|
|
41
|
-
author_date_br: "{{ author }} ({{
|
|
40
|
+
author_date: "{{ author }} {{ disambiguated_date}}"
|
|
41
|
+
author_date_br: "{{ author }} ({{ disambiguated_date}})"
|
|
42
42
|
author: "{{ author }}"
|
|
43
|
-
date: "{{
|
|
43
|
+
date: "{{ disambiguated_date }}"
|
|
44
44
|
reference_tag: "{{ biblio_tag }}"
|
|
45
45
|
title: "{{ title }}"
|
|
46
46
|
title_reference_tag: "{{ title }} {{ biblio_tag }}"
|
|
@@ -48,7 +48,6 @@ module Relaton
|
|
|
48
48
|
# ...[0], ...[1], ...[2]
|
|
49
49
|
def expand_nametemplate(template, size)
|
|
50
50
|
t = nametemplate_split(template)
|
|
51
|
-
|
|
52
51
|
mid = (1..size - 2).each_with_object([]) do |i, m|
|
|
53
52
|
m << t[1].gsub("[1]", "[#{i}]")
|
|
54
53
|
end
|
|
@@ -68,6 +67,7 @@ module Relaton
|
|
|
68
67
|
def nametemplate_split(template)
|
|
69
68
|
curr = 0
|
|
70
69
|
prec = ""
|
|
70
|
+
@in_name = 0
|
|
71
71
|
t = template.split(/(\{[{%][^{]+?[}%]\})/)
|
|
72
72
|
.each_with_object([""]) do |n, m|
|
|
73
73
|
m, curr, prec = nametemplate_split1(n, m, curr, prec)
|
|
@@ -79,6 +79,9 @@ module Relaton
|
|
|
79
79
|
|
|
80
80
|
def nametemplate_split1(elem, acc, curr, prec)
|
|
81
81
|
if match = /\{[{%].+?\[(\d)\]/.match(elem)
|
|
82
|
+
# we are in a name component
|
|
83
|
+
# if an if is started, track the if nesting...
|
|
84
|
+
@in_name += 1 if /\{%\s*if/.match?(elem)
|
|
82
85
|
if match[1].to_i > curr
|
|
83
86
|
curr += 1
|
|
84
87
|
acc[curr] ||= ""
|
|
@@ -86,7 +89,10 @@ module Relaton
|
|
|
86
89
|
acc[curr] += prec
|
|
87
90
|
prec = ""
|
|
88
91
|
acc[curr] += elem
|
|
89
|
-
elsif /\{%\s*endif/.match?(elem)
|
|
92
|
+
elsif /\{%\s*endif/.match?(elem) && @in_name.positive?
|
|
93
|
+
# stick the endif to the currently if-nested name component,
|
|
94
|
+
# if we are in one (@in_name.positive?)
|
|
95
|
+
@in_name -= 1
|
|
90
96
|
acc[curr] += prec
|
|
91
97
|
prec = ""
|
|
92
98
|
acc[curr] += elem
|
|
@@ -115,10 +115,12 @@ module Relaton
|
|
|
115
115
|
# potentially enhanced
|
|
116
116
|
def render(hash, context)
|
|
117
117
|
t = template_select(hash) or return nil # TODO select on context?
|
|
118
|
-
i = @i18n.select(context)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
i = @i18n.select(context)
|
|
119
|
+
i18nsettings = { "labels" => i.get, "lang" => i.lang,
|
|
120
|
+
"script" => i.script, "locale" => i.locale }
|
|
121
|
+
ret = template_clean(t.render(liquid_hash(hash.merge(i18nsettings))))
|
|
122
|
+
bib_delim = i.get.dig("punct", "biblio-field-delimiter") || ". "
|
|
123
|
+
template_components(ret, bib_delim, context)
|
|
122
124
|
end
|
|
123
125
|
|
|
124
126
|
def template_select(_hash)
|
|
@@ -172,17 +174,23 @@ module Relaton
|
|
|
172
174
|
# Do not strip any delimiters from final field in string
|
|
173
175
|
#
|
|
174
176
|
# if delim = ". " , then: ({{ series }}$$$|) => (series1.)
|
|
175
|
-
def template_components(str, delim)
|
|
177
|
+
def template_components(str, delim, context)
|
|
176
178
|
str or return str
|
|
177
179
|
delimrstrip, delimre, delimrstripre = template_components_prep(delim)
|
|
180
|
+
ret = template_components_split(str, delimre)
|
|
181
|
+
delim != delimrstrip and # "." in field followed by ". " in delim
|
|
182
|
+
ret = remove_double_period(ret, delimrstripre)
|
|
183
|
+
context[:citestyle] == "short" and
|
|
184
|
+
ret[0] += "<span class='fmt-first-biblio-delim'/>"
|
|
185
|
+
ret.join(delim).gsub(/#{delim}\|/, delimrstrip)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def template_components_split(str, delimre)
|
|
178
189
|
ret = str.gsub(NON_SPACING_DELIM, "|").split(/#{COMPONENT_DELIM}/o)
|
|
179
190
|
.map(&:strip).reject(&:empty?)
|
|
180
|
-
ret
|
|
191
|
+
ret[0...-1].map do |s|
|
|
181
192
|
s.sub(/#{delimre}$/, "").sub(%r[#{delimre}(</[^>]+>)$], "\\1")
|
|
182
193
|
end + [ret.last]
|
|
183
|
-
delim != delimrstrip and # "." in field followed by ". " in delim
|
|
184
|
-
ret = remove_double_period(ret, delimrstripre)
|
|
185
|
-
ret.join(delim).gsub(/#{delim}\|/, delimrstrip)
|
|
186
194
|
end
|
|
187
195
|
|
|
188
196
|
def remove_double_period(ret, delimrstripre)
|
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.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|