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

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: 6e6e4911053aee3915882fcee48c182f8bf0d1ca2c879e7201bb0d19cfd48e4b
4
- data.tar.gz: 60b845d08886130df02eaef46bfe5811996f208aaab13093fb660221f5f50799
3
+ metadata.gz: 1765d54a70d5e79ba48d03c848135bad61bfb6f27e439cb142e869054e06b181
4
+ data.tar.gz: 9d8636b1838f06a8d119ad2052e7c7b7c47f81f6e9d176ca414fb76b1cbc0698
5
5
  SHA512:
6
- metadata.gz: 855419eacf8dc6f71a4c9eaef6b23341328bee50a1a59b0c2138d62420b3295d59176a83d3cac5c52a0c2cb989558ebced170badaf8732f04449fb5a5047cc6d
7
- data.tar.gz: 38ace39e42d57252a8eb994cc4ec4a82ea56a5bd6476025db679b6b4a42c6c676b77908d6d076f06442e30768bb406104e284daed8e85dd73dfbb8f7c66aa7fc
6
+ metadata.gz: d4907031dd0d8e1180b3e25221000d58498d5bd18468bf743d372fc84ca79d878518f3b4c966d7faa7dfb3b36c4c5a61fef82d5c508295e3167dfb9cb722485a
7
+ data.tar.gz: 832213c7c17a9b58dee06a8953c75f30a41b23e568a3ff936cf32d4167a69b69eebe74d9bfbd31b0e7cd22ac3964da999aeb05f2bbd7e30b86473d656b458067
@@ -63,15 +63,25 @@ module Relaton
63
63
  end
64
64
  m[item.id] = {
65
65
  id: item.id, ord: i, formattedref: ref,
66
- citation: {
67
- full: ref,
68
- default: item.docidentifier.first&.content.to_s,
69
- short: @renderer.citation(item),
70
- },
66
+ citation: citation_renderings(item, ref),
71
67
  }
72
68
  end
73
69
  end
74
70
 
71
+ # isodoc's styled citations consume these keys: the default is the
72
+ # authoritative identifier; the short cite is the style's citation,
73
+ # falling back to the reference rendering (the 1.x short-cite)
74
+ def citation_renderings(item, ref)
75
+ short = @renderer.citation(item)
76
+ short = ref if short.empty?
77
+
78
+ {
79
+ full: ref,
80
+ default: item.docidentifier.first&.content.to_s,
81
+ short: short,
82
+ }
83
+ end
84
+
75
85
  # isodoc's pref_ref_code_parse reads
76
86
  # data[:authoritative_identifier] to build biblio-tag identifiers
77
87
  # (presentation_function/docid.rb). Returns [data, self] as the
@@ -48,8 +48,12 @@ module Relaton
48
48
  end
49
49
 
50
50
  def org_name(contributor)
51
+ shown = ->(n) do
52
+ text = localized(n)
53
+ @style.scheme.name_form.org_upcase ? text.upcase : text
54
+ end
51
55
  name = Array(contributor.organization&.name)
52
- .map { |n| localized(n).upcase }.join(", ")
56
+ .map(&shown).join(", ")
53
57
  abbrev = localized(contributor.organization&.abbreviation)
54
58
  return name if name.empty? || abbrev.empty?
55
59
 
@@ -95,15 +99,27 @@ module Relaton
95
99
  end
96
100
 
97
101
  def join_names(names)
102
+ oxford = @i18n.label("oxford_comma")
103
+ if serial_list? && names.size > 1 && !oxford.empty?
104
+ return "#{names[0..-2].join(', ')}#{oxford} " \
105
+ "#{@i18n.label('and')} #{names.last}"
106
+ end
107
+
98
108
  case names.size
99
109
  when 0 then ""
100
110
  when 1 then names.first
101
111
  when 2 then names.join(" #{@i18n.label('and')} ")
102
112
  else
103
- "#{names[0..-2].join(', ')}#{@i18n.label('oxford_comma')} " \
113
+ "#{names[0..-2].join(', ')}#{oxford} " \
104
114
  "#{@i18n.label('and')} #{names.last}"
105
115
  end
106
116
  end
117
+
118
+ # Serial list style: the oxford comma appears at every gap of a
119
+ # name list, including between two names
120
+ def serial_list?
121
+ @style.scheme.name_form.list_style == "serial"
122
+ end
107
123
  end
108
124
  end
109
125
  end
@@ -115,21 +115,9 @@ module Relaton
115
115
  end
116
116
 
117
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
-
124
118
  join_names(names)
125
119
  end
126
120
 
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
-
133
121
  def editors?
134
122
  !creators.empty? && creators.all? { |c| has_role?(c, "editor") }
135
123
  end
@@ -9,19 +9,28 @@ module Relaton
9
9
  # organization contributors.
10
10
  class Production < Element
11
11
  def present?
12
- !places.empty? || !publishers.empty?
12
+ !places.empty? || !publishers.empty? || no_place_declared?
13
13
  end
14
14
 
15
15
  def render
16
- [place_text, publishers.join("; ")]
16
+ return no_place_production if places.empty? && no_place_declared?
17
+
18
+ [places.join("; "), publishers.join("; ")]
17
19
  .reject(&:empty?).join(@i18n.punct_fetch("production_sep", ": "))
18
20
  end
19
21
 
20
- def place_text
21
- return places.join("; ") unless places.empty?
22
-
22
+ # The no-place placeholder keeps the production separator even
23
+ # when no publisher follows ("n.p.: n.d.")
24
+ def no_place_production
23
25
  label = @i18n.label("no_place")
24
- label == "no_place" ? "" : label
26
+ return "" if label.empty? || label == "no_place"
27
+
28
+ pubs = publishers.join("; ")
29
+ pubs.empty? ? "#{label}:" : "#{label}: #{pubs}"
30
+ end
31
+
32
+ def no_place_declared?
33
+ @style.type_template_for(item_kind)&.no_place == true
25
34
  end
26
35
 
27
36
  private
@@ -25,8 +25,11 @@ module Relaton
25
25
  def initialize(style: DEFAULT_STYLE, lang: "en", script: "Latn",
26
26
  labels: {})
27
27
  @style = Style.load(style)
28
- @i18n = I18n.load(lang).overlay!(@style.scheme.locale)
28
+ @i18n = I18n.load(lang)
29
29
  @i18n.overlay_hash!(labels) unless labels.empty?
30
+ # The style instance is the citation-style authority: its
31
+ # declared strings win over the caller's generic i18n hash
32
+ @i18n.overlay!(@style.scheme.locale)
30
33
  @script = script
31
34
  end
32
35
 
@@ -23,6 +23,9 @@ module Relaton
23
23
  # "serial": the oxford comma appears at every gap of the
24
24
  # creator list, including between two names
25
25
  attribute :list_style, :string, default: ""
26
+ # Organization names take the inverted form's casing; small-cap
27
+ # styles keep the declared case
28
+ attribute :org_upcase, :boolean, default: -> { true }
26
29
  # The inverted form's surname casing: the name-date convention
27
30
  # upcases; small-cap styles keep the declared case
28
31
  attribute :surname_upcase, :boolean, default: -> { true }
@@ -36,6 +39,7 @@ module Relaton
36
39
  map "completenameUpcase", to: :completename_upcase
37
40
  map "invertedAll", to: :inverted_all
38
41
  map "listStyle", to: :list_style
42
+ map "orgUpcase", to: :org_upcase
39
43
  map "surnameUpcase", to: :surname_upcase
40
44
  map "initialsSeparator", to: :initials_separator
41
45
  end
@@ -13,6 +13,9 @@ module Relaton
13
13
  attribute :title, :string
14
14
  attribute :home, :boolean
15
15
  attribute :fallbacks, :hash, default: -> { {} }
16
+ # Render the style's no_place label when the publisher has no
17
+ # place (the book-family templates of some flavors)
18
+ attribute :no_place, :boolean
16
19
 
17
20
  key_value do
18
21
  map "type", to: :type
@@ -21,6 +24,7 @@ module Relaton
21
24
  map "title", to: :title
22
25
  map "home", to: :home
23
26
  map "fallbacks", to: :fallbacks
27
+ map "noPlace", to: :no_place
24
28
  end
25
29
  end
26
30
  end
@@ -57,6 +57,9 @@ module Relaton
57
57
  end
58
58
 
59
59
  def terminate(body)
60
+ # An element ending in a colon carries its own separator: the
61
+ # following sentence period collapses (1.x punctuation cleanup)
62
+ body = body.gsub(/:\s*\.\s*/, ": ")
60
63
  return body if @terminator.strip.empty?
61
64
  return body if body.rstrip.end_with?(@terminator.strip)
62
65
 
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "3.0.0.pre.alpha.6".freeze
3
+ VERSION = "3.0.0.pre.alpha.7".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.6
4
+ version: 3.0.0.pre.alpha.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.