relaton-render 0.4.1 → 0.4.4

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: 3e893e8e3387625e3c0fa4d92117bf0580df3eda1fd24b7893627e97a70aa6e5
4
- data.tar.gz: 0741eec09057676c8198d3572ed5c441fe3ae89669bf0120a37f8ab357f746e9
3
+ metadata.gz: 3e355ba215a67c891399708f72baabeba37cddfc01a43df6d722c0a1aa769878
4
+ data.tar.gz: cdc21aa38ecdadab907db21b1b0cf58b8ce1f2ebc7966be7a894b4f58ffc3919
5
5
  SHA512:
6
- metadata.gz: 5f504a73a3b3ec8e5aeb2bea0557daf0f66f552af05277fdc6b52e8bf905bd629fdc06b6a02c8a8d8ab5a19f4be6aff10135c0e3b24feeb5a9b18c5d19c952a5
7
- data.tar.gz: 87add59c85c84d861650b95e2d6ae2954dbd63ba4013a199493f2e9417b727de13955b4fbf2a5b20e3a00405dd0ae2c4e78d3cc1e8496f1d8ad2cd6d5c4188b4
6
+ metadata.gz: f52456f0d7708e911a731fb6f584aed61cced226ed4f7a5de54407b0563ccaa5e5d182472cc0d01d2a59e13d1955910b8cfed1fd601d79ac88745ec6cab45743
7
+ data.tar.gz: aeb47b97f4146f90bdc86a3e2b5637e35675c67e37bb79b49010a450d34adcfb5c2792b3334ecedf8ff2749bc3511afaeb42442cf35eb8ef840f56d2599f654c
data/README.adoc CHANGED
@@ -191,6 +191,7 @@ The Liquid template surrounds each field by preceding and following punctuation.
191
191
  * Underscore is escaped by \. So `<span_class="std\_note">` maps to `<span class="std_note">`.
192
192
  * If punctuation is space delimited, it is inserted regardless of preceding content. So `{{ creatornames }} ({{date}}) .` will insert the full stop whether or not the date is present.
193
193
  * Space between punctuation and before punctuation is automatically removed.
194
+ * Spaces within fields are globally converted to underscores. For that reason, any filter operations in Liquid need to refer to underscore instead of space.
194
195
 
195
196
  For example:
196
197
 
@@ -218,7 +219,7 @@ draws on the following fields drawn from the bibliographic item:
218
219
  | surname[0] | ./contributor[1]/person/name/surname \| ./contributor[1]/person/name/completename | | i.e. surname is the name default
219
220
  | surname[1] | ./contributor[2]/name/surname | |
220
221
  | surname[2] | ./contributor[3]/name/surname | |
221
- | initials[0] | ./contributor[1]/name/initial | | If not supplied, the first letter of each given name is used instead
222
+ | initials[0] | ./contributor[1]/name/formatted-initials \| ./contributor[1]/name/forename/@initial | | If not supplied, the first letter of each given name is used instead
222
223
  | initials[1] | ./contributor[2]/name/initial | |
223
224
  | given[0] | ./contributor[1]/name/forename[1] | | If not supplied, initials are used instead
224
225
  | given[1] | ./contributor[2]/name/forename[1] | |
@@ -228,6 +229,10 @@ draws on the following fields drawn from the bibliographic item:
228
229
  | nonpersonal[1] |./contributor[2]/organization/name | Y |
229
230
  |===
230
231
 
232
+ The `formatted-initials` field is presumed to contain full stops, and so do the surrogates of that field done by using individual
233
+ forenames' `initial` attributes, or the forename initials. If the full stops are to be stripped, that needs to occur within the
234
+ Liquid template.
235
+
231
236
  There are at least three distinct `nametemplate` instances that need to be provided, one for a single contributor (`one:`), one for two contributors (`two:`), one for three or more (`more:`), and optionally one for "et al." (`etal:`). The number of contributors for which "et al." starts being used is indicated by `etal_count`.
232
237
 
233
238
  For example:
@@ -61,19 +61,25 @@ module Relaton
61
61
  end
62
62
 
63
63
  def suffix_date(ret)
64
- ret.each_value do |v|
65
- v.each_value do |v1|
66
- next if v1.size < 2
64
+ ret.each do |k, v|
65
+ v.each do |k1, v1|
66
+ next if v1.reject { |b| b[:date].nil? }.size < 2
67
67
 
68
- v1.each_with_index do |b, i|
69
- b[:date] += ("a".ord + i).chr.to_s
70
- b[:data_liquid][:date] = b[:date]
71
- end
68
+ suffix_date1(ret, k, k1)
72
69
  end
73
70
  end
74
71
  ret
75
72
  end
76
73
 
74
+ def suffix_date1(ret, key1, key2)
75
+ ret[key1][key2].each_with_index do |b, i|
76
+ next if b[:date].nil?
77
+
78
+ b[:date] += ("a".ord + i).chr.to_s
79
+ b[:data_liquid][:date] = b[:date]
80
+ end
81
+ end
82
+
77
83
  def to_hash(ret)
78
84
  ret.each_with_object({}) do |(_k, v), m|
79
85
  v.each do |_k1, v1|
@@ -1,9 +1,9 @@
1
1
  nametemplate:
2
- one: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase }} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: '. '}}.{%endif%}{% endif %}"
3
- two: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: '. '}}.{%endif%}{% endif %} {{ labels['and'] }} {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: '. '}}.{%endif%} {{surname[1] | upcase}}{% endif %}"
4
- more: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: '. '}}.{%endif%}{% endif %} , {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: '. '}}.{%endif%} {{surname[1] | upcase}}{% endif %} {{ labels['and'] }} {% if nonpersonal[2] %}{{ nonpersonal[2] }}{% else %}{%if given[2]%}{{given[2]}} {{middle[2]}}{%else%}{{initials[2] | join: '. '}}.{%endif%} {{surname[2] | upcase}}{% endif %}"
2
+ one: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase }} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: ' '}}.{%endif%}{% endif %}"
3
+ two: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: ' '}}.{%endif%}{% endif %} {{ labels['and'] }} {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: ' '}}.{%endif%} {{surname[1] | upcase}}{% endif %}"
4
+ more: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: ' '}}.{%endif%}{% endif %} , {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: ' '}}.{%endif%} {{surname[1] | upcase}}{% endif %} {{ labels['and'] }} {% if nonpersonal[2] %}{{ nonpersonal[2] }}{% else %}{%if given[2]%}{{given[2]}} {{middle[2]}}{%else%}{{initials[2] | join: ' '}}.{%endif%} {{surname[2] | upcase}}{% endif %}"
5
5
  # disabled the following: they should be provided in inheriting calls
6
- # etal: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: '. '}}.{%endif%}{% endif %}, {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: '. '}}.{%endif%} {{surname[1] | upcase}}{% endif %} <em>et al.</em>"
6
+ # etal: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: ' '}}.{%endif%}{% endif %}, {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: ' '}}.{%endif%} {{surname[1] | upcase}}{% endif %} <em>et al.</em>"
7
7
  # etal_count: 5
8
8
  authorcitetemplate:
9
9
  one: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] }}{% endif %}"
@@ -15,12 +15,15 @@ module Relaton
15
15
  end
16
16
 
17
17
  def given_and_middle_name(person)
18
- forenames = person.name.forename.map(&:content)
19
- initials = person.name.initial.map(&:content)
20
- .map { |x| x.sub(/\.$/, "") }
18
+ forenames = person.name.forename.map do |x|
19
+ x.content.empty? ? "#{x.initial}." : x.content
20
+ end
21
+ initials = person.name.initials&.content&.sub(/(.)\.?$/, "\\1.")
22
+ initials ||= person.name.forename.map(&:initial)
23
+ .compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
21
24
  forenames.empty? and initials.empty? and return [nil, nil, nil]
22
- initials.empty? and initials = forenames.map { |x| x[0] }
23
- [forenames.first, forenames[1..-1], initials]
25
+ initials.empty? and initials = forenames.map { |x| "#{x[0]}." }
26
+ [forenames.first, forenames[1..-1], Array(initials)]
24
27
  end
25
28
 
26
29
  def extractname(contributor)
@@ -56,9 +56,10 @@ module Relaton
56
56
  def series_title(series, _doc)
57
57
  return nil if series.nil?
58
58
 
59
- series.title.respond_to?(:titles) and
59
+ series.title.respond_to?(:titles) && !series.title.titles.empty? and
60
60
  return series.title.titles.first.title.content
61
- series.title&.title&.content || series.formattedref&.content
61
+ series.title.respond_to?(:title) and return series.title.title&.content
62
+ series.title.respond_to?(:formattedref) and series.formattedref.content
62
63
  end
63
64
 
64
65
  def series_formatted(series, _doc)
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.4.1".freeze
3
+ VERSION = "0.4.4".freeze
4
4
  end
5
5
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "isodoc-i18n"
32
32
  spec.add_dependency "liquid", "~> 4"
33
33
  spec.add_dependency "nokogiri"
34
- spec.add_dependency "relaton-bib", ">= 1.12.0"
34
+ spec.add_dependency "relaton-bib", ">= 1.13.0"
35
35
  spec.add_dependency "twitter_cldr"
36
36
  spec.add_dependency "tzinfo-data" # we need this for windows only
37
37
  #spec.metadata["rubygems_mfa_required"] = "true"
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.4.1
4
+ version: 0.4.4
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-08-10 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 1.12.0
145
+ version: 1.13.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 1.12.0
152
+ version: 1.13.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: twitter_cldr
155
155
  requirement: !ruby/object:Gem::Requirement