relaton-render 0.10.2 → 1.0.0
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/isodoc-yaml/i18n-ar.yaml +6 -4
- data/lib/isodoc-yaml/i18n-de.yaml +6 -4
- data/lib/isodoc-yaml/i18n-en.yaml +6 -4
- data/lib/isodoc-yaml/i18n-es.yaml +6 -4
- data/lib/isodoc-yaml/i18n-fr.yaml +6 -4
- data/lib/isodoc-yaml/i18n-ja.yaml +7 -4
- data/lib/isodoc-yaml/i18n-ru.yaml +6 -4
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +7 -4
- data/lib/isodoc-yaml/i18n-zh-Hant.yaml +7 -4
- data/lib/relaton/render/fields/date.rb +1 -0
- data/lib/relaton/render/fields/fields.rb +95 -54
- data/lib/relaton/render/general/citations.rb +64 -34
- data/lib/relaton/render/general/config.yml +60 -11
- data/lib/relaton/render/general/render.rb +66 -24
- data/lib/relaton/render/general/render_classes.rb +4 -1
- data/lib/relaton/render/i18n/i18n.rb +40 -0
- data/lib/relaton/render/parse/parse.rb +41 -13
- data/lib/relaton/render/parse/parse_contributors.rb +4 -10
- data/lib/relaton/render/parse/parse_extract.rb +21 -4
- data/lib/relaton/render/parse/parse_id.rb +11 -4
- data/lib/relaton/render/template/liquid.rb +18 -12
- data/lib/relaton/render/template/subclasses.rb +117 -0
- data/lib/relaton/render/template/template.rb +78 -122
- data/lib/relaton/render/version.rb +1 -1
- data/lib/relaton-render.rb +1 -0
- data/relaton-render.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9cec3f38cf2f0d1a1551a569b758e55e26114ff09e57dfe1d56042fc6f90d9c0
|
|
4
|
+
data.tar.gz: 8d5c2413e975f8c27c12a9ec9a4b906e714de5b8a3d58c24f378f1ad30de9d9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 363654ad4adf20d8330ad8f17d398051b410962351763ea7d25b1489cfc32675b770237d5c20951e954bb155c01ca378d9b770a043a315d78cfe4eee7962075b
|
|
7
|
+
data.tar.gz: a3e7c9f9015ee5bf9a0e380432d01d0bf9139a523c4c2a6a95d57d0776fa9097cc7c08fe1ab8b47be1ff6d5fee10573b3995e84164c367af4f70589668feaf65
|
|
@@ -15,6 +15,7 @@ date_formats:
|
|
|
15
15
|
ordinal_keys: []
|
|
16
16
|
OrdinalRules: digits-ordinal
|
|
17
17
|
edition_ordinal: "الطبعة {{ var1 | ordinal_num: 'edition', '' }}"
|
|
18
|
+
edition_cardinal: "الطبعة {{ var }}"
|
|
18
19
|
edition: الطبعة
|
|
19
20
|
draft: "مشروع %"
|
|
20
21
|
editor:
|
|
@@ -43,10 +44,11 @@ size:
|
|
|
43
44
|
issue:
|
|
44
45
|
sg: "% عدد"
|
|
45
46
|
pl: "% عدد"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
punct:
|
|
48
|
+
open-title: «
|
|
49
|
+
close-title: »
|
|
50
|
+
open-secondary-title:
|
|
51
|
+
close-secondary-title:
|
|
50
52
|
inflection:
|
|
51
53
|
الطبعة:
|
|
52
54
|
grammar:
|
|
@@ -14,6 +14,7 @@ date_formats:
|
|
|
14
14
|
date_time: to_long_s
|
|
15
15
|
draft: "Entwurf %"
|
|
16
16
|
edition_ordinal: "{{ var1 }} Ausg."
|
|
17
|
+
edition_cardinal: "Ausg. {{ var1 }}"
|
|
17
18
|
ordinal_keys: []
|
|
18
19
|
edition: Ausgabe
|
|
19
20
|
editor:
|
|
@@ -29,10 +30,11 @@ extent:
|
|
|
29
30
|
issue:
|
|
30
31
|
sg: "Nr. %"
|
|
31
32
|
pl: "Nr. %"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
punct:
|
|
34
|
+
open-title: <em>
|
|
35
|
+
close-title: </em>
|
|
36
|
+
open-secondary-title:
|
|
37
|
+
close-secondary-title:
|
|
36
38
|
stage:
|
|
37
39
|
valid: Gültig
|
|
38
40
|
withdrawn: Zurückgezogen
|
|
@@ -16,14 +16,16 @@ ordinal_keys: []
|
|
|
16
16
|
OrdinalRules: digits-ordinal
|
|
17
17
|
edition: edition
|
|
18
18
|
edition_ordinal: "{{ var1 | ordinal_num: '', '' }} edition"
|
|
19
|
+
edition_cardinal: "Edition {{ var1 }}"
|
|
19
20
|
draft: "draft %"
|
|
20
21
|
editor:
|
|
21
22
|
sg: ed.
|
|
22
23
|
pl: eds.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
punct:
|
|
25
|
+
open-title: <em>
|
|
26
|
+
close-title: </em>
|
|
27
|
+
open-secondary-title:
|
|
28
|
+
close-secondary-title:
|
|
27
29
|
stage:
|
|
28
30
|
valid: Valid
|
|
29
31
|
withdrawn: Withdrawn
|
|
@@ -17,15 +17,17 @@ OrdinalRules:
|
|
|
17
17
|
m: digits-ordinal-masculine
|
|
18
18
|
f: digits-ordinal-feminine
|
|
19
19
|
edition_ordinal: "{{ var1 | ordinal_num: 'edition', '' }} ed."
|
|
20
|
+
edition_cardinal: "Ed. {{ var1 }}"
|
|
20
21
|
edition: edición
|
|
21
22
|
draft: "borrador %"
|
|
22
23
|
editor:
|
|
23
24
|
sg: ed.
|
|
24
25
|
pl: eds.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
punct:
|
|
27
|
+
open-title: <em>
|
|
28
|
+
close-title: </em>
|
|
29
|
+
open-secondary-title:
|
|
30
|
+
close-secondary-title:
|
|
29
31
|
stage:
|
|
30
32
|
valid: Válido
|
|
31
33
|
withdrawn: Retirado
|
|
@@ -19,15 +19,17 @@ OrdinalRules:
|
|
|
19
19
|
m.pl: digits-ordinal-masculine-plural
|
|
20
20
|
f.pl: digits-ordinal-feminine-plural
|
|
21
21
|
edition_ordinal: "{{ var1 | ordinal_num: 'edition', '' }} édition"
|
|
22
|
+
edition_cardinal: "Édition {{ var1 }}"
|
|
22
23
|
edition: édition
|
|
23
24
|
draft: "brouillon %"
|
|
24
25
|
editor:
|
|
25
26
|
sg: éd.
|
|
26
27
|
pl: éd.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
punct:
|
|
29
|
+
open-title: <em>
|
|
30
|
+
close-title: </em>
|
|
31
|
+
open-secondary-title:
|
|
32
|
+
close-secondary-title:
|
|
31
33
|
stage:
|
|
32
34
|
valid: Valide
|
|
33
35
|
withdrawn: Retiré
|
|
@@ -16,14 +16,17 @@ ordinal_keys: []
|
|
|
16
16
|
OrdinalRules: digits-ordinal
|
|
17
17
|
edition: 版
|
|
18
18
|
edition_ordinal: "第{{ var1 }}版"
|
|
19
|
+
edition_cardinal: "第{{ var1 }}版"
|
|
19
20
|
draft: "下書き %"
|
|
20
21
|
editor:
|
|
21
22
|
sg: 編
|
|
22
23
|
pl: 編
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
punct:
|
|
25
|
+
open-title:
|
|
26
|
+
close-title:
|
|
27
|
+
open-secondary-title:
|
|
28
|
+
close-secondary-title:
|
|
29
|
+
biblio-terminator: "。"
|
|
27
30
|
stage:
|
|
28
31
|
valid: 有効です
|
|
29
32
|
withdrawn: 取り消されました
|
|
@@ -21,15 +21,17 @@ SpelloutRules:
|
|
|
21
21
|
f.pl: spellout-ordinal-plural
|
|
22
22
|
n.pl: spellout-ordinal-plural
|
|
23
23
|
edition_ordinal: "{{ var1 | ordinal_word: 'edition', '' }} издание"
|
|
24
|
+
edition_cardinal: "Издание {{ var1 }}"
|
|
24
25
|
edition: издание
|
|
25
26
|
draft: "проект %"
|
|
26
27
|
editor:
|
|
27
28
|
sg: изд.
|
|
28
29
|
pl: изд.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
punct:
|
|
31
|
+
open-title: <em>
|
|
32
|
+
close-title: </em>
|
|
33
|
+
open-secondary-title:
|
|
34
|
+
close-secondary-title:
|
|
33
35
|
stage:
|
|
34
36
|
valid: Действительный
|
|
35
37
|
withdrawn: Снято
|
|
@@ -16,15 +16,18 @@ ordinal_keys: []
|
|
|
16
16
|
OrdinalRules: digits-ordinal
|
|
17
17
|
SpelloutRules: spellout-ordinal
|
|
18
18
|
edition_ordinal: "第{{ var1 | ordinal_num: '', '' }}版"
|
|
19
|
+
edition_cardinal: "第{{ var1 }}版"
|
|
19
20
|
edition: 版
|
|
20
21
|
draft: "草案%"
|
|
21
22
|
editor:
|
|
22
23
|
sg: 编
|
|
23
24
|
pl: 编
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
punct:
|
|
26
|
+
open-title: 《
|
|
27
|
+
close-title: 》
|
|
28
|
+
open-secondary-title: 〈
|
|
29
|
+
close-secondary-title: 〉
|
|
30
|
+
biblio-terminator: "。"
|
|
28
31
|
stage:
|
|
29
32
|
valid: 有效
|
|
30
33
|
withdrawn: 已撤回
|
|
@@ -15,15 +15,18 @@ date_formats:
|
|
|
15
15
|
ordinal_keys: []
|
|
16
16
|
OrdinalRules: digits-ordinal
|
|
17
17
|
edition_ordinal: "第{{ var1 | ordinal_num: '', '' }}版"
|
|
18
|
+
edition_cardinal: "第{{ var1 }}版"
|
|
18
19
|
edition: 版
|
|
19
20
|
draft: "草案%"
|
|
20
21
|
editor:
|
|
21
22
|
sg: 編輯
|
|
22
23
|
pl: 編輯
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
punct:
|
|
25
|
+
open-title: <underline style="wavy">
|
|
26
|
+
close-title: </underline>
|
|
27
|
+
open-secondary-title: 〈
|
|
28
|
+
close-secondary-title: 〉
|
|
29
|
+
biblio-terminator: "。"
|
|
27
30
|
stage:
|
|
28
31
|
valid: 有效的
|
|
29
32
|
withdrawn: 取消
|
|
@@ -7,81 +7,114 @@ module Relaton
|
|
|
7
7
|
@r = options[:renderer]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
# the @i18n.select choices here need to rely on
|
|
11
|
+
# fields already present, they can't rely on fields they are yet to build
|
|
10
12
|
def compound_fields_format(hash)
|
|
11
13
|
name_fields_format(hash)
|
|
12
14
|
role_fields_format(hash)
|
|
13
15
|
date_fields_format(hash)
|
|
14
16
|
edition_fields_format(hash)
|
|
17
|
+
place_fields_format(hash)
|
|
18
|
+
series_fields_format(hash)
|
|
15
19
|
misc_fields_format(hash)
|
|
16
20
|
end
|
|
17
21
|
|
|
22
|
+
def comma(hash)
|
|
23
|
+
"#{@r.i18n.select(hash).get.dig('punct', 'comma') || ','} "
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def place_fields_format(hash)
|
|
27
|
+
hash[:place_raw]&.map! do |p|
|
|
28
|
+
# TODO use enum-comma?
|
|
29
|
+
if p.is_a?(Array)
|
|
30
|
+
p.join(comma(hash))
|
|
31
|
+
else p
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
hash[:place] =
|
|
35
|
+
nameformat(hash[:place_raw].map { |x| { nonpersonal: x } }, hash)
|
|
36
|
+
end
|
|
37
|
+
|
|
18
38
|
def name_fields_format(hash)
|
|
19
39
|
[%i(creatornames creators), %i(host_creatornames host_creators),
|
|
20
40
|
%i(publisher publisher_raw), %i(distributor distributor_raw),
|
|
21
41
|
%i(authorizer authorizer_raw)]
|
|
22
42
|
.each do |k|
|
|
23
|
-
hash[k[0]] = nameformat(hash[k[1]])
|
|
43
|
+
hash[k[0]] = nameformat(hash[k[1]], hash)
|
|
24
44
|
end
|
|
25
|
-
hash[:publisher_abbrev] = hash[:publisher_abbrev_raw]&.join(
|
|
26
|
-
hash[:authorcite] = authorciteformat(hash[:creators])
|
|
27
|
-
place_format(hash)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def place_format(hash)
|
|
31
|
-
hash[:place] =
|
|
32
|
-
nameformat(hash[:place_raw].map { |x| { nonpersonal: x } })
|
|
45
|
+
hash[:publisher_abbrev] = hash[:publisher_abbrev_raw]&.join(comma(hash))
|
|
46
|
+
hash[:authorcite] = authorciteformat(hash[:creators], hash)
|
|
33
47
|
end
|
|
34
48
|
|
|
35
49
|
def role_fields_format(hash)
|
|
36
|
-
hash[:role] = role_inflect(hash[:creators], hash[:role_raw])
|
|
50
|
+
hash[:role] = role_inflect(hash[:creators], hash[:role_raw], hash)
|
|
37
51
|
hash[:host_role] =
|
|
38
|
-
role_inflect(hash[:host_creators], hash[:host_role_raw])
|
|
52
|
+
role_inflect(hash[:host_creators], hash[:host_role_raw], hash)
|
|
39
53
|
end
|
|
40
54
|
|
|
41
55
|
def edition_fields_format(hash)
|
|
42
|
-
hash[:edition] =
|
|
56
|
+
hash[:edition] =
|
|
57
|
+
editionformat(hash[:edition_raw], hash[:edition_num], hash)
|
|
43
58
|
hash[:draft] = draftformat(hash[:draft_raw], hash)
|
|
44
59
|
end
|
|
45
60
|
|
|
46
61
|
def misc_fields_format(hash)
|
|
47
|
-
hash[:
|
|
48
|
-
hash[:medium] = mediumformat(hash[:medium_raw])
|
|
62
|
+
hash[:medium] = mediumformat(hash[:medium_raw], hash)
|
|
49
63
|
hash[:extent] = extentformat(hash[:extent_raw], hash)
|
|
50
64
|
hash[:size] = sizeformat(hash[:size_raw], hash)
|
|
51
65
|
hash[:uri] = uriformat(hash[:uri_raw])
|
|
66
|
+
hash[:status] = statusformat(hash[:status_raw], hash)
|
|
67
|
+
hash[:other_identifier] =
|
|
68
|
+
otheridentifierformat(hash[:other_identifier_raw], hash)
|
|
52
69
|
hash
|
|
53
70
|
end
|
|
54
71
|
|
|
72
|
+
def otheridentifierformat(otherids, _hash)
|
|
73
|
+
otherids&.map do |i|
|
|
74
|
+
# ret = "#{i[0]}: <esc>#{i[1]}</esc>"
|
|
75
|
+
# @r.i18n.select(hash).l10n(ret) # no i18n!
|
|
76
|
+
"#{i[0]}: #{i[1]}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def statusformat(status, hash)
|
|
81
|
+
status.nil? and return
|
|
82
|
+
@r.i18n.select(hash).get.dig("stage", status) || status
|
|
83
|
+
end
|
|
84
|
+
|
|
55
85
|
def date_fields_format(hash)
|
|
56
86
|
[%i(date date), %i(date_updated date_updated),
|
|
57
87
|
%i(date_accessed date_accessed)].each do |k|
|
|
58
88
|
hash[k[0]] = dateformat(hash[k[1]], hash, k)
|
|
59
89
|
k[0] == :date &&
|
|
60
90
|
!%w(standard webresource website).include?(hash[:type]) and
|
|
61
|
-
hash[k[0]] ||= @r.i18n.get["no_date"]
|
|
91
|
+
hash[k[0]] ||= @r.i18n.select(nil).get["no_date"]
|
|
62
92
|
end
|
|
63
93
|
end
|
|
64
94
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
m <<
|
|
95
|
+
def mediumformat(medium, hash)
|
|
96
|
+
medium.nil? and return nil
|
|
97
|
+
ret = %w(content genre form carrier size
|
|
98
|
+
scale).each_with_object([]) do |i, m|
|
|
99
|
+
m << "<esc>#{medium[i]}</esc>" if medium[i]
|
|
70
100
|
m
|
|
71
|
-
end.compact
|
|
101
|
+
end.compact
|
|
102
|
+
i = @r.i18n.select(hash)
|
|
103
|
+
i.l10n(ret.join(comma(hash)))
|
|
72
104
|
end
|
|
73
105
|
|
|
74
|
-
def
|
|
75
|
-
parts =
|
|
76
|
-
|
|
106
|
+
def series_fields_format(hash)
|
|
107
|
+
parts =
|
|
108
|
+
%i(series_title series_abbr series_num series_partnumber
|
|
109
|
+
series_run series_formatted series_dates series_place series_org)
|
|
77
110
|
series_out = parts.each_with_object({}) do |i, m|
|
|
78
111
|
m[i] = hash[i]
|
|
79
112
|
end
|
|
80
113
|
t = hash[:type] == "article" ? @r.journaltemplate : @r.seriestemplate
|
|
81
|
-
t.render(series_out)
|
|
114
|
+
hash[:series] = t.render(series_out, hash)
|
|
82
115
|
end
|
|
83
116
|
|
|
84
|
-
def nameformat(names)
|
|
117
|
+
def nameformat(names, hash)
|
|
85
118
|
names.nil? and return names
|
|
86
119
|
parts = %i(surname initials given middle nonpersonal)
|
|
87
120
|
names_out = names.each_with_object({}) do |n, m|
|
|
@@ -90,10 +123,10 @@ module Relaton
|
|
|
90
123
|
m[i] << n[i]
|
|
91
124
|
end
|
|
92
125
|
end
|
|
93
|
-
@r.nametemplate.render(names_out)
|
|
126
|
+
@r.nametemplate.render(names_out, hash)
|
|
94
127
|
end
|
|
95
128
|
|
|
96
|
-
def authorciteformat(names)
|
|
129
|
+
def authorciteformat(names, hash)
|
|
97
130
|
names.nil? || @r.authorcitetemplate.nil? and return names
|
|
98
131
|
parts = %i(surname initials given middle nonpersonal)
|
|
99
132
|
names_out = names.each_with_object({}) do |n, m|
|
|
@@ -102,48 +135,53 @@ module Relaton
|
|
|
102
135
|
m[i] << n[i]
|
|
103
136
|
end
|
|
104
137
|
end
|
|
105
|
-
@r.authorcitetemplate.render(names_out)
|
|
138
|
+
@r.authorcitetemplate.render(names_out, hash)
|
|
106
139
|
end
|
|
107
140
|
|
|
108
|
-
def role_inflect(contribs, role)
|
|
141
|
+
def role_inflect(contribs, role, hash)
|
|
109
142
|
role.nil? || contribs.empty? ||
|
|
110
143
|
%w(author publisher distributor
|
|
111
144
|
authorizer).include?(role) and return nil
|
|
112
145
|
number = contribs.size > 1 ? "pl" : "sg"
|
|
113
|
-
x = @r.i18n.get[role]
|
|
146
|
+
x = @r.i18n.select(hash).get[role]
|
|
114
147
|
x.is_a?(Hash) or return role
|
|
115
148
|
x[number] || role
|
|
116
149
|
end
|
|
117
150
|
|
|
118
|
-
def editionformat(edn, num)
|
|
119
|
-
num ||
|
|
120
|
-
|
|
151
|
+
def editionformat(edn, num, hash)
|
|
152
|
+
num || edn && !edn.empty? or return
|
|
153
|
+
edn_num = edn&.gsub(/<\/?esc>/, "")
|
|
154
|
+
num || /^\d+$/.match?(edn_num) and
|
|
155
|
+
return @r.i18n.select(hash)
|
|
156
|
+
.populate("edition_ordinal", { "var1" => num || edn_num.to_i })
|
|
157
|
+
@r.i18n.select(hash).populate("edition_cardinal", { "var1" => edn })
|
|
121
158
|
end
|
|
122
159
|
|
|
123
|
-
def draftformat(num,
|
|
160
|
+
def draftformat(num, hash)
|
|
124
161
|
num.nil? ||
|
|
125
162
|
(num.is_a?(Hash) && num[:status].nil? &&
|
|
126
163
|
num[:iteration].nil?) and return nil
|
|
127
|
-
@r.i18n.draft.sub("%", num)
|
|
164
|
+
@r.i18n.select(hash).draft.sub("%", num)
|
|
128
165
|
end
|
|
129
166
|
|
|
130
167
|
def extentformat(extent, hash)
|
|
131
168
|
extent.map do |stack|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
169
|
+
stack.map do |e|
|
|
170
|
+
e1 = e.transform_values { |v| v.is_a?(Hash) ? range(v) : v }
|
|
171
|
+
ret = e.each_with_object({}) do |(k, v), m|
|
|
172
|
+
extentformat1(k, v, m, e1, hash)
|
|
173
|
+
m
|
|
174
|
+
end
|
|
175
|
+
@r.extenttemplate.render(hash.merge(ret), hash)
|
|
176
|
+
end.join(" ")
|
|
140
177
|
end.join("; ")
|
|
141
178
|
end
|
|
142
179
|
|
|
143
|
-
def extentformat1(key, val, hash, norm_hash)
|
|
180
|
+
def extentformat1(key, val, hash, norm_hash, context)
|
|
144
181
|
if %i(volume issue page).include?(key)
|
|
145
182
|
hash["#{key}_raw".to_sym] = norm_hash[key]
|
|
146
|
-
hash[key] =
|
|
183
|
+
hash[key] =
|
|
184
|
+
pagevolformat(norm_hash[key], val, key.to_s, false, context)
|
|
147
185
|
end
|
|
148
186
|
end
|
|
149
187
|
|
|
@@ -159,25 +197,27 @@ module Relaton
|
|
|
159
197
|
def sizeformat(size, hash)
|
|
160
198
|
return nil unless size
|
|
161
199
|
|
|
162
|
-
ret = size.transform_values
|
|
200
|
+
ret = size.transform_values do |v|
|
|
201
|
+
@r.i18n.select(hash).l10n(v.join(" + "))
|
|
202
|
+
end
|
|
163
203
|
.each_with_object({}) do |(k, v), m|
|
|
164
|
-
sizeformat1(k, v, m)
|
|
204
|
+
sizeformat1(k, v, m, hash)
|
|
165
205
|
m
|
|
166
206
|
end
|
|
167
|
-
@r.sizetemplate.render(ret.merge(type: hash[:type]))
|
|
207
|
+
@r.sizetemplate.render(ret.merge(type: hash[:type]), hash)
|
|
168
208
|
end
|
|
169
209
|
|
|
170
|
-
def sizeformat1(key, val, hash)
|
|
210
|
+
def sizeformat1(key, val, hash, context)
|
|
171
211
|
case key
|
|
172
212
|
when "volume", "issue", "page"
|
|
173
213
|
hash["#{key}_raw".to_sym] = val
|
|
174
|
-
hash[key.to_sym] = pagevolformat(val, nil, key, true)
|
|
214
|
+
hash[key.to_sym] = pagevolformat(val, nil, key, true, context)
|
|
175
215
|
when "data" then hash[:data] = val
|
|
176
216
|
when "duration" then hash[:duration] = val
|
|
177
217
|
end
|
|
178
218
|
end
|
|
179
219
|
|
|
180
|
-
def pagevolformat(value, value_raw, type, is_size)
|
|
220
|
+
def pagevolformat(value, value_raw, type, is_size, hash)
|
|
181
221
|
value.nil? and return nil
|
|
182
222
|
num = "pl"
|
|
183
223
|
if is_size
|
|
@@ -185,8 +225,9 @@ module Relaton
|
|
|
185
225
|
else
|
|
186
226
|
value_raw[:to] or num = "sg"
|
|
187
227
|
end
|
|
188
|
-
@r.i18n.
|
|
189
|
-
|
|
228
|
+
i = @r.i18n.select(hash)
|
|
229
|
+
i.l10n(i.get[is_size ? "size" : "extent"][type][num]
|
|
230
|
+
.sub("%", value))
|
|
190
231
|
end
|
|
191
232
|
|
|
192
233
|
def date_range(hash)
|
|
@@ -2,17 +2,21 @@ module Relaton
|
|
|
2
2
|
module Render
|
|
3
3
|
class Citations
|
|
4
4
|
def initialize(opt = {})
|
|
5
|
-
|
|
5
|
+
# invoking i18n hash, but we preference the specific renderer's i18n
|
|
6
6
|
@i18n = opt[:i18n]
|
|
7
|
+
@lang = opt[:lang] # document lang and script
|
|
8
|
+
@script = opt[:script]
|
|
9
|
+
# hash of renderers, to be applied to specific citation by selector
|
|
7
10
|
@renderer = opt[:renderer]
|
|
8
11
|
end
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
def renderer(_cite)
|
|
14
|
+
@renderer[:default]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# takes array of { id, type, author, date, ord, data }
|
|
11
18
|
def render(ret)
|
|
12
19
|
cites = citations(ret)
|
|
13
|
-
cites.each_value do |v|
|
|
14
|
-
v[:renderer] = @renderer.renderer(v[:type] || "misc")
|
|
15
|
-
end
|
|
16
20
|
enhance_data(cites)
|
|
17
21
|
cites.each_key do |k|
|
|
18
22
|
cites[k] = render1(cites[k])
|
|
@@ -38,8 +42,8 @@ module Relaton
|
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
def extract_uri_for_lookup(cite)
|
|
41
|
-
t = cite[:
|
|
42
|
-
c = cite[:
|
|
45
|
+
t = renderer(cite).renderer(cite[:type] || "misc").template_raw
|
|
46
|
+
c = cite[:data]
|
|
43
47
|
t.is_a?(String) or return
|
|
44
48
|
(/\{\{\s*date_accessed\s*\}\}/.match?(t) &&
|
|
45
49
|
/\{\{\s*uri\s*\}\}/.match?(t) &&
|
|
@@ -47,46 +51,72 @@ module Relaton
|
|
|
47
51
|
c[:uri_raw]
|
|
48
52
|
end
|
|
49
53
|
|
|
50
|
-
def add_date_accessed(
|
|
54
|
+
def add_date_accessed(cite, uri, status)
|
|
55
|
+
r = renderer(cite)
|
|
51
56
|
if status
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.compound_fields_format(
|
|
57
|
+
cite[:data][:date_accessed] = { on: ::Date.today.to_s }
|
|
58
|
+
cite[:data] = r.fieldsklass.new(renderer: r)
|
|
59
|
+
.compound_fields_format(cite[:data])
|
|
55
60
|
else
|
|
56
|
-
|
|
61
|
+
r.url_warn(uri)
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
def render1(cit)
|
|
66
|
+
ref, ref1, r = render1_prep(cit)
|
|
67
|
+
i = @i18n.select(cit[:data])
|
|
61
68
|
cit[:formattedref] =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
%i(type data_liquid renderer).each { |x| cit.delete(x) }
|
|
69
|
+
r.valid_parse(i.l10n(ref1))
|
|
70
|
+
cit[:citation][:full] = r.valid_parse(i.l10n(ref))
|
|
71
|
+
%i(type data renderer).each { |x| cit.delete(x) }
|
|
66
72
|
cit
|
|
67
73
|
end
|
|
68
74
|
|
|
75
|
+
def use_terminator?(ref, final, _cit)
|
|
76
|
+
!ref || ref.empty? and return false
|
|
77
|
+
!ref.end_with?(final)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def render1_prep(cit)
|
|
81
|
+
r = renderer(cit)
|
|
82
|
+
ref = r.renderer(cit[:type] || "misc").render(cit[:data], cit[:data])
|
|
83
|
+
final = @i18n.select(cit[:data]).get
|
|
84
|
+
.dig("punct", "biblio-terminator") || "."
|
|
85
|
+
ref1 = ref
|
|
86
|
+
use_terminator?(ref, final, cit) and ref1 += final
|
|
87
|
+
[ref, ref1, r]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# TODO: configure how multiple ids are joined, from template?
|
|
69
91
|
def citations(ret)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
ret = disambig_author_date_citations(ret)
|
|
93
|
+
ret.each_value do |b|
|
|
94
|
+
i = @i18n.select(b[:data])
|
|
95
|
+
b[:citation][:default] =
|
|
96
|
+
i.l10n(b[:data][:authoritative_identifier]&.first || "")
|
|
97
|
+
b[:citation][:short] = i.l10n(renderer(b).citeshorttemplate
|
|
98
|
+
.render(b[:data].merge(citestyle: "short"), b[:data]))
|
|
99
|
+
citations_iterate_cite_styles(b, i)
|
|
74
100
|
end
|
|
101
|
+
ret
|
|
75
102
|
end
|
|
76
103
|
|
|
77
|
-
def
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
def citations_iterate_cite_styles(bib, i18n)
|
|
105
|
+
r = renderer(bib)
|
|
106
|
+
r.citetemplate.citation_styles.each do |style|
|
|
107
|
+
bib[:citation][style] =
|
|
108
|
+
i18n.l10n(r.citetemplate
|
|
109
|
+
.render(bib.merge(citestyle: style)
|
|
110
|
+
.merge(bib[:data]), bib[:data]))
|
|
81
111
|
end
|
|
82
112
|
end
|
|
83
113
|
|
|
84
|
-
# takes array of { id, type, author, date, ord,
|
|
114
|
+
# takes array of { id, type, author, date, ord, data }
|
|
85
115
|
def disambig_author_date_citations(ret)
|
|
86
|
-
|
|
116
|
+
author_date_to_hash(suffix_date(sort_ord(author_date_breakdown(ret))))
|
|
87
117
|
end
|
|
88
118
|
|
|
89
|
-
def
|
|
119
|
+
def author_date_breakdown(ret)
|
|
90
120
|
ret.each_with_object({}) do |b, m|
|
|
91
121
|
m[b[:author]] ||= {}
|
|
92
122
|
m[b[:author]][b[:date]] ||= []
|
|
@@ -114,21 +144,21 @@ module Relaton
|
|
|
114
144
|
end
|
|
115
145
|
|
|
116
146
|
def suffix_date1(ret, key1, key2)
|
|
147
|
+
key1.nil? and return
|
|
117
148
|
ret[key1][key2].each_with_index do |b, i|
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
b[:date].nil? and next
|
|
120
150
|
b[:date] += ("a".ord + i).chr.to_s
|
|
121
|
-
b[:
|
|
151
|
+
b[:data][:date] = b[:date]
|
|
122
152
|
end
|
|
123
153
|
end
|
|
124
154
|
|
|
125
|
-
def
|
|
155
|
+
def author_date_to_hash(ret)
|
|
126
156
|
ret.each_with_object({}) do |(_k, v), m|
|
|
127
157
|
v.each_value do |v1|
|
|
128
158
|
v1.each do |b|
|
|
129
|
-
m[b[:id]] = { author: @i18n.
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
m[b[:id]] = { author: @i18n.select(b[:data]).l10n(b[:author]),
|
|
160
|
+
date: b[:date], citation: {},
|
|
161
|
+
data: b[:data], type: b[:type] }
|
|
132
162
|
end
|
|
133
163
|
end
|
|
134
164
|
end
|