csl 2.2.1 → 2.3.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: 1d0cf629adc60121035ae2b8b86b8042a2a3da87b264402fa93fdc7da093f709
4
- data.tar.gz: 6d2c61c0e05a1214fcc8653142fcac1a45d63f357f24a434e453d7932caad645
3
+ metadata.gz: c0f6649dcc754264a3546a210a92cc4dd50ed8910ef011d61c0db3818cb1c576
4
+ data.tar.gz: 85ebc13c82b78cfefd1898c1e44380acea10fead06a1ac7bb4a34dc09b51d77b
5
5
  SHA512:
6
- metadata.gz: 5fe9697ec7d2c7308397fe192e912542d255c4317a310f83c51a066463a2f4a3c80a346edf528ead70ae3c95487a40870bfedb7f6d6db23cc1e38d37a022b73a
7
- data.tar.gz: 959edc27ca855e1083d4b2e2e23bde12607334d3d38647e0185753c584c10abbcecf48735f9f95e8e8b85db13acad20c405a3419c008f22d100291730ee75e42
6
+ metadata.gz: 1934e44e5893b200dc7ca55d522c3fc0024a0510e2a8d918bc5596f5249adad6c0357cae926ff2d47087404f9d3d58767a8448833d017bd47fbfcb8700922db6
7
+ data.tar.gz: cab29314253dd59ef4f669e3e649d6bf562eaa9799b8c6384e48a6d20bbc091b4d9a10079929ef960be2997c3879c775eb34c04faf73014693a3c0a0a0e6a080
data/README.md CHANGED
@@ -1,48 +1,56 @@
1
1
  CSL-Ruby
2
2
  ========
3
3
  CSL-Ruby provides a Ruby parser and a comprehensive API for the
4
- [Citation Style Language](http://citationstyles.org) (CSL), an XML-based
5
- format to describe the formatting of citations, notes and bibliographies.
4
+ [Citation Style Language](https://citationstyles.org) (CSL),
5
+ an XML-based format to describe the formatting
6
+ of citations, notes and bibliographies.
6
7
 
7
8
  Styles and Locales
8
9
  ------------------
9
- You can load CSL styles and locales by passing a respective XML string, file
10
- name, or URL. You can also load styles and locales by name if the
11
- corresponding files are installed in your local styles and locale directories.
10
+ You can load CSL styles and locales
11
+ by passing a respective XML string, file name, or URL.
12
+ You can also load styles and locales by name
13
+ if the corresponding files are installed
14
+ in your local styles and locale directories.
12
15
  By default, CSL-Ruby looks for CSL styles and locale files in
13
16
 
14
17
  /usr/local/share/csl/styles
15
18
  /usr/local/share/csl/locales
16
19
 
17
- You can change these locations by changing the value of `CSL::Style.root` and
18
- `CSL::Locale.root` respectively.
20
+ You can change these locations
21
+ by changing the value of `CSL::Style.root` and `CSL::Locale.root` respectively.
19
22
 
20
- Alternatively, you can `gem install csl-styles` to install all official CSL
21
- styles and locales. To make the styles and locales available, simply
22
- `require 'csl/styles`.
23
+ Alternatively, you can `gem install csl-styles`
24
+ to install all official CSL styles and locales.
25
+ To make the styles and locales available,
26
+ simply `require 'csl/styles'`.
23
27
 
24
28
  Usage
25
29
  -----
26
- CSL-Ruby is broadly aimed at two very different usage scenarios: on the one
27
- hand, you can use the parser to load existing styles and locales and
28
- manipulate, query or otherwise work with them using a dedicated API: that is
29
- to say, you do not have to resort to XML-related methods of access, but can
30
- make use of a large set of library methods which are specific to CSL. This
31
- is useful, primarily, for citation processors like
32
- [CiteProc-Ruby](https://github.com/inukshuk/citeproc).
33
-
34
- On the other hand, CSL-Ruby makes it easy to create new styles and locales
35
- using Ruby; this is useful, for example, if you need to change or adapt
36
- styles on-the-fly or for writing an interactive style editor.
37
-
38
- To get you started, here are a few usage examples; for the full set of
39
- available features, please consult the
40
- [API documentation](http://rubydoc.info/gems/csl/).
30
+ CSL-Ruby is broadly aimed at two very different usage scenarios:
31
+ on the one hand,
32
+ you can use the parser to load existing styles and locales
33
+ and manipulate, query or otherwise work with them using a dedicated API:
34
+ that is to say,
35
+ you do not have to resort to XML-related methods of access,
36
+ but can make use of a large set of library methods which are specific to CSL.
37
+ This is useful, primarily, for citation processors like
38
+ [CiteProc-Ruby](https://github.com/inukshuk/citeproc-ruby).
39
+
40
+ On the other hand,
41
+ CSL-Ruby makes it easy to create new styles and locales using Ruby;
42
+ this is useful, for example,
43
+ if you need to change or adapt styles on-the-fly
44
+ or for writing an interactive style editor.
45
+
46
+ To get you started, here are a few usage examples;
47
+ for the full set of available features, please consult the
48
+ [API documentation](https://rubydoc.info/gems/csl/).
41
49
 
42
50
  require 'csl'
43
51
 
44
52
  # Load a style from the Zotero style repository
45
- jps = CSL::Style.load 'http://zotero.org/styles/american-journal-of-political-science'
53
+ jps = CSL::Style.load 'https://www.zotero.org/styles/american-journal-of-political-science'
46
54
 
47
55
  # Query style information
48
56
  jps.title #-> "American Journal of Political Science"
@@ -53,7 +61,7 @@ available features, please consult the
53
61
  jps.valid? #-> true
54
62
 
55
63
  # Load another style
56
- amc = CSL::Style.load 'http://zotero.org/styles/applied-mathematics-and-computation'
64
+ amc = CSL::Style.load 'https://www.zotero.org/styles/applied-mathematics-and-computation'
57
65
 
58
66
  amc.independent? #-> false
59
67
 
@@ -68,9 +76,9 @@ available features, please consult the
68
76
  # Load a locally installed style
69
77
  apa = CSL::Style.load :apa
70
78
 
71
- # Fetch the a macro
72
- authors = apa.macros['authors'].children[0]
73
- #-> #<CSL::Style::Names variable="author" children=[2]>
79
+ # Fetch the first child of a macro
80
+ authors = apa.macros['author-bib'].children[0]
81
+ #-> #<CSL::Style::Group delimiter=" " children=[2]>
74
82
 
75
83
  # Load a locally installed locale
76
84
  fr = CSL::Locale.load :fr
@@ -82,7 +90,7 @@ available features, please consult the
82
90
 
83
91
  # Ordinalize a number
84
92
  fr.ordinalize 42 #=> "42ᵉ"
85
- fr.ordinalize 3, form: 'long' => "troisième"
93
+ fr.ordinalize 3, form: 'long' #=> "troisième"
86
94
 
87
95
  # Create a new style
88
96
  style = CSL::Style.new
@@ -101,11 +109,12 @@ available features, please consult the
101
109
 
102
110
  Dependencies
103
111
  ------------
104
- CSL-Ruby was written with portability in mind. For performance reasons it
105
- will use [Nokogiri ](http://nokogiri.org) for XML parsing and validation
106
- if available; however, CSL-Ruby will fallback to REXML from the Ruby standard
107
- library. In order to use Nokogiri, simply `gem install nokogiri` or add it
108
- to your Gemfile.
112
+ CSL-Ruby was written with portability in mind.
113
+ For performance reasons it will use [Nokogiri](https://nokogiri.org)
114
+ for XML parsing and validation if available;
115
+ however, CSL-Ruby will fallback to REXML from the Ruby standard library.
116
+ In order to use Nokogiri,
117
+ simply `gem install nokogiri` or add it to your Gemfile.
109
118
 
110
119
  Development
111
120
  -----------
@@ -114,28 +123,33 @@ You can check out a copy of the latest code using Git:
114
123
 
115
124
  $ git clone https://github.com/inukshuk/csl-ruby.git
116
125
 
117
- To get started, install the development dependencies and run all tests:
126
+ To get started,
127
+ install the development dependencies and run all tests:
118
128
 
119
129
  $ cd csl-ruby
120
130
  $ bundle install
121
131
  $ rake
122
132
 
123
- If you've found a bug or have a question, please open an issue on the
133
+ If you've found a bug or have a question,
134
+ please open an issue on the
124
135
  [issue tracker](https://github.com/inukshuk/csl-ruby/issues).
125
- Or, for extra credit, clone the CSL-Ruby repository, write a failing
126
- example, fix the bug and submit a pull request.
136
+ Or, for extra credit, clone the CSL-Ruby repository,
137
+ write a failing example, fix the bug and submit a pull request.
127
138
 
128
139
  Credits
129
140
  -------
130
141
  Thanks to Rintze M. Zelle, Sebastian Karcher, Frank G. Bennett, Jr.,
131
- and Bruce D'Arcus of CSL and citeproc-js fame for their support!
142
+ and Bruce D'Arcus of CSL and citeproc-js fame
143
+ for their support!
132
144
 
133
- Thanks to Google and the Berkman Center at Harvard University for supporting
134
- this project as part of [Google Summer of Code](https://developers.google.com/open-source/soc/).
145
+ Thanks to Google and the Berkman Center at Harvard University
146
+ for supporting this project as part of
147
+ [Google Summer of Code](https://developers.google.com/open-source/soc/).
135
148
 
136
149
  Copyright
137
150
  ---------
138
- Copyright 2009-2025 Sylvester Keil. All rights reserved.
151
+ Copyright 2009-2026 Sylvester Keil.
152
+ All rights reserved.
139
153
 
140
154
  Copyright 2012 President and Fellows of Harvard College.
141
155
 
@@ -10,12 +10,8 @@ module CSL
10
10
  end
11
11
 
12
12
  class Module
13
- if RUBY_VERSION < '1.9'
14
- alias const? const_defined?
15
- else
16
- def const?(name)
17
- const_defined?(name, false)
18
- end
13
+ def const?(name)
14
+ const_defined?(name, false)
19
15
  end
20
16
  end
21
17
 
@@ -26,30 +22,11 @@ end unless Struct.instance_methods.include?(:__class__)
26
22
  module CSL
27
23
  module_function
28
24
 
29
- if RUBY_VERSION < '1.9'
30
-
31
- XML_ENTITY_SUBSTITUTION = Hash[*%w{
32
- & &amp; < &lt; > &gt; ' &apos; " &quot;
33
- }].freeze
34
-
35
- def encode_xml_text(string)
36
- string.gsub(/[&<>]/) { |match|
37
- XML_ENTITY_SUBSTITUTION[match]
38
- }
39
- end
40
-
41
- def encode_xml_attr(string)
42
- string.gsub(/[&<>'"]/) { |match|
43
- XML_ENTITY_SUBSTITUTION[match]
44
- }.inspect
45
- end
46
- else
47
- def encode_xml_text(string)
48
- string.encode(string.encoding, :xml => :text)
49
- end
25
+ def encode_xml_text(string)
26
+ string.encode(string.encoding, :xml => :text)
27
+ end
50
28
 
51
- def encode_xml_attr(string)
52
- string.encode(string.encoding, :xml => :attr)
53
- end
29
+ def encode_xml_attr(string)
30
+ string.encode(string.encoding, :xml => :attr)
54
31
  end
55
32
  end
data/lib/csl/info.rb CHANGED
@@ -85,18 +85,6 @@ module CSL
85
85
  end
86
86
  end
87
87
 
88
- # Ruby 1.8 still has Object#id methods so the attr_children generator
89
- # may not have created those; since #id is deprecated in 1.8.7 we're
90
- # forcing the override anyway. Live dangerously!
91
- remove_method :id
92
-
93
- # @return [Id] the id text node
94
- def id
95
- children[:id]
96
- end
97
-
98
- alias id= set_child_id
99
-
100
88
  def self_link!
101
89
  return unless has_id?
102
90
  self.self_link = id
data/lib/csl/loader.rb CHANGED
@@ -9,6 +9,12 @@ module CSL
9
9
  # Base classes are exepcted to define a #parse method.
10
10
  module Loader
11
11
 
12
+ class << self
13
+ attr_accessor :allow_remote
14
+ end
15
+
16
+ @allow_remote = true
17
+
12
18
  attr_accessor :root, :prefix, :extension
13
19
 
14
20
  # @example
@@ -82,8 +88,11 @@ module CSL
82
88
  location = input
83
89
  end
84
90
 
85
- Kernel.open(location, 'r:UTF-8') do |io|
86
- io.read
91
+ if location =~ /\A\w+:\/\//
92
+ raise 'loading from URLs is disabled' unless Loader.allow_remote
93
+ URI.open(location, 'r:UTF-8') { |io| io.read }
94
+ else
95
+ File.open(location, 'r:UTF-8') { |io| io.read }
87
96
  end
88
97
  end
89
98
  rescue => e
data/lib/csl/locale.rb CHANGED
@@ -15,7 +15,7 @@ module CSL
15
15
  @extension = '.xml'.freeze
16
16
  @prefix = 'locales-'.freeze
17
17
 
18
- @tag_pattern = /^[a-z]{2,3}(-[a-z]{4})?(-[a-z]{2})?|-[a-z]{2}$/i
18
+ @tag_pattern = /\A(?:[a-z]{2,3}(-[a-z]{4})?(-[a-z]{2})?|-[a-z]{2})\z/i
19
19
 
20
20
  # Default languages/regions.
21
21
  # Auto-detection is based on these lists.
@@ -40,10 +40,27 @@ module CSL
40
40
  attr_accessor :default
41
41
  attr_reader :languages, :regions, :scripts
42
42
 
43
+ # Loads the locale. For IETF tags without a locale file, falls
44
+ # back to the language's primary dialect and to the default locale.
43
45
  def load(input = nil)
44
46
  input ||= Locale.default
45
- input = normalize input if input.to_s =~ @tag_pattern
46
- super(input)
47
+
48
+ # Drop extensions and private-use subtags (e.g. "-x-...")
49
+ tag = input.to_s.sub(/-[a-z0-9]-.*\z/i, '')
50
+ return super(input) unless tag =~ @tag_pattern
51
+
52
+ tag = normalize(tag)
53
+ candidates = [tag, normalize(tag.split('-')[0]), Locale.default].uniq
54
+
55
+ error = nil
56
+
57
+ candidates.each do |candidate|
58
+ return super(candidate)
59
+ rescue ParseError => e
60
+ error ||= e
61
+ end
62
+
63
+ raise error
47
64
  end
48
65
 
49
66
  # Normalizes an IETF tag; adds default language, region, script.
@@ -493,7 +510,7 @@ module CSL
493
510
  end
494
511
 
495
512
  def preamble
496
- Schema.preamble.dup
513
+ Schema.preamble
497
514
  end
498
515
 
499
516
  # @param other [Locale] an other locale whose options should be merged
data/lib/csl/node.rb CHANGED
@@ -131,8 +131,7 @@ module CSL
131
131
  def attr_struct(*attributes)
132
132
  const_set(:Attributes, Struct.new(*attributes) {
133
133
 
134
- # 1.8 Compatibility
135
- @keys = attributes.map(&:to_sym).freeze
134
+ @keys = members.freeze
136
135
 
137
136
  class << self
138
137
  attr_reader :keys
data/lib/csl/parser.rb CHANGED
@@ -12,8 +12,7 @@ module CSL
12
12
  :nokogiri => lambda { |source|
13
13
  Nokogiri::XML::Document.parse(source, nil, nil,
14
14
  Nokogiri::XML::ParseOptions::DEFAULT_XML |
15
- Nokogiri::XML::ParseOptions::NOBLANKS |
16
- Nokogiri::XML::ParseOptions::NOENT)
15
+ Nokogiri::XML::ParseOptions::NOBLANKS)
17
16
  },
18
17
  :default => lambda { |source|
19
18
  REXML::Document.new(source, :compress_whitespace => :all, :ignore_whitespace_nodes => :all)
@@ -10,7 +10,7 @@ module CSL
10
10
  end
11
11
 
12
12
  def pretty_print
13
- preamble << tags.map { |t| pp t }.join("\n")
13
+ "#{preamble}#{tags.map { |t| pp t }.join("\n")}"
14
14
  end
15
15
 
16
16
  private
@@ -16,7 +16,7 @@ module CSL
16
16
 
17
17
  has_no_children
18
18
 
19
- @variables = [:locator, :page].concat(Schema.variables[:number]).freeze
19
+ @variables = ([:locator, :page] | Schema.variables[:number]).freeze
20
20
 
21
21
  @terms = Hash.new { |h,k| h[k] = k }
22
22
 
data/lib/csl/style.rb CHANGED
@@ -80,20 +80,20 @@ module CSL
80
80
 
81
81
  remove_method :info # generated by struct_children
82
82
  def info
83
- children[:info] ||= Info.new
83
+ children[:info] || add_child(Info.new)
84
84
  end
85
85
 
86
86
  alias_child :metadata, :info
87
87
 
88
88
  # @return [String] the style's id
89
89
  def id
90
- return unless info.has_id?
90
+ return unless has_info? && info.has_id?
91
91
  info.id.to_s
92
92
  end
93
93
 
94
94
  # @return [String] the style's title
95
95
  def title
96
- return unless info.has_title?
96
+ return unless has_info? && info.has_title?
97
97
  info.title.to_s
98
98
  end
99
99
 
@@ -141,7 +141,7 @@ module CSL
141
141
  private
142
142
 
143
143
  def preamble
144
- Schema.preamble.dup
144
+ Schema.preamble
145
145
  end
146
146
 
147
147
  def load_related_style_from(uri)
data/lib/csl/treelike.rb CHANGED
@@ -349,8 +349,7 @@ module CSL
349
349
 
350
350
  const_set(:Children, Struct.new(*names) {
351
351
 
352
- # 1.8 Compatibility
353
- @keys = members.map(&:to_sym).freeze
352
+ @keys = members.freeze
354
353
 
355
354
  class << self
356
355
  attr_reader :keys
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
data/lib/csl.rb CHANGED
@@ -1,5 +1,4 @@
1
1
 
2
- require 'enumerator'
3
2
  require 'forwardable'
4
3
  require 'open-uri'
5
4
  require 'singleton'
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.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-16 00:00:00.000000000 Z
10
+ date: 2026-10-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: namae
@@ -117,17 +117,8 @@ executables: []
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
- - ".document"
121
- - ".github/workflows/ci.yml"
122
- - ".gitignore"
123
- - ".yardopts"
124
- - AGPL
125
120
  - BSDL
126
- - Gemfile
127
121
  - README.md
128
- - Rakefile
129
- - csl.gemspec
130
- - cucumber.yml
131
122
  - lib/csl.rb
132
123
  - lib/csl/compatibility.rb
133
124
  - lib/csl/date_part.rb
@@ -176,14 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
167
  requirements:
177
168
  - - ">="
178
169
  - !ruby/object:Gem::Version
179
- version: '2.2'
170
+ version: '3.1'
180
171
  required_rubygems_version: !ruby/object:Gem::Requirement
181
172
  requirements:
182
173
  - - ">="
183
174
  - !ruby/object:Gem::Version
184
175
  version: '0'
185
176
  requirements: []
186
- rubygems_version: 3.7.2
177
+ rubygems_version: 4.0.22
187
178
  specification_version: 4
188
179
  summary: A Ruby CSL parser and library
189
180
  test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- AGPL
5
- README.md
@@ -1,33 +0,0 @@
1
- name: CI
2
- on:
3
- push:
4
- branches:
5
- - master
6
- pull_request:
7
- branches:
8
- - master
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
- env:
13
- BUNDLE_WITHOUT: debug:extra
14
- strategy:
15
- matrix:
16
- ruby-version:
17
- - 3.4
18
- - 3.3
19
- - 3.2
20
- - 3.1
21
- steps:
22
- - uses: actions/checkout@v4
23
- - uses: ruby/setup-ruby@v1
24
- with:
25
- ruby-version: ${{ matrix.ruby-version }}
26
- bundler-cache: true
27
- - run: bundle exec rake
28
- - name: Upload coverage results
29
- if: matrix.ruby-version == '3.3'
30
- continue-on-error: true
31
- uses: coverallsapp/github-action@v2
32
- with:
33
- github-token: ${{ github.token }}
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- .DS_Store
2
- Gemfile.lock
3
- /coverage
4
- /pkg
5
- /doc
6
- /.yardoc
7
- /.rbx
8
- *.rbc
9
- *.swp
10
- *.gem
11
- .ruby-version
12
- .rvm
13
- .bundle
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --no-private
2
- --document