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 +4 -4
- data/README.md +58 -44
- data/lib/csl/compatibility.rb +7 -30
- data/lib/csl/info.rb +0 -12
- data/lib/csl/loader.rb +11 -2
- data/lib/csl/locale.rb +21 -4
- data/lib/csl/node.rb +1 -2
- data/lib/csl/parser.rb +1 -2
- data/lib/csl/pretty_printer.rb +1 -1
- data/lib/csl/style/label.rb +1 -1
- data/lib/csl/style.rb +4 -4
- data/lib/csl/treelike.rb +1 -2
- data/lib/csl/version.rb +1 -1
- data/lib/csl.rb +0 -1
- metadata +4 -13
- data/.document +0 -5
- data/.github/workflows/ci.yml +0 -33
- data/.gitignore +0 -13
- data/.yardopts +0 -2
- data/AGPL +0 -662
- data/Gemfile +0 -32
- data/Rakefile +0 -61
- data/csl.gemspec +0 -45
- data/cucumber.yml +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c0f6649dcc754264a3546a210a92cc4dd50ed8910ef011d61c0db3818cb1c576
|
|
4
|
+
data.tar.gz: 85ebc13c82b78cfefd1898c1e44380acea10fead06a1ac7bb4a34dc09b51d77b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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](
|
|
5
|
-
format to describe the formatting
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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`
|
|
21
|
-
|
|
22
|
-
|
|
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:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 '
|
|
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 '
|
|
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['
|
|
73
|
-
#-> #<CSL::Style::
|
|
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'
|
|
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.
|
|
105
|
-
will use [Nokogiri
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
to
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
134
|
-
this project as part of
|
|
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-
|
|
151
|
+
Copyright 2009-2026 Sylvester Keil.
|
|
152
|
+
All rights reserved.
|
|
139
153
|
|
|
140
154
|
Copyright 2012 President and Fellows of Harvard College.
|
|
141
155
|
|
data/lib/csl/compatibility.rb
CHANGED
|
@@ -10,12 +10,8 @@ module CSL
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class Module
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
& & < < > > ' ' " "
|
|
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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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 =
|
|
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
|
-
|
|
46
|
-
|
|
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
|
|
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
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)
|
data/lib/csl/pretty_printer.rb
CHANGED
data/lib/csl/style/label.rb
CHANGED
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]
|
|
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
|
|
144
|
+
Schema.preamble
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def load_related_style_from(uri)
|
data/lib/csl/treelike.rb
CHANGED
data/lib/csl/version.rb
CHANGED
data/lib/csl.rb
CHANGED
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
|
+
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:
|
|
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: '
|
|
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:
|
|
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/.github/workflows/ci.yml
DELETED
|
@@ -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
data/.yardopts
DELETED