citeproc 1.0.0.pre12 → 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 +7 -0
- data/.simplecov +4 -0
- data/AGPL +1 -1
- data/BSDL +2 -2
- data/Gemfile +39 -19
- data/README.md +123 -14
- data/Rakefile +22 -8
- data/cucumber.yml +1 -1
- data/features/step_definitions/processor.rb +59 -0
- data/features/support/env.rb +45 -2
- data/lib/citeproc.rb +8 -8
- data/lib/citeproc/abbreviate.rb +5 -4
- data/lib/citeproc/assets.rb +109 -109
- data/lib/citeproc/attributes.rb +11 -11
- data/lib/citeproc/bibliography.rb +107 -71
- data/lib/citeproc/citation_data.rb +175 -150
- data/lib/citeproc/compatibility.rb +5 -108
- data/lib/citeproc/date.rb +23 -12
- data/lib/citeproc/engine.rb +9 -4
- data/lib/citeproc/errors.rb +6 -6
- data/lib/citeproc/extensions.rb +66 -66
- data/lib/citeproc/item.rb +60 -2
- data/lib/citeproc/names.rb +103 -24
- data/lib/citeproc/number.rb +27 -8
- data/lib/citeproc/processor.rb +31 -41
- data/lib/citeproc/selector.rb +132 -126
- data/lib/citeproc/utilities.rb +6 -6
- data/lib/citeproc/variable.rb +5 -4
- data/lib/citeproc/version.rb +1 -1
- data/spec/citeproc/assets_spec.rb +17 -15
- data/spec/citeproc/bibliography_spec.rb +17 -17
- data/spec/citeproc/citation_data_spec.rb +90 -90
- data/spec/citeproc/engine_spec.rb +3 -4
- data/spec/citeproc/item_spec.rb +76 -68
- data/spec/citeproc/names_spec.rb +187 -148
- data/spec/citeproc/processor_spec.rb +119 -115
- data/spec/citeproc/selector_spec.rb +87 -78
- data/spec/citeproc/variable_spec.rb +30 -30
- data/spec/fixtures/locales/locales-en-US.xml +304 -0
- data/spec/spec_helper.rb +32 -1
- data/tasks/testsuite.rb +209 -0
- metadata +19 -87
- data/.gitignore +0 -6
- data/.travis.yml +0 -21
- data/citeproc.gemspec +0 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53a6b76b4acbcdf2fbb930e63301e17562cbf864
|
4
|
+
data.tar.gz: 8d609c36df5cda49552269df91042682bc06e9a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4c3642540b8cf3af9fa23b1a8da4a08265da2795899ca4995eaf20b12d7c4814177bbafcd37b61c804b87f281b81d4f029bc1b81ff32c742bd92db72ccf95b2
|
7
|
+
data.tar.gz: 340736821671a7c6bd27e3326ff03f918feb95a54236e8a9c79b6e6c66085f0aa083cae02bd478a429eb594371ddb91954ed4b807bd2c4a77319cc3ca0b5a8de
|
data/.simplecov
ADDED
data/AGPL
CHANGED
@@ -631,7 +631,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
|
631
631
|
|
632
632
|
CiteProc. A CSL Cite Processor API
|
633
633
|
Copyright 2012 President and Fellows of Harvard College.
|
634
|
-
Copyright 2009-
|
634
|
+
Copyright 2009-2014 Sylvester Keil. All rights reserved.
|
635
635
|
|
636
636
|
This program is free software: you can redistribute it and/or modify
|
637
637
|
it under the terms of the GNU Affero General Public License as published by
|
data/BSDL
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright 2012 President and Fellows of Harvard College.
|
2
|
-
Copyright 2009-
|
2
|
+
Copyright 2009-2014 Sylvester Keil. All rights reserved.
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
@@ -24,4 +24,4 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
24
24
|
|
25
25
|
The views and conclusions contained in the software and documentation are
|
26
26
|
those of the authors and should not be interpreted as representing official
|
27
|
-
policies, either expressed or implied, of the copyright holder.
|
27
|
+
policies, either expressed or implied, of the copyright holder.
|
data/Gemfile
CHANGED
@@ -1,29 +1,49 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :debug do
|
5
|
-
gem '
|
5
|
+
gem 'ruby-debug', :require => false, :platform => :jruby
|
6
|
+
gem 'debugger', '~>1.6', :require => false, :platform => :mri
|
7
|
+
gem 'rubinius-compiler', '~>2.0', :require => false, :platform => :rbx
|
8
|
+
gem 'rubinius-debugger', '~>2.0', :require => false, :platform => :rbx
|
6
9
|
end
|
7
10
|
|
8
11
|
group :optional do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
gem 'guard', '~>
|
17
|
-
gem 'guard-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
gem '
|
24
|
-
gem '
|
12
|
+
gem 'nokogiri', '~>1.6'
|
13
|
+
gem 'chronic', '~>0.10', :require => false
|
14
|
+
gem 'edtf', '~>2.1'
|
15
|
+
|
16
|
+
gem 'bibtex-ruby', '~>3.0', :require => 'bibtex'
|
17
|
+
|
18
|
+
gem 'guard', '~>2.2'
|
19
|
+
gem 'guard-rspec', '~>4.2'
|
20
|
+
gem 'guard-cucumber', '~>1.4'
|
21
|
+
|
22
|
+
gem 'pry'
|
23
|
+
|
24
|
+
gem 'unicode', '~>0.4', :platforms => [:ruby, :mswin, :mingw]
|
25
|
+
|
26
|
+
gem 'citeproc-ruby', :github => 'inukshuk/citeproc-ruby'
|
27
|
+
#gem 'csl', :github => 'inukshuk/csl-ruby'
|
28
|
+
end
|
29
|
+
|
30
|
+
group :development do
|
31
|
+
gem 'rake'
|
32
|
+
gem 'cucumber'
|
33
|
+
gem 'rspec'
|
34
|
+
gem 'simplecov', '~>0.8', :require => false
|
35
|
+
gem 'rubinius-coverage', :platform => :rbx
|
36
|
+
gem 'coveralls', :require => false
|
37
|
+
gem 'csl-styles', '~>1.0.1', :require => false
|
25
38
|
end
|
26
39
|
|
27
40
|
group :extra do
|
28
|
-
gem '
|
41
|
+
gem 'yard', '~>0.8', :platforms => :ruby
|
42
|
+
gem 'redcarpet', '~>3.0', :platform => :mri
|
43
|
+
end
|
44
|
+
|
45
|
+
platform :rbx do
|
46
|
+
gem 'rubysl', '~>2.0'
|
47
|
+
gem 'json', '~>1.8'
|
48
|
+
gem 'racc'
|
29
49
|
end
|
data/README.md
CHANGED
@@ -2,34 +2,143 @@ CiteProc
|
|
2
2
|
========
|
3
3
|
CiteProc is a cite processor interface and citation data API based on the
|
4
4
|
Citation Style Language (CSL) specifications. To actually process citations
|
5
|
-
a dedicated processor engine is required;
|
6
|
-
gems.
|
5
|
+
a dedicated processor engine is required; a pure Ruby engine is available
|
6
|
+
in the [citeproc-ruby](https://rubygems/gems/citeproc-ruby) gem.
|
7
7
|
|
8
|
-
### A word of caution
|
9
|
-
As work on this and on the related packages is still in progress, please
|
10
|
-
be aware of the following caveats: the 0.0.x branch of citeproc-ruby is still
|
11
|
-
a standalone package and will conflict with this release of citeproc; support
|
12
|
-
will be added in future versions of the 1.x.x branch.
|
13
8
|
|
14
|
-
[](http://travis-ci.org/inukshuk/citeproc)
|
10
|
+
[](https://coveralls.io/r/inukshuk/citeproc?branch=master)
|
11
|
+
[](https://gemnasium.com/inukshuk/citeproc)
|
15
12
|
|
13
|
+
[](http://travis-ci.org/inukshuk/citeproc-ruby)
|
14
|
+
[](https://coveralls.io/r/inukshuk/citeproc-ruby?branch=master)
|
15
|
+
[](https://gemnasium.com/inukshuk/citeproc-ruby)
|
16
16
|
|
17
|
-
|
17
|
+
[](http://travis-ci.org/inukshuk/csl-ruby)
|
18
|
+
[](https://coveralls.io/r/inukshuk/csl-ruby?branch=master)
|
19
|
+
[](https://gemnasium.com/inukshuk/csl-ruby)
|
20
|
+
|
21
|
+
Quickstart
|
22
|
+
----------
|
23
|
+
Install CiteProc-Ruby and all official CSL styles (optional).
|
24
|
+
|
25
|
+
$ [sudo] gem install citeproc-ruby
|
26
|
+
$ [sudo] gem install csl-styles
|
27
|
+
|
28
|
+
Start rendering you references with any CSL style!
|
29
|
+
|
30
|
+
require 'citeproc'
|
31
|
+
require 'csl/styles'
|
32
|
+
|
33
|
+
# Create a new processor with the desired style,
|
34
|
+
# format, and locale.
|
35
|
+
cp = CiteProc::Processor.new style: 'apa', format: 'text'
|
36
|
+
|
37
|
+
# To see what styles are available in your current
|
38
|
+
# environment, run `CSL::Style.ls'; this also works for
|
39
|
+
# locales as `CSL::Locale.ls'.
|
40
|
+
|
41
|
+
# Tell the processor where to find your references. In this
|
42
|
+
# example we load them from a BibTeX bibliography using the
|
43
|
+
# bibtex-ruby gem.
|
44
|
+
cp.import BibTeX.open('./references.bib').to_citeproc
|
45
|
+
|
46
|
+
# Now you are ready for rendering; the processor API
|
47
|
+
# provides three main rendering methods: `process',
|
48
|
+
# `append', or `bibliography'.
|
49
|
+
|
50
|
+
# For simple one-off renditions, you can also call
|
51
|
+
# `render' in bibliography or citation mode:
|
52
|
+
cp.render :bibliography, id: 'knuth'
|
53
|
+
|
54
|
+
# This will return a rendered reference, like:
|
55
|
+
#-> Knuth, D. (1968). The art of computer programming. Boston: Addison-Wesley.
|
56
|
+
|
57
|
+
# CiteProc-Ruby exposes a full CSL API to you; this
|
58
|
+
# makes it possible to just alter CSL styles on the
|
59
|
+
# fly. For example, what if we want names not to be
|
60
|
+
# initialized even though APA style is configured to
|
61
|
+
# do so? We could change the CSL style itself, but
|
62
|
+
# we can also make a quick adjustment at runtime:
|
63
|
+
name = cp.engine.style.macros['author'] > 'names' > 'name'
|
64
|
+
|
65
|
+
# What just happened? We selected the current style's
|
66
|
+
# 'author' macro and then descended to the CSL name
|
67
|
+
# node via its parent names node. Now we can change
|
68
|
+
# this name node and the cite processor output will
|
69
|
+
# pick-up the changes right away:
|
70
|
+
name[:initialize] = 'false'
|
71
|
+
|
72
|
+
cp.render :bibliography, id: 'knuth'
|
73
|
+
#-> Knuth, Donald. (1968). The art of computer programming (Vol. 1). Boston: Addison-Wesley.
|
74
|
+
|
75
|
+
# Note that we have picked 'text' as the output format;
|
76
|
+
# if we want to make us of richer output formats we
|
77
|
+
# can switch to HTML instead:
|
78
|
+
cp.engine.format = 'html'
|
79
|
+
|
80
|
+
cp.render :bibliography, id: 'knuth'
|
81
|
+
#-> Knuth, Donald. (1968). <i>The art of computer programming</i> (Vol. 1). Boston: Addison-Wesley.
|
82
|
+
|
83
|
+
# You can also render citations on the fly.
|
84
|
+
cp.render :citation, id: 'knuth', locator: '23'
|
85
|
+
#-> (Knuth, 1968, p. 23)
|
86
|
+
|
87
|
+
Documentation
|
18
88
|
-------------
|
89
|
+
* [CiteProc Documentation](http://rubydoc.info/gems/citeproc/)
|
90
|
+
* [CiteProc-Ruby API Documentation](http://rubydoc.info/gems/citeproc-ruby/)
|
91
|
+
* [CSL-Ruby API Documentation](http://rubydoc.info/gems/csl/)
|
92
|
+
|
93
|
+
Optional Dependencies
|
94
|
+
---------------------
|
95
|
+
CiteProc-Ruby tries to minimize hard dependencies for increased compatibility.
|
96
|
+
You can speed up the XML parsing by installing
|
97
|
+
[Nokogiri](https://rubygems.org/gems/nokogiri); otherwise the REXML from the
|
98
|
+
Ruby standard library will be used.
|
99
|
+
|
100
|
+
Similarly, you can install either of the gems
|
101
|
+
[EDTF](https://rubygems.org/gems/edtf) or
|
102
|
+
[Chronic](https://rubygems.org/gems/chronic) to support a wide range of
|
103
|
+
additional inputs for date variables.
|
104
|
+
|
105
|
+
CSL Styles and Locales
|
106
|
+
----------------------
|
107
|
+
You can load CSL styles and locales by passing a respective XML string, file
|
108
|
+
name, or URL. You can also load styles and locales by name if the
|
109
|
+
corresponding files are installed in your local styles and locale directories.
|
110
|
+
By default, CSL-Ruby looks for CSL styles and locale files in
|
19
111
|
|
20
|
-
|
21
|
-
|
112
|
+
/usr/local/share/csl/styles
|
113
|
+
/usr/local/share/csl/locales
|
114
|
+
|
115
|
+
You can change these locations by changing the value of `CSL::Style.root` and
|
116
|
+
`CSL::Locale.root` respectively.
|
117
|
+
|
118
|
+
Alternatively, you can `gem install csl-styles` to install all official CSL
|
119
|
+
styles and locales. To make the styles and locales available, simply
|
120
|
+
`require 'csl/styles`.
|
121
|
+
|
122
|
+
Compatibility
|
123
|
+
-------------
|
124
|
+
The cite processor and the CSL API libraries have been developed for MRI,
|
125
|
+
Rubinius, and JRuby. Please note that we try to support only Ruby versions
|
126
|
+
1.9.3 and upwards.
|
22
127
|
|
23
128
|
Credits
|
24
129
|
-------
|
130
|
+
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!
|
25
132
|
|
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/).
|
26
135
|
|
27
136
|
Copyright
|
28
137
|
---------
|
29
|
-
Copyright
|
138
|
+
Copyright 2009-2014 Sylvester Keil. All rights reserved.
|
30
139
|
|
31
|
-
Copyright
|
140
|
+
Copyright 2012 President and Fellows of Harvard College.
|
32
141
|
|
33
142
|
License
|
34
143
|
-------
|
35
|
-
CiteProc is dual licensed under the AGPL and the FreeBSD license.
|
144
|
+
CiteProc is dual licensed under the AGPL and the FreeBSD license.
|
data/Rakefile
CHANGED
@@ -14,14 +14,18 @@ require 'citeproc/version'
|
|
14
14
|
|
15
15
|
|
16
16
|
desc 'Run an IRB session with CiteProc loaded'
|
17
|
-
task :console
|
18
|
-
|
17
|
+
task :console do
|
18
|
+
require 'pry'
|
19
|
+
require 'citeproc'
|
20
|
+
|
21
|
+
Pry.start
|
22
|
+
end
|
19
23
|
|
20
|
-
|
24
|
+
task :check_warnings do
|
25
|
+
$VERBOSE = true
|
21
26
|
require 'citeproc'
|
22
|
-
|
23
|
-
|
24
|
-
IRB.start
|
27
|
+
|
28
|
+
puts CiteProc::VERSION
|
25
29
|
end
|
26
30
|
|
27
31
|
require 'rspec/core'
|
@@ -33,6 +37,10 @@ end
|
|
33
37
|
require 'cucumber/rake/task'
|
34
38
|
Cucumber::Rake::Task.new(:cucumber)
|
35
39
|
|
40
|
+
require 'coveralls/rake/task'
|
41
|
+
Coveralls::RakeTask.new
|
42
|
+
task :test_with_coveralls => [:spec, :cucumber, 'coveralls:push']
|
43
|
+
|
36
44
|
task :release do |t|
|
37
45
|
system "gem build citeproc.gemspec"
|
38
46
|
system "git tag #{CiteProc::VERSION}"
|
@@ -42,5 +50,11 @@ end
|
|
42
50
|
|
43
51
|
task :default => :spec
|
44
52
|
|
45
|
-
|
46
|
-
|
53
|
+
begin
|
54
|
+
require 'yard'
|
55
|
+
YARD::Rake::YardocTask.new
|
56
|
+
rescue LoadError => e
|
57
|
+
# ignore
|
58
|
+
end
|
59
|
+
|
60
|
+
require './tasks/testsuite'
|
data/cucumber.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
default: --format progress --require features --color
|
1
|
+
default: --format progress --require features --color --tags ~@non-standard
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Given(/^the following style:$/) do |string|
|
2
|
+
@style = CSL::Style.parse!(string)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^the following input:$/) do |string|
|
6
|
+
@input = JSON.parse(string)
|
7
|
+
@input.should_not be_nil
|
8
|
+
|
9
|
+
processor.import @input
|
10
|
+
end
|
11
|
+
|
12
|
+
Given(/^the following abbreviations:$/) do |string|
|
13
|
+
processor.abbreviations = JSON.parse(string)
|
14
|
+
processor.abbreviations[:default].should_not be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
When(/^I render the entire bibliography$/) do
|
18
|
+
@bibliography = processor.bibliography
|
19
|
+
@bibliography.errors.should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
When(/^I render the following bibliography selection:$/) do |string|
|
23
|
+
selection = JSON.parse(string)
|
24
|
+
selection.should_not be_nil
|
25
|
+
|
26
|
+
@bibliography = processor.bibliography(selection)
|
27
|
+
@bibliography.errors.should == []
|
28
|
+
end
|
29
|
+
|
30
|
+
Then(/^the bibliography should be:$/) do |string|
|
31
|
+
string.gsub!(/\n\s*/m, '') # strip newlines
|
32
|
+
@bibliography.join.should == string
|
33
|
+
end
|
34
|
+
|
35
|
+
When(/^I cite the following items:$/) do |string|
|
36
|
+
@results = JSON.parse(string).map do |item|
|
37
|
+
processor.process(item)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
When(/^I cite all items$/) do
|
42
|
+
@result = processor.process @input.map { |i| { 'id' => i['id'] } }
|
43
|
+
end
|
44
|
+
|
45
|
+
Then(/^the bibliography's options should match:$/) do |table|
|
46
|
+
headers = table.headers.map(&:to_sym)
|
47
|
+
expected = table.rows[0]
|
48
|
+
|
49
|
+
@bibliography.options.values_at(*headers).should == expected
|
50
|
+
end
|
51
|
+
|
52
|
+
Then(/^the results should be:$/) do |table|
|
53
|
+
@results.should == table.raw.map(&:first)
|
54
|
+
end
|
55
|
+
|
56
|
+
Then(/^the result should be:$/) do |string|
|
57
|
+
@result.should == string
|
58
|
+
end
|
59
|
+
|
data/features/support/env.rb
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
begin
|
2
2
|
require 'simplecov'
|
3
|
-
require 'debugger'
|
4
3
|
rescue LoadError
|
5
4
|
# ignore
|
6
5
|
end
|
7
6
|
|
8
|
-
|
7
|
+
begin
|
8
|
+
case
|
9
|
+
when RUBY_PLATFORM < 'java'
|
10
|
+
require 'debug'
|
11
|
+
Debugger.start
|
12
|
+
when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
13
|
+
require 'rubinius/debugger'
|
14
|
+
else
|
15
|
+
require 'debugger'
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
# ignore
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'nokogiri'
|
22
|
+
require 'citeproc'
|
23
|
+
require 'citeproc/ruby'
|
24
|
+
require 'csl/styles'
|
25
|
+
|
26
|
+
module MimicksCiteProcJS
|
27
|
+
def processor
|
28
|
+
@processor ||= CiteProc::Processor.new :style => @style,
|
29
|
+
:format => default_format, :locale => default_locale_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_format
|
33
|
+
unless @format
|
34
|
+
@format = CiteProc::Ruby::Format.load('citeprocjs')
|
35
|
+
@format.config[:bib_indent] = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
@format
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_locale_path
|
42
|
+
File.expand_path('../../../spec/fixtures/locales/locales-en-US.xml', __FILE__)
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_locale
|
46
|
+
@locale ||= CSL::Locale.load default_locale_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
World(MimicksCiteProcJS)
|
51
|
+
|
data/lib/citeproc.rb
CHANGED
@@ -4,7 +4,7 @@ require 'forwardable'
|
|
4
4
|
require 'observer'
|
5
5
|
require 'open-uri'
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'json'
|
8
8
|
require 'namae'
|
9
9
|
|
10
10
|
require 'citeproc/version'
|
@@ -14,13 +14,13 @@ require 'citeproc/version'
|
|
14
14
|
# defined in CSL (Citation Style Language).
|
15
15
|
#
|
16
16
|
module CiteProc
|
17
|
-
|
17
|
+
|
18
18
|
module Converters
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
module Utilities
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
|
26
26
|
require 'citeproc/compatibility'
|
@@ -62,14 +62,14 @@ CiteProc::Converters.class_eval do
|
|
62
62
|
# Define all converters (all classes have been loaded at this point)
|
63
63
|
CiteProc.constants.each do |name|
|
64
64
|
klass = CiteProc.const_get(name)
|
65
|
-
|
65
|
+
|
66
66
|
if klass.instance_of?(Class) && klass.respond_to?(:create)
|
67
|
-
|
67
|
+
|
68
68
|
define_method(name) do |obj|
|
69
69
|
obj.instance_of?(klass) ? obj : klass.create(obj)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|