relaton-render 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca7bf47fcca9f20390105c3bd1168e9bfa9fa6e16289fc8155be3de4b1b9e5fb
|
4
|
+
data.tar.gz: 6e2e6e8882405c484067bf2bf760af8a1aa84a2639583e2ea5e3ec4fe92d5683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6bd46639d0419f4c271fe451768e10be23d044f8d0957c2659412461052ff6a8ca34de7b8e23fa73fcc569ef8bb72da90f4fdb8d7aec9d40f9489dad2cf5a9
|
7
|
+
data.tar.gz: 27d0c9a160d2d784272a71d15d335f1e882ffac41d25c81af084e8fe624356dfd4a4098041ad6ac43977d7eb5a25398efb65c68ce51fca7dd37bfd5e5a7482cd
|
data/README.adoc
CHANGED
@@ -256,12 +256,31 @@ For example:
|
|
256
256
|
|
257
257
|
In the case of `more`, the `(name)[1]` entries are repeated for all additional authors above 2 and before the final author.
|
258
258
|
|
259
|
+
The behaviour of _et al._ can be specified as follows:
|
260
|
+
|
261
|
+
* `etal_count`: the number of authors to trigger _et al._ in bibliographic rendering
|
262
|
+
* `etal_display`: how many authors to show if using _et al._ in bibliography (by default, same as `etal_count`)
|
263
|
+
|
264
|
+
So the Chicago Manual of Style behaviour:
|
265
|
+
|
266
|
+
____
|
267
|
+
For more than ten authors (not shown here), list the first seven in the reference list, followed by et al.
|
268
|
+
____
|
269
|
+
|
270
|
+
is realised with etal_count = 10, etal_display = 7
|
271
|
+
|
259
272
|
[[authorcitetemplate]]
|
260
273
|
=== Author citation templates
|
261
274
|
|
262
275
|
The `authorcitetemplate` is a subclass of the name template, configured for rendering author names for author-date citations.
|
263
276
|
That means that it typically selects only surnames for rendering.
|
264
277
|
|
278
|
+
|
279
|
+
The behaviour of _et al._ in author-date citations can be specified as follows:
|
280
|
+
|
281
|
+
* `etal_count`: the number of authors to trigger _et al._ in bibliographic rendering
|
282
|
+
* `etal_display`: how many authors to show if using _et al._ in bibliography (by default, same as `etal_count`)
|
283
|
+
|
265
284
|
[[seriestemplate]]
|
266
285
|
=== Series template
|
267
286
|
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module Relaton
|
2
2
|
module Render
|
3
3
|
class Parse
|
4
|
+
def content(node)
|
5
|
+
node.nil? and return node
|
6
|
+
node.content.strip
|
7
|
+
end
|
8
|
+
|
4
9
|
def extract_orgname(org)
|
5
|
-
org.name&.first
|
10
|
+
content(org.name&.first)
|
6
11
|
end
|
7
12
|
|
8
13
|
def extract_personname(person)
|
9
14
|
surname = person.name.surname || person.name.completename
|
10
15
|
given, middle, initials = given_and_middle_name(person)
|
11
|
-
{ surname: surname
|
16
|
+
{ surname: content(surname),
|
12
17
|
given: given,
|
13
18
|
middle: middle,
|
14
19
|
initials: initials }
|
@@ -16,9 +21,9 @@ module Relaton
|
|
16
21
|
|
17
22
|
def given_and_middle_name(person)
|
18
23
|
forenames = person.name.forename.map do |x|
|
19
|
-
x.content.empty? ? "#{x.initial}." : x
|
24
|
+
x.content.empty? ? "#{x.initial}." : content(x)
|
20
25
|
end
|
21
|
-
initials = person.name.initials&.
|
26
|
+
initials = content(person.name.initials)&.sub(/(.)\.?$/, "\\1.")
|
22
27
|
&.split /(?<=\.) /
|
23
28
|
initials ||= person.name.forename.map(&:initial)
|
24
29
|
.compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
|
@@ -29,13 +34,13 @@ module Relaton
|
|
29
34
|
|
30
35
|
def forenames_parse(person)
|
31
36
|
person.name.forename.map do |x|
|
32
|
-
x.content.empty? ? "#{x.initial}." : x
|
37
|
+
x.content.empty? ? "#{x.initial}." : content(x)
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
# de S. => one initial, M.-J. => one initial
|
37
42
|
def initials_parse(person)
|
38
|
-
i = person.name.initials
|
43
|
+
i = content(person.name.initials) or
|
39
44
|
return person.name.forename.map(&:initial)
|
40
45
|
.compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
|
41
46
|
|
@@ -136,8 +141,8 @@ module Relaton
|
|
136
141
|
host and x ||= pick_contributor(host, "publisher")
|
137
142
|
x.nil? and return nil
|
138
143
|
x.map do |c|
|
139
|
-
c.entity.abbreviation
|
140
|
-
c.entity.name.first
|
144
|
+
content(c.entity.abbreviation) ||
|
145
|
+
content(c.entity.name.first)
|
141
146
|
end
|
142
147
|
end
|
143
148
|
|
@@ -13,7 +13,7 @@ module Relaton
|
|
13
13
|
t.empty? and t = doc.title
|
14
14
|
t1 = t.select { |x| x.type == "main" }
|
15
15
|
t1.empty? and t1 = t
|
16
|
-
t1.first&.title
|
16
|
+
content(t1.first&.title)
|
17
17
|
end
|
18
18
|
|
19
19
|
def medium(doc, host)
|
@@ -33,7 +33,7 @@ module Relaton
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def edition(doc, host)
|
36
|
-
doc.edition
|
36
|
+
content(doc.edition || host&.edition)
|
37
37
|
end
|
38
38
|
|
39
39
|
def edition_num(doc, host)
|
@@ -65,17 +65,19 @@ module Relaton
|
|
65
65
|
return nil if series.nil?
|
66
66
|
|
67
67
|
series.title.respond_to?(:titles) && !series.title.titles.empty? and
|
68
|
-
return series.title.titles.first.title
|
69
|
-
series.title.respond_to?(:title) and
|
70
|
-
|
68
|
+
return content(series.title.titles.first.title)
|
69
|
+
series.title.respond_to?(:title) and
|
70
|
+
return content(series.title.title)
|
71
|
+
series.title.respond_to?(:formattedref) and
|
72
|
+
content(series.formattedref)
|
71
73
|
end
|
72
74
|
|
73
75
|
def series_formatted(series, _doc)
|
74
|
-
series.formattedref
|
76
|
+
content(series.formattedref)
|
75
77
|
end
|
76
78
|
|
77
79
|
def series_abbr(series, _doc)
|
78
|
-
series.abbreviation
|
80
|
+
content(series.abbreviation)
|
79
81
|
end
|
80
82
|
|
81
83
|
def series_num(series, _doc)
|
@@ -122,7 +124,7 @@ module Relaton
|
|
122
124
|
uri ||= doc.link.detect { |u| !u.type&.casecmp("doi")&.zero? }
|
123
125
|
return nil unless uri
|
124
126
|
|
125
|
-
uri.content.to_s
|
127
|
+
uri.content.to_s.strip
|
126
128
|
end
|
127
129
|
|
128
130
|
def uri_type_select(doc, type)
|
@@ -201,7 +203,7 @@ module Relaton
|
|
201
203
|
def localized_string_or_text(str)
|
202
204
|
case str
|
203
205
|
when RelatonBib::LocalizedString
|
204
|
-
str
|
206
|
+
content(str)
|
205
207
|
when String
|
206
208
|
str
|
207
209
|
end
|
@@ -31,7 +31,7 @@ module Relaton
|
|
31
31
|
|
32
32
|
# denote start and end of field,
|
33
33
|
# so that we can detect empty fields in postprocessing
|
34
|
-
#FIELD_DELIM = "\u0018".freeze
|
34
|
+
# FIELD_DELIM = "\u0018".freeze
|
35
35
|
FIELD_DELIM = "%%".freeze
|
36
36
|
|
37
37
|
# escape < >
|
@@ -130,7 +130,9 @@ module Relaton
|
|
130
130
|
class Name < General
|
131
131
|
def initialize(opt = {})
|
132
132
|
@etal_count = opt[:template]["etal_count"]
|
133
|
+
@etal_display = opt[:template]["etal_display"] || @etal_count
|
133
134
|
opt[:template].delete("etal_count")
|
135
|
+
opt[:template].delete("etal_display")
|
134
136
|
super
|
135
137
|
end
|
136
138
|
|
@@ -147,8 +149,9 @@ module Relaton
|
|
147
149
|
|
148
150
|
def template_select_etal(names)
|
149
151
|
if @etal_count && names[:surname].size >= @etal_count
|
150
|
-
@
|
151
|
-
else
|
152
|
+
expand_nametemplate(@template_raw[:etal], @etal_display)
|
153
|
+
else
|
154
|
+
expand_nametemplate(@template_raw[:more], names[:surname].size)
|
152
155
|
end
|
153
156
|
end
|
154
157
|
|
@@ -156,29 +159,41 @@ module Relaton
|
|
156
159
|
# ...[0], ...[1], ...[2]
|
157
160
|
def expand_nametemplate(template, size)
|
158
161
|
t = nametemplate_split(template)
|
162
|
+
|
159
163
|
mid = (1..size - 2).each_with_object([]) do |i, m|
|
160
164
|
m << t[1].gsub(/\[1\]/, "[#{i}]")
|
161
165
|
end
|
162
|
-
|
163
|
-
|
166
|
+
t[1] = mid.join
|
167
|
+
t[2].gsub!(/\[\d+\]/, "[#{size - 1}]")
|
168
|
+
template_process(combine_nametemplate(t, size))
|
169
|
+
end
|
170
|
+
|
171
|
+
def combine_nametemplate(parts, size)
|
172
|
+
case size
|
173
|
+
when 1 then parts[0] + parts[3]
|
174
|
+
when 2 then parts[0] + parts[2] + parts[3]
|
175
|
+
else parts.join
|
176
|
+
end
|
164
177
|
end
|
165
178
|
|
166
179
|
def nametemplate_split(template)
|
167
180
|
curr = 0
|
168
181
|
prec = ""
|
169
182
|
t = template.split(/(\{[{%].+?[}%]\})/)
|
170
|
-
.each_with_object([""
|
183
|
+
.each_with_object([""]) do |n, m|
|
171
184
|
m, curr, prec = nametemplate_split1(n, m, curr, prec)
|
172
185
|
|
173
186
|
m
|
174
187
|
end
|
175
|
-
t[-1]
|
176
|
-
t
|
188
|
+
[t[0], t[1], t[-1], prec]
|
177
189
|
end
|
178
190
|
|
179
191
|
def nametemplate_split1(elem, acc, curr, prec)
|
180
192
|
if match = /\{[{%].+?\[(\d)\]/.match(elem)
|
181
|
-
|
193
|
+
if match[1].to_i > curr
|
194
|
+
curr += 1
|
195
|
+
acc[curr] ||= ""
|
196
|
+
end
|
182
197
|
acc[curr] += prec
|
183
198
|
prec = ""
|
184
199
|
acc[curr] += elem
|
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: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|