relaton-render 0.5.5 → 0.5.7

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: 582bd299999942dc5919461f4bde4d4ea90418708be1cda926903aa05659baa2
4
- data.tar.gz: 5c8f8e6346a911b28bca037a9f6f931dd997d562400a615b9bbfd9f66a653848
3
+ metadata.gz: f0f0cf15017a8c117f7a8fde7567564f61138760cfeb89b506e5c2848ff6899d
4
+ data.tar.gz: 2d5bdd64aeb924e67b2c4f823e60033a1a51018542deb4596f32533038919e00
5
5
  SHA512:
6
- metadata.gz: d5994cb6fbfac2a14e0ad9e34c5acd3f33b12e2f983ac2e9de2d34cf8392b8e5e11fa1802eb5bc21dce0b545d1ac2d36b9a50a75e6344b962c207dba31a923cb
7
- data.tar.gz: 6363973667df0ba2751b7d87dd6abd7d3f4f733cdb1cbac6c6543ea0cd79befea3cfb5003ae6b50753132c2aebf826f846e0fc12e0985aa84163a88e91c92874
6
+ metadata.gz: 2f05f38566cf4f94bad2152db2cb2c71c0d2f2a63939c7bac0039fbaa0e21314aba6288640ec9a7c1248b6548342ba21ccff47e0b360902055ed1f026f52eabc
7
+ data.tar.gz: e787ce6357bfd515b9d7a975027f798ec027fa2845a6495ea53c0c2032abb8e90f7881736bf1f0c947cf30e0b82e5aeb259ba9f9f20877823828cc6c3d987277
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&.content
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.content,
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.content
24
+ x.content.empty? ? "#{x.initial}." : content(x)
20
25
  end
21
- initials = person.name.initials&.content&.sub(/(.)\.?$/, "\\1.")
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.content
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&.content or
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&.content ||
140
- c.entity.name.first&.content
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&.content
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&.content || host&.edition&.content
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.content
69
- series.title.respond_to?(:title) and return series.title.title&.content
70
- series.title.respond_to?(:formattedref) and series.formattedref.content
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&.content
76
+ content(series.formattedref)
75
77
  end
76
78
 
77
79
  def series_abbr(series, _doc)
78
- series.abbreviation&.content
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.content
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 < >
@@ -49,6 +49,11 @@ module Relaton
49
49
  end
50
50
 
51
51
  def template_process(template)
52
+ template.is_a?(String) or return template
53
+ ::Liquid::Template.parse(add_field_delim_to_template(template))
54
+ end
55
+
56
+ def add_field_delim_to_template(template)
52
57
  t = template.split(/(\{\{|\}\})/).each_slice(4).map do |a|
53
58
  unless !a[2] || punct_field?(a[2]&.strip)
54
59
  a[1] = "#{FIELD_DELIM}{{"
@@ -56,9 +61,8 @@ module Relaton
56
61
  end
57
62
  a.join
58
63
  end.join.gsub(/\t/, " ")
59
- t1 = t.gsub(/\}\}#{FIELD_DELIM}\|/o, "}}#{FIELD_DELIM}\t")
64
+ t.gsub(/\}\}#{FIELD_DELIM}\|/o, "}}#{FIELD_DELIM}\t")
60
65
  .gsub(/\|#{FIELD_DELIM}\{\{/o, "\t#{FIELD_DELIM}{{")
61
- ::Liquid::Template.parse(t1)
62
66
  end
63
67
 
64
68
  def render(hash)
@@ -130,7 +134,9 @@ module Relaton
130
134
  class Name < General
131
135
  def initialize(opt = {})
132
136
  @etal_count = opt[:template]["etal_count"]
137
+ @etal_display = opt[:template]["etal_display"] || @etal_count
133
138
  opt[:template].delete("etal_count")
139
+ opt[:template].delete("etal_display")
134
140
  super
135
141
  end
136
142
 
@@ -147,8 +153,9 @@ module Relaton
147
153
 
148
154
  def template_select_etal(names)
149
155
  if @etal_count && names[:surname].size >= @etal_count
150
- @template[:etal]
151
- else expand_nametemplate(@template_raw[:more], names[:surname].size)
156
+ expand_nametemplate(@template_raw[:etal], @etal_display)
157
+ else
158
+ expand_nametemplate(@template_raw[:more], names[:surname].size)
152
159
  end
153
160
  end
154
161
 
@@ -156,29 +163,41 @@ module Relaton
156
163
  # ...[0], ...[1], ...[2]
157
164
  def expand_nametemplate(template, size)
158
165
  t = nametemplate_split(template)
166
+
159
167
  mid = (1..size - 2).each_with_object([]) do |i, m|
160
168
  m << t[1].gsub(/\[1\]/, "[#{i}]")
161
169
  end
162
- template_process(t[0] + mid.join + t[2].gsub(/\[2\]/,
163
- "[#{size - 1}]"))
170
+ t[1] = mid.join
171
+ t[2].gsub!(/\[\d+\]/, "[#{size - 1}]")
172
+ template_process(combine_nametemplate(t, size))
173
+ end
174
+
175
+ def combine_nametemplate(parts, size)
176
+ case size
177
+ when 1 then parts[0] + parts[3]
178
+ when 2 then parts[0] + parts[2] + parts[3]
179
+ else parts.join
180
+ end
164
181
  end
165
182
 
166
183
  def nametemplate_split(template)
167
184
  curr = 0
168
185
  prec = ""
169
186
  t = template.split(/(\{[{%].+?[}%]\})/)
170
- .each_with_object(["", "", ""]) do |n, m|
187
+ .each_with_object([""]) do |n, m|
171
188
  m, curr, prec = nametemplate_split1(n, m, curr, prec)
172
189
 
173
190
  m
174
191
  end
175
- t[-1] += prec
176
- t
192
+ [t[0], t[1], t[-1], prec]
177
193
  end
178
194
 
179
195
  def nametemplate_split1(elem, acc, curr, prec)
180
196
  if match = /\{[{%].+?\[(\d)\]/.match(elem)
181
- curr += 1 if match[1].to_i > curr
197
+ if match[1].to_i > curr
198
+ curr += 1
199
+ acc[curr] ||= ""
200
+ end
182
201
  acc[curr] += prec
183
202
  prec = ""
184
203
  acc[curr] += elem
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.5.5".freeze
3
+ VERSION = "0.5.7".freeze
4
4
  end
5
5
  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: 0.5.5
4
+ version: 0.5.7
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-09 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler