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
data/lib/citeproc/utilities.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module CiteProc
|
2
|
-
|
2
|
+
|
3
3
|
module Utilities
|
4
4
|
|
5
5
|
# call-seq:
|
6
6
|
# process(mode = :bibliography, items, options = {})
|
7
7
|
def process(*arguments)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def cite(items, options = {})
|
11
11
|
process(:citation, items, options)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def bibliography(items, options = {})
|
15
15
|
process(:bibliography, items, options)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
|
20
|
+
end
|
data/lib/citeproc/variable.rb
CHANGED
@@ -133,8 +133,9 @@ module CiteProc
|
|
133
133
|
def_delegators :@value, :to_s,
|
134
134
|
*::String.instance_methods(false).select {|m| m.to_s =~ /!$/ }
|
135
135
|
|
136
|
-
def_delegators :to_s, :=~, :===,
|
137
|
-
|
136
|
+
def_delegators :to_s, :=~, :===, *String.instance_methods(false).reject { |m|
|
137
|
+
m.to_s =~ /^[\W_]|[!=_]$|^(to_s|inspect|replace|first|last|dup|clone|to_f|to_i)$/
|
138
|
+
}
|
138
139
|
|
139
140
|
|
140
141
|
# Creates new Variable for the passed-in value
|
@@ -278,7 +279,7 @@ module CiteProc
|
|
278
279
|
|
279
280
|
# @return [String] a JSON string representation of the variable
|
280
281
|
def to_json
|
281
|
-
|
282
|
+
::JSON.dump(to_citeproc)
|
282
283
|
end
|
283
284
|
|
284
285
|
# @return [String] a human-readable representation of the variable
|
@@ -291,4 +292,4 @@ module CiteProc
|
|
291
292
|
# A CiteProc Variable used for string values.
|
292
293
|
class Text < Variable
|
293
294
|
end
|
294
|
-
end
|
295
|
+
end
|
data/lib/citeproc/version.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
module CiteProc
|
2
2
|
|
3
3
|
describe 'Assets' do
|
4
|
-
let(:file) { Tempfile.new('asset') }
|
5
|
-
let(:root) { File.dirname(file.path) }
|
6
|
-
let(:name) { File.basename(file.path) }
|
7
|
-
let(:extension) { File.extname(name) }
|
8
4
|
|
9
5
|
before(:all) do
|
10
|
-
|
11
|
-
file.
|
6
|
+
@file = Tempfile.new('asset')
|
7
|
+
@file.write("asset content\n")
|
8
|
+
@file.close
|
9
|
+
|
10
|
+
@root = File.dirname(@file.path)
|
11
|
+
@name = File.basename(@file.path)
|
12
|
+
|
13
|
+
@extension = File.extname(@name)
|
12
14
|
end
|
13
15
|
|
14
|
-
after(:all) { file.unlink }
|
16
|
+
after(:all) { @file.unlink }
|
15
17
|
|
16
18
|
describe 'Style' do
|
17
19
|
|
18
20
|
before(:all) do
|
19
21
|
@default_root = Style.root
|
20
22
|
@default_extension = Style.extension
|
21
|
-
Style.root = root
|
22
|
-
Style.extension = extension
|
23
|
+
Style.root = @root
|
24
|
+
Style.extension = @extension
|
23
25
|
end
|
24
26
|
|
25
27
|
after(:all) do
|
@@ -34,20 +36,20 @@ module CiteProc
|
|
34
36
|
describe '.open' do
|
35
37
|
|
36
38
|
it 'accepts an absolute file name' do
|
37
|
-
Style.open(file.path).to_s.should == "asset content\n"
|
39
|
+
Style.open(@file.path).to_s.should == "asset content\n"
|
38
40
|
end
|
39
41
|
|
40
42
|
it 'accepts a file name' do
|
41
|
-
Style.open(name).to_s.should == "asset content\n"
|
43
|
+
Style.open(@name).to_s.should == "asset content\n"
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'accepts a file name without extension' do
|
45
|
-
Style.open(name.sub(/#{extension}$/,'')).to_s.should == "asset content\n"
|
47
|
+
Style.open(@name.sub(/#{@extension}$/,'')).to_s.should == "asset content\n"
|
46
48
|
end
|
47
49
|
|
48
50
|
|
49
51
|
it 'accepts an io object' do
|
50
|
-
Style.open(file.open).to_s.should == "asset content\n"
|
52
|
+
Style.open(@file.open).to_s.should == "asset content\n"
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'returns the given string if it looks like XML' do
|
@@ -57,11 +59,11 @@ module CiteProc
|
|
57
59
|
|
58
60
|
describe '.extend_name' do
|
59
61
|
it 'adds the default extension if the file does not already end with it' do
|
60
|
-
Style.extend_name(name.sub(/#{extension}$/,'')).should == name
|
62
|
+
Style.extend_name(@name.sub(/#{@extension}$/,'')).should == @name
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'does not add the default extension if the file already ends with it' do
|
64
|
-
Style.extend_name(name).should == name
|
66
|
+
Style.extend_name(@name).should == @name
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module CiteProc
|
4
|
-
|
4
|
+
|
5
5
|
describe Bibliography do
|
6
|
-
|
6
|
+
|
7
7
|
it { should be_empty }
|
8
8
|
it { should_not have_errors }
|
9
|
-
|
9
|
+
|
10
10
|
describe '#to_citeproc conversion' do
|
11
|
-
|
11
|
+
|
12
12
|
it 'returns an array' do
|
13
13
|
subject.to_citeproc.should be_a(Array)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it 'returns exactly two elements' do
|
17
17
|
subject.to_citeproc.should have(2).elements
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it 'returns formatting options as the first element' do
|
21
21
|
subject.to_citeproc.first.should be_a(Hash)
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'the formatting options' do
|
25
25
|
let(:options) { subject.to_citeproc[0] }
|
26
|
-
|
26
|
+
|
27
27
|
it 'contains a the error list' do
|
28
28
|
options.should have_key('bibliography_errors')
|
29
29
|
options['bibliography_errors'].should be_empty
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it 'returns the list of references as the second element' do
|
35
35
|
subject.to_citeproc.last.should be_a(Array)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
describe '.create (citeproc parser)' do
|
41
41
|
let(:js) { <<-JS_END }
|
42
42
|
[
|
@@ -56,17 +56,17 @@ module CiteProc
|
|
56
56
|
]
|
57
57
|
]
|
58
58
|
JS_END
|
59
|
-
|
59
|
+
|
60
60
|
it 'parses citeproc/json strings' do
|
61
|
-
b = Bibliography.create(js)
|
61
|
+
b = Bibliography.create!(js)
|
62
62
|
b.should be_a(Bibliography)
|
63
63
|
b.should have(2).references
|
64
64
|
b.should_not have_errors
|
65
|
-
b.options[:align].should be true
|
65
|
+
b.options[:'second-field-align'].should be true
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
@@ -2,93 +2,93 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module CiteProc
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
5
|
+
describe 'citation input' do
|
6
|
+
|
7
|
+
let(:hash) {{
|
8
|
+
"citationItems" => [
|
9
|
+
{
|
10
|
+
"id" => "ITEM-1"
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"properties" => {
|
14
|
+
"noteIndex" => 1
|
15
|
+
}
|
16
|
+
}}
|
17
|
+
|
18
|
+
let(:json) { ::JSON.dump(hash) }
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
describe CitationData do
|
23
|
+
|
24
|
+
it { should_not be nil }
|
25
|
+
it { should be_empty }
|
26
|
+
|
27
|
+
it 'has not been processed by default' do
|
28
|
+
CitationData.new.should_not be_processed
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.new' do
|
32
|
+
|
33
|
+
it 'accepts a citeproc hash' do
|
34
|
+
d = CitationData.new(hash)
|
35
|
+
d.should be_footnote
|
36
|
+
d.should_not be_empty
|
37
|
+
d[0].should be_a(CitationItem)
|
38
|
+
d.index.should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'accepts an array of items' do
|
42
|
+
CitationData.new([CitationItem.new(:id => 'id')]).should have(1).items
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'accepts an array of hashes' do
|
46
|
+
CitationData.new([{:id => 'id'}])[0].should be_a(CitationItem)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#to_citeproc' do
|
52
|
+
|
53
|
+
it 'returns empty an empty/default citation data element by default' do
|
54
|
+
CitationData.new.to_citeproc.should == { 'citationItems' => [], 'properties' => { 'noteIndex' => 0}}
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe CitationItem do
|
63
|
+
|
64
|
+
it { should_not be nil }
|
65
|
+
it { should be_empty }
|
66
|
+
|
67
|
+
describe '.new' do
|
68
|
+
|
69
|
+
it 'accepts a hash as input' do
|
70
|
+
CitationItem.new(:label => 'chapter').should have_label
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#to_citeproc' do
|
76
|
+
|
77
|
+
it 'returns empty citation data by default' do
|
78
|
+
CitationItem.new.to_citeproc.should == {}
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns a hash with stringified keys' do
|
82
|
+
CitationItem.new(:type => :article).to_citeproc.should have_key('type')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns a hash with stringified values' do
|
86
|
+
CitationItem.new(:type => :article).to_citeproc.should have_value('article')
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -6,15 +6,14 @@ module CiteProc
|
|
6
6
|
it 'cannot be instantiated' do
|
7
7
|
lambda { Engine.new }.should raise_error(NoMethodError)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
describe 'subclasses' do
|
11
11
|
let(:subject) { Class.new(Engine).new }
|
12
12
|
|
13
13
|
it 'can be instantiated' do
|
14
14
|
subject.should_not be nil
|
15
15
|
end
|
16
|
-
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
end
|
20
|
-
end
|
19
|
+
end
|
data/spec/citeproc/item_spec.rb
CHANGED
@@ -1,71 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module CiteProc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
4
|
+
describe Item do
|
5
|
+
|
6
|
+
|
7
|
+
describe '.new' do
|
8
|
+
it { should_not be nil }
|
9
|
+
|
10
|
+
it 'creates number variables for number fields' do
|
11
|
+
Item.new(:edition => 23).edition.should be_a(Number)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates text variable for text fields' do
|
15
|
+
Item.new(:ISBN => 23).isbn.should be_a(Text)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'creates date variables for date fields' do
|
19
|
+
Item.new(:accessed => Time.now).accessed.should be_a(CiteProc::Date)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'creates names variables for name fields' do
|
23
|
+
Item.new(:editor => { :given => 'Jane' }).editor.should be_a(Names)
|
24
|
+
Item.new(:editor => 'Plato and Socrates').editor.should have(2).names
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'creates text variables for unknown fields' do
|
28
|
+
v = Item.new(:unknown => 42)[:unknown]
|
29
|
+
v.should be_a(Variable)
|
30
|
+
v.should == '42'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#empty' do
|
35
|
+
it { should be_empty }
|
36
|
+
|
37
|
+
it 'returns false when there is at least one variable in the item' do
|
38
|
+
Item.new(:title => 'foo').should_not be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#each' do
|
43
|
+
it 'yields each variable to the given block' do
|
44
|
+
Item.new(:title => 'foo', :edition => 2).each.map {|kv| kv.join('-') }.sort.should == %w{edition-2 title-foo}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#each_value' do
|
49
|
+
it "yields each variable's value to the given block" do
|
50
|
+
Item.new(:title => 'foo', :edition => 2).each_value.map(&:to_s).sort.should == %w{2 foo}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#to_citeproc' do
|
55
|
+
it 'returns an empty hash by default' do
|
56
|
+
Item.new.to_citeproc.should == {}
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns a hash with stringified keys' do
|
60
|
+
Item.new(:issue => 42).to_citeproc.should have_key('issue')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns a hash with stringified values' do
|
64
|
+
Item.new(:issue => 42).to_citeproc.values[0].should == '42'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#dup' do
|
69
|
+
it 'returns a copy' do
|
70
|
+
item = Item.new
|
71
|
+
item.dup.should_not equal(item)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'copies all variables' do
|
75
|
+
Item.new(:issued => 1976).dup[:issued].year.should == 1976
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|