relaton-render 3.0.0.pre.alpha.13 → 3.0.0.pre.alpha.14

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: 3e80ae8de229852d85ba4eabcd093152e140c9252f07c301fb6091c03694eac8
4
- data.tar.gz: c378a86333710cabdcd00fd085a43e74a924c47e0b5df3d37eb830b56697ecf8
3
+ metadata.gz: ead90c5cd3e6ad47098edb1a67c40811de053b49d723dc64d85e8413f5197334
4
+ data.tar.gz: 6b8edcc93cc0d005a94552af4621af0cfbad5ae32fdf5b5e7ba5f8681dea3900
5
5
  SHA512:
6
- metadata.gz: 51b3ee0d7f8486e221ad0ea3fc0a69b8ae43a8f18056aa7357e77a362ea9c414c71ae724f241c8c12cc76ee29d34a906788a0b1abf82e1bf5a740d1c8dd5cada
7
- data.tar.gz: 5d99388b322ae77613713554f9d6a0a7effb284a31267dda00427fbedf122a1c8d3abc990eceef6de27350b3394b6c710d433311bb025614c7c9db11adfb7e5d
6
+ metadata.gz: 97e932d38d5f754bbec369ac6218592121ba1214811defbf553ac260c4b4de6fb8f4b0a24fb56e25d0bba75be8b8dbb79aa56b5375f54a4862dbfb05172e3d90
7
+ data.tar.gz: '088c9aeb8e944ede167697eee2ce60d3c8952c457a8ae8e3ce35e517f942ee167ba69142b2df52ab9873c104b361c76eb95e9a108df49f2855500adba95176e9'
@@ -55,9 +55,10 @@ module Relaton
55
55
  # presentation_function/refs.rb).
56
56
  def render_all(bib, type: "author-date")
57
57
  items = facade_bibitems(bib) or return nil
58
+ disambiguators = date_disambiguators(items)
58
59
  items.each_with_object({}).with_index do |(item, m), i|
59
60
  ref = begin
60
- @renderer.render(item)
61
+ @renderer.render(item, disambiguator: disambiguators[item.id])
61
62
  rescue ::Relaton::Render::Unrenderable
62
63
  next
63
64
  end
@@ -82,6 +83,31 @@ module Relaton
82
83
  # render_all feeds the bibliography list: a reference not ending
83
84
  # in the biblio terminator takes one (the 1.x render1 behaviour;
84
85
  # single-item render stays verbatim)
86
+ # The batch disambiguation suffixes ("2022a"): items sharing a
87
+ # principal-creator surname and a date take alphabetical
88
+ # suffixes in bibliography order (the 1.x
89
+ # disambig_author_date_citations)
90
+ def date_disambiguators(items)
91
+ keys = items.filter_map do |item|
92
+ begin
93
+ [item.id, @renderer.author_key(item),
94
+ @renderer.citation(item)]
95
+ rescue ::Relaton::Render::Unrenderable
96
+ nil
97
+ end
98
+ end
99
+ groups = keys.group_by { |_, author, cite| [author, cite] }
100
+ suffixes = {}
101
+ groups.each_value do |group|
102
+ next if group.size < 2
103
+
104
+ group.each_with_index do |(id, _author, _cite), i|
105
+ suffixes[id] = ("a".ord + i).chr
106
+ end
107
+ end
108
+ suffixes
109
+ end
110
+
85
111
  # The bibliography terminator; flavors override to suppress it
86
112
  # (1.x use_terminator?), receiving the item it terminates
87
113
  def terminate_reference(ref, _item = nil)
@@ -59,18 +59,27 @@ module Relaton
59
59
  end
60
60
 
61
61
  def marked?
62
- creators.size > 1 || name_form.lone_editor_marked
62
+ name_form.editors_marked &&
63
+ (creators.size > 1 || name_form.lone_editor_marked)
63
64
  end
64
65
 
65
66
  def role_word
66
67
  @i18n.label(creators.one? ? "ed" : "eds")
67
68
  end
68
69
 
69
- # In-text (name-and-date) form: the principal creator only
70
+ # In-text (name-and-date) form: the principal creator only;
71
+ # at the style's et-al threshold the cite truncates
72
+ # ("Aluffi <em>et al.</em>")
70
73
  def in_text
71
74
  principal = creators.first or return ""
72
75
  person = principal.person or return org_name(principal)
73
- completename(person) || surname(person)&.upcase || ""
76
+ name = completename(person) || surname(person)&.upcase || ""
77
+ etal? ? "#{name} <em>et al.</em>" : name
78
+ end
79
+
80
+ def etal?
81
+ count = name_form.etal_count
82
+ count.positive? && creators.size >= count
74
83
  end
75
84
 
76
85
  # The principal creator's given names, as the name form declares
@@ -141,7 +150,11 @@ module Relaton
141
150
  if (first || name_form.inverted_all) && !name_form.given_name_first
142
151
  @style.render_name(surname: surname, given: given)
143
152
  else
144
- [given, surname.upcase].reject(&:empty?).join(" ")
153
+ # the direct form initializes per the style's initials
154
+ # knob ("S. Payne" over "Sam Payne")
155
+ shown = name_form.subsequent_surname_upcase ? surname.upcase :
156
+ surname
157
+ [person_given(person), shown].reject(&:empty?).join(" ")
145
158
  end
146
159
  end
147
160
 
@@ -31,12 +31,21 @@ module Relaton
31
31
  table[key] = element_field(slot)
32
32
  end
33
33
  table["dategroup"] = dategroup_field
34
+ table["disambiguateddate"] = disambiguated_date_field(table["date"])
34
35
  unless table["dategroup"].present?
35
36
  table["dategroup"] = fallback_field(:dategroup)
36
37
  end
37
38
  table.merge(name_fields)
38
39
  end
39
40
 
41
+ # The date carrying the batch disambiguation suffix ("2022a"):
42
+ # identity when the caller passes none
43
+ def disambiguated_date_field(date)
44
+ return date if @disambiguator.empty? || !date.present?
45
+
46
+ Template::Field[true, "#{date.text}#{@disambiguator}"]
47
+ end
48
+
40
49
  def fallback_field(slot)
41
50
  fallback = @style.fallback_for(item_kind, slot)
42
51
  fallback ? Template::Field[true, fallback] :
@@ -34,11 +34,12 @@ module Relaton
34
34
  @script = script
35
35
  end
36
36
 
37
- def render(model)
37
+ def render(model, disambiguator: nil)
38
38
  kind = @style.kind_for(model.type)
39
39
  template = @style.template_for(kind, home: home_docid?(model))
40
40
  out = Template.new(template).evaluate(
41
41
  Fields.new(model, style: @style, i18n: @i18n,
42
+ disambiguator: disambiguator,
42
43
  elements: @elements).to_h,
43
44
  )
44
45
  raise ::Relaton::Render::Unrenderable,
@@ -74,6 +75,14 @@ module Relaton
74
75
  ""
75
76
  end
76
77
 
78
+ # The in-text author key (the principal creator's surname, as
79
+ # the citation renders it): the batch disambiguation groups by
80
+ # it
81
+ def author_key(model)
82
+ Fields.new(model, style: @style, i18n: @i18n,
83
+ elements: @elements).to_h["surname"].text
84
+ end
85
+
77
86
  # In-text form: SURNAME, year + disambiguator (name-and-date)
78
87
  def citation(model, disambiguator: nil)
79
88
  Template.new(@style.templates.citation).evaluate(
@@ -38,6 +38,15 @@ module Relaton
38
38
  attribute :surname_upcase, :boolean, default: -> { true }
39
39
  # Initials are a list; this separates them ("J. K." vs "J.K.")
40
40
  attribute :initials_separator, :string, default: " "
41
+ # The direct-order surname casing after the first creator:
42
+ # the name-date convention upcases
43
+ attribute :subsequent_surname_upcase, :boolean,
44
+ default: -> { true }
45
+ # At this many creators the in-text cite truncates to the
46
+ # first surname with "et al." (0 disables)
47
+ attribute :etal_count, :integer, default: 0
48
+ # Editor lists carry the role marker ("(Eds.)")
49
+ attribute :editors_marked, :boolean, default: -> { true }
41
50
 
42
51
  key_value do
43
52
  map "initials", to: :initials
@@ -52,6 +61,9 @@ module Relaton
52
61
  map "initialsPeriod", to: :initials_period
53
62
  map "surnameUpcase", to: :surname_upcase
54
63
  map "initialsSeparator", to: :initials_separator
64
+ map "subsequentSurnameUpcase", to: :subsequent_surname_upcase
65
+ map "etalCount", to: :etal_count
66
+ map "editorsMarked", to: :editors_marked
55
67
  end
56
68
  end
57
69
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "3.0.0.pre.alpha.13".freeze
3
+ VERSION = "3.0.0.pre.alpha.14".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.13
4
+ version: 3.0.0.pre.alpha.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.