relaton-render 3.0.0.pre.alpha.5 → 3.0.0.pre.alpha.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cf356647bbf5280c9c9e4300c861917b428fc8d248db8a94b3c7b66916a0c01
4
- data.tar.gz: 81bbe019e929ae84c4db8ca0808a10029c55dce0f61c94e072aa03c9d01127be
3
+ metadata.gz: 6e6e4911053aee3915882fcee48c182f8bf0d1ca2c879e7201bb0d19cfd48e4b
4
+ data.tar.gz: 60b845d08886130df02eaef46bfe5811996f208aaab13093fb660221f5f50799
5
5
  SHA512:
6
- metadata.gz: 61831187b3aba40f2e3701e00b0af1d89e25f219dc735cbb1d36877a0431c0e548776b39d1b90ee8606dfdb4968962a58f61c82f83ba734b9ba4756bb02cd11e
7
- data.tar.gz: 640b3659f2bd48a9b6cfb46c063f8d4ed7ecfe15fef2c7961c208875b56a9c7514a0641edcad9e3f335ba7fab91581044d832b737944c9a8c7a9cd134d77cb23
6
+ metadata.gz: 855419eacf8dc6f71a4c9eaef6b23341328bee50a1a59b0c2138d62420b3295d59176a83d3cac5c52a0c2cb989558ebced170badaf8732f04449fb5a5047cc6d
7
+ data.tar.gz: 38ace39e42d57252a8eb994cc4ec4a82ea56a5bd6476025db679b6b4a42c6c676b77908d6d076f06442e30768bb406104e284daed8e85dd73dfbb8f7c66aa7fc
@@ -76,12 +76,20 @@ module Relaton
76
76
 
77
77
  ""
78
78
  end.reject(&:empty?)
79
- return localized(person.name&.formatted_initials) if parts.empty?
80
- return parts.map { |p| "#{p[0]}." }.join(" ") if initials?
79
+ sep = @style.scheme.name_form.initials_separator.to_s
80
+ return reinitials(localized(person.name&.formatted_initials),
81
+ sep) if parts.empty?
82
+ return parts.map { |p| "#{p[0]}." }.join(sep) if initials?
81
83
 
82
84
  parts.join(" ")
83
85
  end
84
86
 
87
+ # Declared initials are a list in string form; rejoin them with
88
+ # the style's separator
89
+ def reinitials(raw, sep)
90
+ raw.split(/\s+/).reject(&:empty?).join(sep)
91
+ end
92
+
85
93
  def initials?
86
94
  @style.scheme.name_form.initials
87
95
  end
@@ -69,7 +69,9 @@ module Relaton
69
69
 
70
70
  surname = person_surname(person)
71
71
  given = person_given(person)
72
- if first
72
+ if @style.scheme.name_form.inverted_all
73
+ @style.render_name(surname: surname, given: given)
74
+ elsif first
73
75
  [surname, given].reject(&:empty?).join(", ")
74
76
  else
75
77
  [given, surname].reject(&:empty?).join(" ")
@@ -15,19 +15,26 @@ module Relaton
15
15
  end
16
16
 
17
17
  def render
18
+ joined = if (form = @style.templates.creators) && !form.empty?
19
+ ::Relaton::Render::Iso690::Template.new(form).evaluate(
20
+ "names" => Template::Field[true, join(names)],
21
+ )
22
+ else
23
+ join(names)
24
+ end
18
25
  case role_placement
19
26
  when "afterPeriod"
20
27
  # the in-slot trailing space separates the (eds.) marker
21
28
  # from the next element, which follows directly in the
22
29
  # template; a lone editor is unmarked
23
30
  if editors? && creators.size > 1
24
- "#{period(join(names))} (#{role_word}) "
31
+ "#{period(joined)} (#{role_word}) "
25
32
  else
26
- "#{period(join(names))} "
33
+ "#{period(joined)} "
27
34
  end
28
35
  else
29
36
  marker = editors? && creators.size > 1 ? " (#{role_word})" : ''
30
- "#{join(names)}#{marker}"
37
+ "#{joined}#{marker}"
31
38
  end
32
39
  end
33
40
 
@@ -96,7 +103,7 @@ module Relaton
96
103
  def personal_name(person, first:)
97
104
  surname = surname(person).to_s
98
105
  given = given_names(person)
99
- if first && !name_form.given_name_first
106
+ if (first || name_form.inverted_all) && !name_form.given_name_first
100
107
  @style.render_name(surname: surname, given: given)
101
108
  else
102
109
  [given, surname.upcase].reject(&:empty?).join(" ")
@@ -108,9 +115,21 @@ module Relaton
108
115
  end
109
116
 
110
117
  def join(names)
118
+ oxford = @i18n.label("oxford_comma")
119
+ if serial_list? && names.size > 1 && !oxford.empty?
120
+ return "#{names[0..-2].join(', ')}#{oxford} " \
121
+ "#{@i18n.label('and')} #{names.last}"
122
+ end
123
+
111
124
  join_names(names)
112
125
  end
113
126
 
127
+ # Serial list style: every gap takes the serial form, even
128
+ # between two names
129
+ def serial_list?
130
+ @style.scheme.name_form.list_style == "serial"
131
+ end
132
+
114
133
  def editors?
115
134
  !creators.empty? && creators.all? { |c| has_role?(c, "editor") }
116
135
  end
@@ -13,10 +13,17 @@ module Relaton
13
13
  end
14
14
 
15
15
  def render
16
- [places.join("; "), publishers.join("; ")]
16
+ [place_text, publishers.join("; ")]
17
17
  .reject(&:empty?).join(@i18n.punct_fetch("production_sep", ": "))
18
18
  end
19
19
 
20
+ def place_text
21
+ return places.join("; ") unless places.empty?
22
+
23
+ label = @i18n.label("no_place")
24
+ label == "no_place" ? "" : label
25
+ end
26
+
20
27
  private
21
28
 
22
29
  def places
@@ -43,9 +43,10 @@ module Relaton
43
43
  end
44
44
 
45
45
  def home_docid?(model)
46
- type = @style.scheme.home_docid_type
47
- !type.nil? && !type.empty? &&
48
- Array(model.docidentifier).any? { |d| d.type == type }
46
+ types = Array(@style.scheme.home_docid_type)
47
+ return false if types.empty?
48
+
49
+ Array(model.docidentifier).any? { |d| types.include?(d.type) }
49
50
  end
50
51
 
51
52
  # In-text form: SURNAME, year + disambiguator (name-and-date)
@@ -17,12 +17,27 @@ module Relaton
17
17
  # A completename is rendered, not decomposed; styles that
18
18
  # upcase inverted names may declare the completename treatment
19
19
  attribute :completename_upcase, :boolean, default: -> { false }
20
+ # Every personal name takes the inverted form (surname first),
21
+ # not just the principal creator
22
+ attribute :inverted_all, :boolean, default: -> { false }
23
+ # "serial": the oxford comma appears at every gap of the
24
+ # creator list, including between two names
25
+ attribute :list_style, :string, default: ""
26
+ # The inverted form's surname casing: the name-date convention
27
+ # upcases; small-cap styles keep the declared case
28
+ attribute :surname_upcase, :boolean, default: -> { true }
29
+ # Initials are a list; this separates them ("J. K." vs "J.K.")
30
+ attribute :initials_separator, :string, default: " "
20
31
 
21
32
  key_value do
22
33
  map "initials", to: :initials
23
34
  map "givenNameFirst", to: :given_name_first
24
35
  map "rolePlacement", to: :role_placement
25
36
  map "completenameUpcase", to: :completename_upcase
37
+ map "invertedAll", to: :inverted_all
38
+ map "listStyle", to: :list_style
39
+ map "surnameUpcase", to: :surname_upcase
40
+ map "initialsSeparator", to: :initials_separator
26
41
  end
27
42
  end
28
43
  end
@@ -10,7 +10,7 @@ module Relaton
10
10
  attribute :system, :string, default: "name-date"
11
11
  attribute :name_form, NameForm, default: -> { NameForm.new }
12
12
  attribute :locale, Locale, default: -> { Locale.new }
13
- attribute :home_docid_type, :string
13
+ attribute :home_docid_type, :string, collection: true
14
14
 
15
15
  key_value do
16
16
  map "system", to: :system
@@ -15,6 +15,7 @@ module Relaton
15
15
  attribute :name, :string, default: "{{surname}}, {{givenNames}}"
16
16
  attribute :series, :string, default: ""
17
17
  attribute :uri, :string, default: ""
18
+ attribute :creators, :string, default: ""
18
19
 
19
20
  key_value do
20
21
  map "titleOpen", to: :title_open
@@ -24,6 +25,7 @@ module Relaton
24
25
  map "name", to: :name
25
26
  map "series", to: :series
26
27
  map "uri", to: :uri
28
+ map "creators", to: :creators
27
29
  end
28
30
  end
29
31
  end
@@ -69,8 +69,9 @@ module Relaton
69
69
  # First-creator name form: the style's declared name template with
70
70
  # the surname upcased, per the name-and-date convention.
71
71
  def render_name(surname:, given:)
72
+ shown = scheme.name_form.surname_upcase ? surname.upcase : surname
72
73
  Template.new(templates.name).evaluate(
73
- "surname" => Template::Field[!surname.empty?, surname.upcase],
74
+ "surname" => Template::Field[!shown.empty?, shown],
74
75
  "givennames" => Template::Field[!given.empty?, given],
75
76
  )
76
77
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "3.0.0.pre.alpha.5".freeze
3
+ VERSION = "3.0.0.pre.alpha.6".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-render
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.alpha.5
4
+ version: 3.0.0.pre.alpha.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.