csl 2.4.0 → 2.5.0

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: c70f967fbf46ada97d0c2b3164d3fc1b843d24d6125f1c6364d2d7f408c5fa7e
4
- data.tar.gz: 59d241370ed43b45a191e938ebbe20b51ed74419a503feb0c71e37d2770facd3
3
+ metadata.gz: e483c629270cabba02a203aba157f855f758ee6a479bd3fe609749dbbc5ca4dd
4
+ data.tar.gz: b12ab1cfcb7d80659cd248d490f1ed5a55c628c6c9ef007207a97046a9788c54
5
5
  SHA512:
6
- metadata.gz: ee00896662db7e3f7ccdc6644f208428a392ad2a66ae09ad93bb37ac4a6366915d9f4cea1cb274526466e8a0441f6c40afdfcbf953735e2d6a744587f41f6777
7
- data.tar.gz: 2807a5c96c581af1a9314d75b5b24b09e461c6fbf956b475d9bde1f8c1f7a6bc420095a9af6380ee7879129b80f6dc0ce1505dcd555dafdff7355b89e09979cc
6
+ metadata.gz: 3a7ab825b430ba85795216742d476bccab2bab9d38f038f383d0c496b61cd0ffdd1d4f17cd2119e87f011b99a509fd06b8a0869f7734904a8705287117867881
7
+ data.tar.gz: d5e3fe727078cfd20acbfd7ca3de9ae1d1dc59cd8f259cf90f69245e139f10460553ede8a96f76e7850d105e5542dea3bf78c17cce3a630b1fafa6e03fd9cae2
@@ -343,14 +343,14 @@ module CSL
343
343
 
344
344
  def singularize
345
345
  return text if textnode?
346
- children.single.to_s
346
+ children.single&.text.to_s.strip
347
347
  end
348
348
 
349
349
  alias singular singularize
350
350
 
351
351
  def pluralize
352
352
  return text if textnode?
353
- children.multiple.to_s
353
+ children.multiple&.text.to_s.strip
354
354
  end
355
355
 
356
356
  alias plural pluralize
data/lib/csl/locale.rb CHANGED
@@ -288,6 +288,9 @@ module CSL
288
288
  # @option options ['feminine','masculine',nil] :'gender-form' (nil)
289
289
  # which ordinals gender-form to use; falls back to the neuter
290
290
  # ordinals (without gender-form)
291
+ # @option options [String] :noun the name of the term accompanied by
292
+ # the ordinal (e.g., "edition" or "month-01"); the ordinal uses the
293
+ # gender of the term unless a gender-form is given
291
294
  #
292
295
  # @raise [ArgumentError] if number cannot be converted to an integer
293
296
  #
@@ -297,6 +300,12 @@ module CSL
297
300
  number.respond_to?(:to_i)
298
301
 
299
302
  number = number.to_i
303
+
304
+ noun = terms.lookup(options[:noun]) if options.key?(:noun)
305
+ if noun&.gendered? && !options.key?(:'gender-form')
306
+ options = options.merge(:'gender-form' => noun.gender)
307
+ end
308
+
300
309
  ordinal = terms.ordinalize number, options
301
310
 
302
311
  return number.to_s if ordinal.nil?
@@ -25,6 +25,10 @@ module CSL
25
25
  children[:sort].sort_keys
26
26
  end
27
27
 
28
+ def second_field_align?
29
+ attribute?(:'second-field-align')
30
+ end
31
+
28
32
  def substitute_subsequent_authors?
29
33
  attribute?(:'subsequent-author-substitute')
30
34
  end
@@ -64,6 +64,49 @@ module CSL
64
64
  def has_overrides?
65
65
  localized? && has_parts?
66
66
  end
67
+
68
+ # Localized dates use the date parts of the locale's date in the
69
+ # same form, filtered by the date-parts attribute; the date parts of
70
+ # this date override their attributes, except for the affixes.
71
+ #
72
+ # @param locale [CSL::Locale]
73
+ # @raise [CSL::Error] if the locale has no date in the same form
74
+ # @return [Array<CSL::Style::DatePart, CSL::Locale::DatePart>]
75
+ # the date parts to use
76
+ def parts_for(locale)
77
+ return parts unless localized?
78
+
79
+ filter = parts_filter
80
+
81
+ localized_date_for(locale).parts
82
+ .select { |part| filter.include?(part.name) }
83
+ .map { |part| override(part) }
84
+ end
85
+
86
+ # @param locale [CSL::Locale]
87
+ # @raise [CSL::Error] if the locale has no date in the same form
88
+ # @return [String] the delimiter to use
89
+ def delimiter_for(locale)
90
+ localized? ? localized_date_for(locale).delimiter : delimiter
91
+ end
92
+
93
+ private
94
+
95
+ def localized_date_for(locale)
96
+ locale.each_date.detect { |date| date.form == form } or
97
+ raise Error, "no localized date for form #{form} found"
98
+ end
99
+
100
+ # @return [CSL::Locale::DatePart] the part or a copy
101
+ # with the attributes of the matching date part
102
+ def override(part)
103
+ override = parts.detect { |p| p.name == part.name }
104
+ return part if override.nil?
105
+
106
+ copy = part.deep_copy
107
+ copy.merge! override.attributes.to_hash.except(:prefix, :suffix)
108
+ copy
109
+ end
67
110
  end
68
111
 
69
112
  class DatePart < Node
@@ -181,8 +181,11 @@ module CSL
181
181
  self
182
182
  end
183
183
 
184
+ # @param names [#to_i, Enumerable] the list of names (or its length)
185
+ # @return [Boolean] whether or not the delimiter will be inserted
186
+ # before et-al
184
187
  def delimiter_precedes_et_al?(names)
185
- names = names.length if names.respond_to?(:length)
188
+ count = names.respond_to?(:length) ? names.length : names.to_i
186
189
 
187
190
  case
188
191
  when delimiter_never_precedes_et_al?
@@ -190,9 +193,9 @@ module CSL
190
193
  when delimiter_always_precedes_et_al?
191
194
  true
192
195
  when delimiter_precedes_et_al_after_inverted_name?
193
- name_as_sort_order_at?(names.to_i)
196
+ inverted_at?(names, count)
194
197
  else
195
- names.to_i > 1
198
+ count > 1
196
199
  end
197
200
  end
198
201
 
@@ -253,7 +256,7 @@ module CSL
253
256
  # @return [Boolean] whether or not the delimiter will be inserted between
254
257
  # the penultimate and the last name
255
258
  def delimiter_precedes_last?(names)
256
- names = names.length if names.respond_to?(:length)
259
+ count = names.respond_to?(:length) ? names.length : names.to_i
257
260
 
258
261
  case
259
262
  when !attribute?(:and)
@@ -263,14 +266,9 @@ module CSL
263
266
  when delimiter_always_precedes_last?
264
267
  true
265
268
  when delimiter_precedes_last_after_inverted_name?
266
- if name_as_sort_order?
267
- all_names_as_sort_order? || names.to_i == 2
268
- else
269
- false
270
- end
271
-
269
+ inverted_at?(names, count - 1)
272
270
  else
273
- names.to_i > 2
271
+ count > 2
274
272
  end
275
273
  end
276
274
 
@@ -342,6 +340,21 @@ module CSL
342
340
  def connector=(c)
343
341
  attributes[:and] = c
344
342
  end
343
+
344
+ private
345
+
346
+ # @param names [#to_i, Enumerable] the list of names (or its length)
347
+ # @param position [Integer] the position of the name (starting at 1)
348
+ # @return [Boolean] whether or not the name at the position is
349
+ # inverted; names which are not invertible (e.g., literal names)
350
+ # never are
351
+ def inverted_at?(names, position)
352
+ return false unless name_as_sort_order_at?(position)
353
+ return true unless names.is_a?(Enumerable)
354
+
355
+ name = names.to_a[position - 1]
356
+ !name.respond_to?(:invertible?) || name.invertible?
357
+ end
345
358
  end
346
359
 
347
360
  class NamePart < Node
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-10-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: namae
@@ -112,7 +112,7 @@ description: |
112
112
  an open XML-based language to describe the formatting of citations
113
113
  and bibliographies.
114
114
  email:
115
- - http://sylvester.keil.or.at
115
+ - sylvester@keil.or.at
116
116
  executables: []
117
117
  extensions: []
118
118
  extra_rdoc_files: []
@@ -159,7 +159,10 @@ files:
159
159
  homepage: https://github.com/inukshuk/csl-ruby
160
160
  licenses:
161
161
  - BSD-2-Clause
162
- metadata: {}
162
+ metadata:
163
+ source_code_uri: https://github.com/inukshuk/csl-ruby
164
+ bug_tracker_uri: https://github.com/inukshuk/csl-ruby/issues
165
+ rubygems_mfa_required: 'true'
163
166
  rdoc_options: []
164
167
  require_paths:
165
168
  - lib