csl 1.0.0.pre23 → 1.0.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 +95 -8
- data/csl.gemspec +2 -2
- data/lib/csl/compatibility.rb +19 -1
- data/lib/csl/info.rb +1 -1
- data/lib/csl/locale/date.rb +1 -1
- data/lib/csl/schema.rb +2 -12
- data/lib/csl/style/choose.rb +4 -3
- data/lib/csl/style/date.rb +6 -6
- data/lib/csl/style/group.rb +1 -1
- data/lib/csl/style/label.rb +4 -4
- data/lib/csl/style/names.rb +1 -1
- data/lib/csl/style/number.rb +9 -10
- data/lib/csl/style/text.rb +1 -1
- data/lib/csl/version.rb +1 -1
- data/spec/csl/style/number_spec.rb +1 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e127a1013d127c41a6347da7c25756a0d3814d
|
4
|
+
data.tar.gz: 2f318db850403ee396c43e39dfb7be716559ac69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ecf845a872d83a9393cca66ce068575cc314931521cb3fd4009eced2b1ada5a7caa8d48ff39ae89cf7b878a538e59cd7ae5b7523b1e295dda47d4c43c25565a
|
7
|
+
data.tar.gz: 5496e604da7d3a7130959161fe09ebac68d6a6cd2d652036dabc9a2adbe234f3288510be89f9a35f2607dd7f9874a01e70f1ca31cb9788efb3ab51511760aaaa
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
CSL-Ruby
|
2
2
|
========
|
3
|
-
CSL-Ruby
|
4
|
-
|
5
|
-
bibliographies.
|
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.
|
6
6
|
|
7
7
|
[](http://travis-ci.org/inukshuk/csl-ruby)
|
8
8
|
|
@@ -20,7 +20,94 @@ You can change these locations by changing the value of `CSL::Style.root` and
|
|
20
20
|
`CSL::Locale.root` respectively.
|
21
21
|
|
22
22
|
Alternatively, you can `gem install csl-styles` to install all official CSL
|
23
|
-
styles and locales.
|
23
|
+
styles and locales. To make the styles and locales available, simply
|
24
|
+
`require 'csl/styles`.
|
25
|
+
|
26
|
+
Usage
|
27
|
+
-----
|
28
|
+
CSL-Ruby is broadly aimed at two very different usage scenarios: on the one
|
29
|
+
hand, you can use the parser to load existing styles and locales and
|
30
|
+
manipulate, query or otherwise work with them using a dedicated API: that is
|
31
|
+
to say, you do not have to resort to XML-related methods of access, but can
|
32
|
+
make use of a large set of library methods which are specific to CSL. This
|
33
|
+
is useful, primarily, for citation processors like
|
34
|
+
[CiteProc-Ruby](https://github.com/inukshuk/citeproc-ruby).
|
35
|
+
|
36
|
+
On the other hand, CSL-Ruby makes it easy to create new styles and locales
|
37
|
+
using Ruby; this is useful, for example, if you need to change or adapt
|
38
|
+
styles on-the-fly or for writing an interactive style editor.
|
39
|
+
|
40
|
+
To get you started, here are a few usage examples; for the full set of
|
41
|
+
available features, please consult the
|
42
|
+
[API documentation](http://rubydoc.info/gems/csl/).
|
43
|
+
|
44
|
+
require 'csl'
|
45
|
+
|
46
|
+
# Load a style from the Zotero style repository
|
47
|
+
jps = CSL::Style.load 'http://zotero.org/styles/american-journal-of-political-science'
|
48
|
+
|
49
|
+
# Query style information
|
50
|
+
jps.title #-> "American Journal of Political Science"
|
51
|
+
jps.independent? #-> true
|
52
|
+
jps.citation_format #-> :"author-date"
|
53
|
+
|
54
|
+
# Validate style against the CSL schema
|
55
|
+
jps.valid? #-> true
|
56
|
+
|
57
|
+
# Load another style
|
58
|
+
amc = CSL::Style.load 'http://zotero.org/styles/applied-mathematics-and-computation'
|
59
|
+
|
60
|
+
amc.independent? #-> false
|
61
|
+
|
62
|
+
# Load the independent parent style
|
63
|
+
parent = amc.independent_parent
|
64
|
+
parent.title #-> "Elsevier (numeric, with titles)"
|
65
|
+
|
66
|
+
# Load standard CSL styles and locales from csl-styles gem
|
67
|
+
# Requires you to gem install csl-styles
|
68
|
+
require 'csl/styles'
|
69
|
+
|
70
|
+
# Load a locally installed style
|
71
|
+
apa = CSL::Style.load :apa
|
72
|
+
|
73
|
+
# Fetch the a macro
|
74
|
+
authors = apa.macros['authors'].children[0]
|
75
|
+
#-> #<CSL::Style::Names variable="author" children=[2]>
|
76
|
+
|
77
|
+
# Load a locally installed locale
|
78
|
+
fr = CSL::Locale.load :fr
|
79
|
+
|
80
|
+
# Translate a term
|
81
|
+
fr.translate 'editor' #-> "éditeur"
|
82
|
+
fr.translate 'editor', plural: true #-> "éditeurs"
|
83
|
+
fr.translate 'editor', form: 'short' #-> "éd."
|
84
|
+
|
85
|
+
# Ordinalize a number
|
86
|
+
fr.ordinalize 42 #=> "42ᵉ"
|
87
|
+
fr.ordinalize 3, form: 'long' => "troisième"
|
88
|
+
|
89
|
+
# Create a new style
|
90
|
+
style = CSL::Style.new
|
91
|
+
|
92
|
+
style.id = 'http://www.zotero.org/styles/my-style'
|
93
|
+
style.title = 'My Style'
|
94
|
+
|
95
|
+
# Add the default license for CSL styles
|
96
|
+
style.default_license!
|
97
|
+
|
98
|
+
# Access the style as XML
|
99
|
+
style.to_xml
|
100
|
+
|
101
|
+
# Access the style as XML (pretty printed)
|
102
|
+
style.to_s
|
103
|
+
|
104
|
+
Dependencies
|
105
|
+
------------
|
106
|
+
CSL-Ruby was written with portability in mind. For performance reasons it
|
107
|
+
will use [Nokogiri ](http://nokogiri.org) for XML parsing and validation
|
108
|
+
if available; however, CSL-Ruby will fallback to REXML from the Ruby standard
|
109
|
+
library. In order to use Nokogiri, simply `gem install nokogiri` or add it
|
110
|
+
to your Gemfile.
|
24
111
|
|
25
112
|
Development
|
26
113
|
-----------
|
@@ -28,7 +115,7 @@ The CSL-Ruby source code is [hosted on GitHub](https://github.com/inukshuk/csl-r
|
|
28
115
|
You can check out a copy of the latest code using Git:
|
29
116
|
|
30
117
|
$ git clone https://github.com/inukshuk/csl-ruby.git
|
31
|
-
|
118
|
+
|
32
119
|
To get started, install the development dependencies and run all tests:
|
33
120
|
|
34
121
|
$ cd csl-ruby
|
@@ -43,10 +130,10 @@ example, fix the bug and submit a pull request.
|
|
43
130
|
|
44
131
|
Copyright
|
45
132
|
---------
|
46
|
-
Copyright 2012 President and Fellows of Harvard College.
|
47
|
-
|
48
133
|
Copyright 2009-2013 Sylvester Keil. All rights reserved.
|
49
134
|
|
135
|
+
Copyright 2012 President and Fellows of Harvard College.
|
136
|
+
|
50
137
|
License
|
51
138
|
-------
|
52
|
-
|
139
|
+
CSL-Ruby is dual licensed under the AGPL and the FreeBSD license.
|
data/csl.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.summary = 'A Ruby CSL parser and library'
|
15
15
|
s.description =
|
16
16
|
"""
|
17
|
-
A Ruby parser and
|
17
|
+
A Ruby parser and full API for the Citation Style Language (CSL),
|
18
18
|
an open XML-based language to describe the formatting of citations
|
19
19
|
and bibliographies.
|
20
20
|
"""
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.license = 'AGPL'
|
23
23
|
s.date = Time.now.strftime('%Y-%m-%d')
|
24
24
|
|
25
|
-
s.add_dependency('namae', ['~>0.
|
25
|
+
s.add_dependency('namae', ['~>0.7'])
|
26
26
|
|
27
27
|
s.files = `git ls-files`.split("\n")
|
28
28
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/csl/compatibility.rb
CHANGED
@@ -3,9 +3,27 @@ class Symbol
|
|
3
3
|
include Comparable
|
4
4
|
|
5
5
|
def <=>(other)
|
6
|
-
return unless other.kind_of?
|
6
|
+
return unless other.kind_of?(Symbol)
|
7
7
|
to_s <=> other.to_s
|
8
8
|
end
|
9
|
+
|
10
|
+
def match(pattern)
|
11
|
+
str = to_s
|
12
|
+
|
13
|
+
case pattern
|
14
|
+
when Regexp
|
15
|
+
match_data = pattern.search_region(str, 0, str.bytesize, true)
|
16
|
+
Regexp.last_match = match_data
|
17
|
+
return match_data.full[0] if match_data
|
18
|
+
when String
|
19
|
+
raise TypeError, "type mismatch: String given"
|
20
|
+
else
|
21
|
+
pattern =~ str
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
alias =~ match
|
26
|
+
|
9
27
|
end unless Symbol.is_a?(Comparable)
|
10
28
|
|
11
29
|
class Module
|
data/lib/csl/info.rb
CHANGED
data/lib/csl/locale/date.rb
CHANGED
data/lib/csl/schema.rb
CHANGED
@@ -10,8 +10,7 @@ module CSL
|
|
10
10
|
|
11
11
|
@default_license = 'http://creativecommons.org/licenses/by-sa/3.0/'
|
12
12
|
@default_rights_string =
|
13
|
-
|
14
|
-
|
13
|
+
'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License'
|
15
14
|
|
16
15
|
@types = %w{ article article-journal article-magazine article-newspaper
|
17
16
|
bill book broadcast chapter entry entry-dictionary entry-encyclopedia
|
@@ -69,18 +68,9 @@ module CSL
|
|
69
68
|
:delimiter => %w{
|
70
69
|
delimiter
|
71
70
|
},
|
72
|
-
:display => %w{
|
73
|
-
block left-margin right-inline indent
|
74
|
-
},
|
75
71
|
:font => %w{
|
76
72
|
font-style font-variant font-weight text-decoration vertical-align
|
77
73
|
},
|
78
|
-
:quotes => %w{
|
79
|
-
quotes
|
80
|
-
},
|
81
|
-
:periods => %w{
|
82
|
-
strip-periods
|
83
|
-
},
|
84
74
|
:name => %w{
|
85
75
|
name-form name-delimiter and delimiter-precedes-et-al initialize-with
|
86
76
|
delimiter-precedes-last et-al-min et-al-use-first et-al-subsequent-min
|
@@ -103,7 +93,7 @@ module CSL
|
|
103
93
|
|
104
94
|
@attributes.each_value { |v| v.map!(&:to_sym).freeze }
|
105
95
|
|
106
|
-
@attributes[:formatting] = [:'text-case'].concat(
|
96
|
+
@attributes[:formatting] = [:'text-case', :display].concat(
|
107
97
|
@attributes.values_at(:affixes, :font).flatten)
|
108
98
|
|
109
99
|
@attributes.freeze
|
data/lib/csl/style/choose.rb
CHANGED
@@ -21,7 +21,7 @@ module CSL
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def matcher(match = attributes[:match])
|
24
|
-
case match
|
24
|
+
case match.to_s
|
25
25
|
when 'any'
|
26
26
|
:any?
|
27
27
|
when 'none'
|
@@ -37,8 +37,9 @@ module CSL
|
|
37
37
|
type, match = attribute.to_s.split(/-(any|all|none)$/, 2)
|
38
38
|
|
39
39
|
# subtle: if the default matcher is :none? and there
|
40
|
-
# is no override we to use :any?
|
41
|
-
# to avoid double negation during evaluation
|
40
|
+
# is no override we want to use :any? inside the nested
|
41
|
+
# lists to avoid double negation during evaluation of
|
42
|
+
# the entire expression!
|
42
43
|
|
43
44
|
if match.nil?
|
44
45
|
match = matcher
|
data/lib/csl/style/date.rb
CHANGED
@@ -4,8 +4,8 @@ module CSL
|
|
4
4
|
class Date < Node
|
5
5
|
attr_defaults :'date-parts' => 'year-month-day'
|
6
6
|
|
7
|
-
attr_struct :name, :form, :'range-delimiter', :'date-parts',
|
8
|
-
|
7
|
+
attr_struct :name, :form, :'range-delimiter', :'date-parts',
|
8
|
+
:variable, *Schema.attr(:formatting, :delimiter)
|
9
9
|
|
10
10
|
attr_children :'date-part'
|
11
11
|
|
@@ -49,11 +49,11 @@ module CSL
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def numeric?
|
52
|
-
|
52
|
+
form =~ /^numeric$/i
|
53
53
|
end
|
54
54
|
|
55
55
|
def text?
|
56
|
-
|
56
|
+
form =~ /^text$/i
|
57
57
|
end
|
58
58
|
|
59
59
|
def has_date_parts?
|
@@ -69,8 +69,8 @@ module CSL
|
|
69
69
|
class DatePart < Node
|
70
70
|
has_no_children
|
71
71
|
|
72
|
-
attr_struct :name, :form, :'range-delimiter',
|
73
|
-
*Schema.attr(:formatting
|
72
|
+
attr_struct :name, :form, :'range-delimiter', :'strip-periods',
|
73
|
+
*Schema.attr(:formatting)
|
74
74
|
|
75
75
|
include CSL::DatePart
|
76
76
|
end
|
data/lib/csl/style/group.rb
CHANGED
@@ -13,7 +13,7 @@ module CSL
|
|
13
13
|
# the Group calls a variable (either directly or via a macro), and
|
14
14
|
# b) all variables that are called are empty.
|
15
15
|
class Group < Node
|
16
|
-
attr_struct(*Schema.attr(:formatting, :affixes, :
|
16
|
+
attr_struct(*Schema.attr(:formatting, :affixes, :delimiter))
|
17
17
|
|
18
18
|
def delimiter
|
19
19
|
attributes.fetch(:delimiter, '')
|
data/lib/csl/style/label.rb
CHANGED
@@ -11,8 +11,8 @@ module CSL
|
|
11
11
|
# is used instead of the local attribute.
|
12
12
|
class Label < Node
|
13
13
|
|
14
|
-
attr_struct :variable, :form, :plural,
|
15
|
-
*Schema.attr(:formatting
|
14
|
+
attr_struct :variable, :form, :plural, :'strip-periods',
|
15
|
+
*Schema.attr(:formatting)
|
16
16
|
|
17
17
|
has_no_children
|
18
18
|
|
@@ -57,11 +57,11 @@ module CSL
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def always_pluralize?
|
60
|
-
attributes[:plural]
|
60
|
+
attribute?(:plural) && attributes[:plural] =~ /^always$/i
|
61
61
|
end
|
62
62
|
|
63
63
|
def never_pluralize?
|
64
|
-
attributes[:plural]
|
64
|
+
attribute?(:plural) && attributes[:plural] =~ /^never$/i
|
65
65
|
end
|
66
66
|
|
67
67
|
# @return [Boolean] whether or not the {Label} is inside a {Names} node
|
data/lib/csl/style/names.rb
CHANGED
data/lib/csl/style/number.rb
CHANGED
@@ -4,8 +4,7 @@ module CSL
|
|
4
4
|
# Numbers are CSL rendering elements which output the number variable
|
5
5
|
# selected with the required variable attribute.
|
6
6
|
class Number < Node
|
7
|
-
attr_struct :variable, :form, :
|
8
|
-
*Schema.attr(:affixes, :display, :font)
|
7
|
+
attr_struct :variable, :form, *Schema.attr(:formatting)
|
9
8
|
|
10
9
|
has_no_children
|
11
10
|
|
@@ -22,29 +21,29 @@ module CSL
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def form
|
25
|
-
attributes[:form]
|
24
|
+
attributes[:form].to_s
|
26
25
|
end
|
27
26
|
|
28
27
|
# @return [Boolean] whether or not the number's format is set to
|
29
28
|
# :numeric; also returns true if the number's form attribute is not
|
30
29
|
# set or nil.
|
31
30
|
def numeric?
|
32
|
-
!has_form? || form
|
31
|
+
!has_form? || form == 'numeric'
|
33
32
|
end
|
34
33
|
|
35
|
-
# @return [Boolean] whether or not the number's format is set to
|
34
|
+
# @return [Boolean] whether or not the number's format is set to 'ordinal
|
36
35
|
def ordinal?
|
37
|
-
has_form? && form
|
36
|
+
has_form? && form == 'ordinal'
|
38
37
|
end
|
39
38
|
|
40
|
-
# @return [Boolean] whether or not the number's format is set to
|
39
|
+
# @return [Boolean] whether or not the number's format is set to 'long-ordinal'
|
41
40
|
def long_ordinal?
|
42
|
-
has_form? && form
|
41
|
+
has_form? && form == 'long-ordinal'
|
43
42
|
end
|
44
43
|
|
45
|
-
# @return [Boolean] whether or not the number's format is set to
|
44
|
+
# @return [Boolean] whether or not the number's format is set to 'roman'
|
46
45
|
def roman?
|
47
|
-
has_form? && form
|
46
|
+
has_form? && form == 'roman'
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
data/lib/csl/style/text.rb
CHANGED
data/lib/csl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: namae
|
@@ -16,15 +16,15 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
27
|
-
description: "\n\t\tA Ruby parser and
|
26
|
+
version: '0.7'
|
27
|
+
description: "\n\t\tA Ruby parser and full API for the Citation Style Language (CSL),\n\t\tan
|
28
28
|
open XML-based language to describe the formatting of citations\n\t\tand bibliographies.\n\t\t"
|
29
29
|
email:
|
30
30
|
- http://sylvester.keil.or.at
|
@@ -132,9 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- - '
|
135
|
+
- - '>='
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
137
|
+
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
140
|
rubygems_version: 2.0.3
|