relaton-render 3.0.0.pre.alpha.12 → 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: 6940d659b738ee1c15dc46b7ee7be2bfb3f3bf322fd6cb8ae5fe70e19a2ab7ce
4
- data.tar.gz: 060007b9cd392e9bf4b84cac3961aa8f0881849e74195c4ca6eb3f5f6dcf64f6
3
+ metadata.gz: ead90c5cd3e6ad47098edb1a67c40811de053b49d723dc64d85e8413f5197334
4
+ data.tar.gz: 6b8edcc93cc0d005a94552af4621af0cfbad5ae32fdf5b5e7ba5f8681dea3900
5
5
  SHA512:
6
- metadata.gz: 4a989f5e702e6e27afbad1fab8dc59c7bd092355eab5dbfb1cedf0b99c2373e71c99c3ed418e033f6638f00addcf68d983006213206a4200b7ef6e45c9907682
7
- data.tar.gz: 56ac7f18bd13de8324a8ac118d68c7c9d98b6b3eb49b455a32cbca194802097b2e5123e725427ff84d16fd8fe1bd4fe952de7e90c610bf27e39cd94d105a76c2
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)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Render
5
+ module Iso690
6
+ module Elements
7
+ # The authorizing body of a standard (the IETF RFC Series, the
8
+ # W3C Recommendation process): the organization carrying the
9
+ # authorizer role, cited after the status
10
+ class Authorizer < Element
11
+ def present?
12
+ !authorizer_name.empty?
13
+ end
14
+
15
+ def render
16
+ authorizer_name
17
+ end
18
+
19
+ private
20
+
21
+ def authorizer_name
22
+ contributors("authorizer").map do |c|
23
+ Array(c.organization&.name).map { |n| localized(n) }.join(", ")
24
+ end.reject(&:empty?).first.to_s
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -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
 
@@ -21,6 +21,7 @@ module Relaton
21
21
  autoload :Access, "relaton/render/iso690/elements/access"
22
22
  autoload :Stddoc, "relaton/render/iso690/elements/stddoc"
23
23
  autoload :Status, "relaton/render/iso690/elements/status"
24
+ autoload :Authorizer, "relaton/render/iso690/elements/authorizer"
24
25
  autoload :Citeid, "relaton/render/iso690/elements/citeid"
25
26
  autoload :Updated, "relaton/render/iso690/elements/updated"
26
27
 
@@ -41,6 +42,7 @@ module Relaton
41
42
  access: Access,
42
43
  stddoc: Stddoc,
43
44
  status: Status,
45
+ authorizer: Authorizer,
44
46
  citeid: Citeid,
45
47
  updated: Updated,
46
48
  }.freeze
@@ -11,7 +11,7 @@ module Relaton
11
11
  ELEMENT_SLOTS = %i[
12
12
  creator title edition medium series production
13
13
  date numeration component_part identifier location size
14
- extent access stddoc status citeid updated
14
+ extent access stddoc status citeid authorizer updated
15
15
  ].freeze
16
16
 
17
17
  def initialize(model, style:, i18n:, disambiguator: nil,
@@ -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.12".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.12
4
+ version: 3.0.0.pre.alpha.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -121,6 +121,7 @@ files:
121
121
  - lib/relaton/render/iso690/element.rb
122
122
  - lib/relaton/render/iso690/elements.rb
123
123
  - lib/relaton/render/iso690/elements/access.rb
124
+ - lib/relaton/render/iso690/elements/authorizer.rb
124
125
  - lib/relaton/render/iso690/elements/citeid.rb
125
126
  - lib/relaton/render/iso690/elements/component_part.rb
126
127
  - lib/relaton/render/iso690/elements/creator.rb