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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.simplecov +4 -0
  3. data/AGPL +1 -1
  4. data/BSDL +2 -2
  5. data/Gemfile +39 -19
  6. data/README.md +123 -14
  7. data/Rakefile +22 -8
  8. data/cucumber.yml +1 -1
  9. data/features/step_definitions/processor.rb +59 -0
  10. data/features/support/env.rb +45 -2
  11. data/lib/citeproc.rb +8 -8
  12. data/lib/citeproc/abbreviate.rb +5 -4
  13. data/lib/citeproc/assets.rb +109 -109
  14. data/lib/citeproc/attributes.rb +11 -11
  15. data/lib/citeproc/bibliography.rb +107 -71
  16. data/lib/citeproc/citation_data.rb +175 -150
  17. data/lib/citeproc/compatibility.rb +5 -108
  18. data/lib/citeproc/date.rb +23 -12
  19. data/lib/citeproc/engine.rb +9 -4
  20. data/lib/citeproc/errors.rb +6 -6
  21. data/lib/citeproc/extensions.rb +66 -66
  22. data/lib/citeproc/item.rb +60 -2
  23. data/lib/citeproc/names.rb +103 -24
  24. data/lib/citeproc/number.rb +27 -8
  25. data/lib/citeproc/processor.rb +31 -41
  26. data/lib/citeproc/selector.rb +132 -126
  27. data/lib/citeproc/utilities.rb +6 -6
  28. data/lib/citeproc/variable.rb +5 -4
  29. data/lib/citeproc/version.rb +1 -1
  30. data/spec/citeproc/assets_spec.rb +17 -15
  31. data/spec/citeproc/bibliography_spec.rb +17 -17
  32. data/spec/citeproc/citation_data_spec.rb +90 -90
  33. data/spec/citeproc/engine_spec.rb +3 -4
  34. data/spec/citeproc/item_spec.rb +76 -68
  35. data/spec/citeproc/names_spec.rb +187 -148
  36. data/spec/citeproc/processor_spec.rb +119 -115
  37. data/spec/citeproc/selector_spec.rb +87 -78
  38. data/spec/citeproc/variable_spec.rb +30 -30
  39. data/spec/fixtures/locales/locales-en-US.xml +304 -0
  40. data/spec/spec_helper.rb +32 -1
  41. data/tasks/testsuite.rb +209 -0
  42. metadata +19 -87
  43. data/.gitignore +0 -6
  44. data/.travis.yml +0 -21
  45. data/citeproc.gemspec +0 -40
@@ -2,122 +2,126 @@ require 'spec_helper'
2
2
 
3
3
  module CiteProc
4
4
  describe Processor do
5
- before { Class.new(Engine) }
6
-
7
- let(:p) { Processor.new }
5
+ let(:p) { Processor.new }
6
+
8
7
  let(:palefire) { Item.new(:id => 'palefire', :type => :book, :title => 'Pale Fire') }
9
8
  let(:despair) { Item.new(:id => 'despair', :type => :book, :title => 'Despair') }
10
-
9
+
11
10
  it { should_not be nil }
12
-
13
- describe '#register' do
14
-
15
- it 'adds the passed-in item to the items hash' do
16
- expect { p.register(palefire) }.to change { p.items.length }.by(1)
17
- end
18
-
19
- it 'register the item with its id' do
20
- expect { p.register(palefire) }.to change { p.has_key?(:palefire) }
21
- end
22
-
23
- end
24
-
25
- describe '#<<' do
26
-
27
- it 'registers the passed in item' do
28
- expect { p << palefire }.to change { p.has_key?(:palefire) }
29
- end
30
-
31
- it 'returns the processor' do
32
- (p << palefire).should be_equal(p)
33
- end
34
-
35
- end
36
-
37
- describe '#[]' do
38
-
39
- describe 'when there is no item with the passed-in id' do
40
- it 'returns nil' do
41
- p[:palefire].should be nil
42
- end
43
- end
44
-
45
- describe 'when there is an item with the passed-in id' do
46
- before(:each) { p.register(palefire) }
47
-
48
- it 'returns the item' do
49
- p[:palefire].should equal(palefire)
50
- end
51
- end
52
- end
53
-
54
- describe '#update' do
55
-
56
- it 'accepts a single item and adds it to the item hash' do
57
- expect { p.update(palefire) }.to change { p.items.length }.by(1)
58
- end
59
-
60
- it 'registers the passed-in item with its id' do
61
- expect { p.update(palefire) }.to change { p[:palefire] }.from(nil).to(palefire)
62
- end
63
-
64
- describe 'when passed a hash' do
65
- it 'registers the value with the key as id' do
66
- p.update(:foo => palefire)[:foo].should equal(palefire)
67
- end
68
-
69
- it 'converts the value to an item' do
70
- p.update(:foo => { :title => 'The Story of Foo' })[:foo].should be_a(Item)
71
- end
72
- end
73
-
74
- it 'adds all items in the array when passed an array' do
75
- expect { p.update([palefire, despair]) }.to change { p.items.length }.by(2)
76
- end
77
-
78
- it 'adds all items in when passed multiple items' do
79
- expect { p.update(palefire, despair) }.to change { p.items.length }.by(2)
80
- end
81
-
82
- end
83
-
84
- describe '#bibliography (generates the bibliography)' do
85
-
86
- describe 'when no items have been processed' do
87
-
88
- it 'returns an empty bibliography'
89
-
90
- # it 'returns a bibliography of all registered items if invoked with :all'
91
-
92
- end
93
-
94
- describe 'when items have been processed' do
95
-
96
- it 'returns a bibliography containing all cited items'
97
-
98
- # it 'returns a bibliography of all registered items if invoked with :all'
99
-
100
- describe 'when invoked with a block as filter' do
101
-
102
- it 'returns an empty bibliography if the block always returns false'
103
-
104
- it 'returns the full bibliography if the block always returns true'
105
-
106
- it 'returns a bibliography with all items for which the block returns true'
107
-
108
- end
109
-
110
- describe 'when passed a hash as argument' do
111
-
112
- it 'fails if the hash is no valid selector'
113
-
114
- it 'creates a selector from the hash and returns a bibliography containing all matching items'
115
-
116
- end
117
-
118
- end
119
-
120
- end
121
-
11
+
12
+ it { p.engine.should_not be nil }
13
+ it { p.engine.name.should == 'citeproc-ruby' }
14
+
15
+ describe '#register' do
16
+
17
+ it 'adds the passed-in item to the items hash' do
18
+ expect { p.register(palefire) }.to change { p.items.length }.by(1)
19
+ end
20
+
21
+ it 'register the item with its id' do
22
+ expect { p.register(palefire) }.to change { p.has_key?('palefire') }
23
+ end
24
+
25
+ end
26
+
27
+ describe '#<<' do
28
+
29
+ it 'registers the passed in item' do
30
+ expect { p << palefire }.to change { p.has_key?('palefire') }
31
+ end
32
+
33
+ it 'returns the processor' do
34
+ (p << palefire).should be_equal(p)
35
+ end
36
+
37
+ end
38
+
39
+ describe '#[]' do
40
+
41
+ describe 'when there is no item with the passed-in id' do
42
+ it 'returns nil' do
43
+ p[:palefire].should be nil
44
+ end
45
+ end
46
+
47
+ describe 'when there is an item with the passed-in id' do
48
+ before(:each) { p.register(palefire) }
49
+
50
+ it 'returns the item' do
51
+ p[:palefire].should equal(palefire)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#update' do
57
+
58
+ it 'accepts a single item and adds it to the item hash' do
59
+ expect { p.update(palefire) }.to change { p.items.length }.by(1)
60
+ end
61
+
62
+ it 'registers the passed-in item with its id' do
63
+ expect { p.update(palefire) }.to change { p[:palefire] }.from(nil).to(palefire)
64
+ end
65
+
66
+ describe 'when passed a hash' do
67
+ it 'registers the value with the key as id' do
68
+ p.update(:foo => palefire)[:foo].should equal(palefire)
69
+ end
70
+
71
+ it 'converts the value to an item' do
72
+ p.update(:foo => { :title => 'The Story of Foo' })[:foo].should be_a(Item)
73
+ end
74
+ end
75
+
76
+ it 'adds all items in the array when passed an array' do
77
+ expect { p.update([palefire, despair]) }.to change { p.items.length }.by(2)
78
+ end
79
+
80
+ it 'adds all items in when passed multiple items' do
81
+ expect { p.update(palefire, despair) }.to change { p.items.length }.by(2)
82
+ end
83
+
84
+ end
85
+
86
+ describe '#bibliography (generates the bibliography)' do
87
+
88
+ describe 'when no items have been processed' do
89
+
90
+ it 'returns an empty bibliography' do
91
+ p.bibliography.should be_empty
92
+ end
93
+
94
+ # it 'returns a bibliography of all registered items if invoked with :all'
95
+
96
+ end
97
+
98
+ describe 'when items have been processed' do
99
+
100
+ it 'returns a bibliography containing all cited items'
101
+
102
+ # it 'returns a bibliography of all registered items if invoked with :all'
103
+
104
+ describe 'when invoked with a block as filter' do
105
+
106
+ it 'returns an empty bibliography if the block always returns false'
107
+
108
+ it 'returns the full bibliography if the block always returns true'
109
+
110
+ it 'returns a bibliography with all items for which the block returns true'
111
+
112
+ end
113
+
114
+ describe 'when passed a hash as argument' do
115
+
116
+ it 'fails if the hash is no valid selector'
117
+
118
+ it 'creates a selector from the hash and returns a bibliography containing all matching items'
119
+
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
122
126
  end
123
- end
127
+ end
@@ -1,81 +1,90 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module CiteProc
4
-
5
- describe Selector do
6
-
7
- let(:select_books) { Selector.new(:all => { :type => :book }) }
8
-
9
- it { should_not be nil }
10
- it { should be_empty }
11
-
12
-
13
- it 'should have no skip_condtions by default' do
14
- Selector.new.skip_conditions.should be_empty
15
- end
16
-
17
- it 'should have no condtions by default' do
18
- Selector.new.conditions.should be_empty
19
- end
20
-
21
- describe 'constructing' do
22
-
23
- %w{ all none any skip }.each do |matcher|
24
- it "accepts the ruby style matcher '#{matcher}'" do
25
- Selector.new(matcher => {}).should_not be nil
26
- end
27
- end
28
-
29
- %w{ include exclude select quash }.each do |matcher|
30
- it "accepts the citeproc-js style matcher '#{matcher}'" do
31
- Selector.new(matcher => {}).should_not be nil
32
- end
33
- end
34
-
35
- # it 'fails if the hash contains more than two elements'
36
- # it 'fails if the hash contains unknown keys'
37
-
38
- it 'accepts a citeproc json style hash'
39
- # it 'accepts a json object (select)' do
40
- # Selector.new(
41
- # "select" => [
42
- # {
43
- # "field" => "type",
44
- # "value" => "book"
45
- # },
46
- # { "field" => "categories",
47
- # "value" => "1990s"
48
- # }
49
- # ]
50
- # ).conditions.should have(2).items
51
- # end
52
-
53
- end
54
-
55
- describe '#to_proc' do
56
- end
57
-
58
- describe '#to_citeproc' do
59
-
60
- it 'returns nil by default' do
61
- Selector.new.to_citeproc.should be nil
62
- end
63
-
64
- it 'converts all matcher to select' do
65
- Selector.new(:all => { :a => 'b' }).to_citeproc.should == { 'select' => [{ 'field' => 'a', 'value' => 'b' }]}
66
- end
67
-
68
- it 'converts any matcher to include' do
69
- Selector.new(:any => { :a => 'b' }).to_citeproc.should == { 'include' => [{ 'field' => 'a', 'value' => 'b' }]}
70
- end
71
-
72
- it 'converts none matcher to exclude' do
73
- Selector.new(:none => { :a => 'b' }).to_citeproc.should == { 'exclude' => [{ 'field' => 'a', 'value' => 'b' }]}
74
- end
75
-
76
-
77
- end
78
-
79
- end
80
-
81
- end
4
+
5
+ describe Selector do
6
+
7
+ let(:select_books) { Selector.new(:all => { :type => :book }) }
8
+
9
+ it { should_not be nil }
10
+ it { should be_empty }
11
+
12
+
13
+ it 'should have no skip_condtions by default' do
14
+ Selector.new.skip_conditions.should be_empty
15
+ end
16
+
17
+ it 'should have no condtions by default' do
18
+ Selector.new.conditions.should be_empty
19
+ end
20
+
21
+ describe 'constructing' do
22
+
23
+ %w{ all none any skip }.each do |matcher|
24
+ it "accepts the ruby style matcher '#{matcher}'" do
25
+ Selector.new(matcher => {}).should_not be nil
26
+ end
27
+ end
28
+
29
+ %w{ include exclude select quash }.each do |matcher|
30
+ it "accepts the citeproc-js style matcher '#{matcher}'" do
31
+ Selector.new(matcher => {}).should_not be nil
32
+ end
33
+ end
34
+
35
+ # it 'fails if the hash contains more than two elements'
36
+ # it 'fails if the hash contains unknown keys'
37
+
38
+ # it 'accepts a citeproc json style hash'
39
+
40
+ it 'accepts a json object (select)' do
41
+ Selector.new(
42
+ "select" => [
43
+ {
44
+ "field" => "type",
45
+ "value" => "book"
46
+ },
47
+ { "field" => "categories",
48
+ "value" => "1990s"
49
+ }
50
+ ]
51
+ ).conditions.should have(2).items
52
+ end
53
+ end
54
+
55
+ describe '#to_proc' do
56
+ end
57
+
58
+ describe '#to_citeproc' do
59
+
60
+ it 'returns nil by default' do
61
+ Selector.new.to_citeproc.should be nil
62
+ end
63
+
64
+ it 'converts all matcher to select' do
65
+ Selector.new(:all => { :a => 'b' }).to_citeproc.should == { 'select' => [{ 'field' => 'a', 'value' => 'b' }]}
66
+ end
67
+
68
+ it 'converts any matcher to include' do
69
+ Selector.new(:any => { :a => 'b' }).to_citeproc.should == { 'include' => [{ 'field' => 'a', 'value' => 'b' }]}
70
+ end
71
+
72
+ it 'converts none matcher to exclude' do
73
+ Selector.new(:none => { :a => 'b' }).to_citeproc.should == { 'exclude' => [{ 'field' => 'a', 'value' => 'b' }]}
74
+ end
75
+ end
76
+
77
+ describe '#matches?' do
78
+ it 'always matches by default' do
79
+ Selector.new.matches?(nil).should be_true
80
+ end
81
+ end
82
+
83
+ describe '#skip?' do
84
+ it 'never skips when by default' do
85
+ Selector.new.skip?(nil).should be_false
86
+ end
87
+ end
88
+ end
89
+
90
+ end
@@ -2,22 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  module CiteProc
4
4
  describe Variable do
5
-
5
+
6
6
  describe '.new' do
7
7
  it { should be_an_instance_of(Variable) }
8
-
8
+
9
9
  it 'is empty by default' do
10
10
  Variable.new.should be_empty
11
11
  end
12
-
12
+
13
13
  it 'equals an empty string (==) by default' do
14
14
  Variable.new.should == ''
15
15
  end
16
-
16
+
17
17
  it 'matches an empty pattern by default' do
18
18
  Variable.new.should =~ /^$/
19
19
  end
20
-
20
+
21
21
  it 'accepts a string value' do
22
22
  Variable.new('test').should == 'test'
23
23
  end
@@ -25,10 +25,10 @@ module CiteProc
25
25
  it 'accepts a numeric value' do
26
26
  Variable.new(23).should == '23'
27
27
  end
28
-
28
+
29
29
  it 'accepts a floating point value' do
30
30
  Variable.new(23.12).should == '23.12'
31
- end
31
+ end
32
32
  end
33
33
 
34
34
  describe '.fields' do
@@ -50,41 +50,41 @@ module CiteProc
50
50
  Variable.fields[:numbers].should_not be_empty
51
51
  Variable.fields[:number].should_not be_empty
52
52
  end
53
-
53
+
54
54
  it 'accepts either string or symbol input' do
55
55
  Variable.fields[:names].should equal Variable.fields['names']
56
- end
56
+ end
57
57
  end
58
-
58
+
59
59
  describe '.types' do
60
60
  it 'given a field name returns the corresponding type' do
61
61
  Variable.types.values_at(:author, :issued, :abstract, :issue).should == [:names, :date, :text, :number]
62
62
  end
63
-
63
+
64
64
  it 'accepts either string or symbol input' do
65
65
  Variable.types.should have_key(:author)
66
66
  Variable.types['author'].should equal Variable.types[:author]
67
67
  end
68
68
  end
69
-
69
+
70
70
  describe '#to_s' do
71
71
  it 'displays the value' do
72
72
  Variable.new('test').to_s.should == 'test'
73
73
  end
74
74
  end
75
-
75
+
76
76
  describe '#to_i' do
77
77
  it 'returns zero by default' do
78
78
  Variable.new.to_i.should == 0
79
79
  end
80
-
80
+
81
81
  context 'when the value is numeric' do
82
82
  %w{ -23 -1 0 1 23 }.each do |value|
83
83
  it "returns the integer value (#{value})" do
84
84
  Variable.new(value).to_i.should equal(value.to_i)
85
85
  end
86
86
  end
87
-
87
+
88
88
  it 'returns only the first numeric value if there are several' do
89
89
  Variable.new('testing 1, 2, 3...').to_i.should == 1
90
90
  end
@@ -95,24 +95,24 @@ module CiteProc
95
95
  it 'returns zero by default' do
96
96
  Variable.new.to_f.should == 0.0
97
97
  end
98
-
98
+
99
99
  context 'when the value is numeric' do
100
100
  %w{ -23.2 -1.45 0.2 1.733 23 }.each do |value|
101
101
  it "returns the integer value (#{value})" do
102
102
  Variable.new(value).to_f.should == value.to_f
103
103
  end
104
104
  end
105
-
105
+
106
106
  it 'returns only the first numeric value if there are several' do
107
107
  Variable.new('testing 1, 2, 3...').to_f.should == 1.0
108
108
  end
109
-
109
+
110
110
  it 'works with dot and comma separators' do
111
111
  Variable.new('1,23').to_f.should == Variable.new('1.23').to_f
112
112
  end
113
113
  end
114
114
  end
115
-
115
+
116
116
  describe '#numeric?' do
117
117
  it 'returns false by default' do
118
118
  Variable.new.should_not be_numeric
@@ -127,28 +127,28 @@ module CiteProc
127
127
  it 'returns true (integer initialized)' do
128
128
  Variable.new(23).should be_numeric
129
129
  end
130
- end
130
+ end
131
131
 
132
132
  context 'variable does not contain a number' do
133
133
  it 'returns false for strings' do
134
134
  Variable.new('test').should_not be_numeric
135
135
  end
136
136
  end
137
-
137
+
138
138
  context 'variable contains numbers but is not numeric' do
139
139
  it 'returns false for strings' do
140
140
  Variable.new('23rd test').should_not be_numeric
141
141
  Variable.new('23rd, 24th & 25th edition').should_not be_numeric
142
142
  end
143
143
  end
144
-
144
+
145
145
  context 'variable contains multiple numbers' do
146
146
  it 'returns true for simple ranges' do
147
147
  Variable.new('23-24').should be_numeric
148
148
  Variable.new('23 - 24').should be_numeric
149
149
  Variable.new('23- 24').should be_numeric
150
150
  end
151
-
151
+
152
152
  it 'returns true for simple lists' do
153
153
  Variable.new('23,24').should be_numeric
154
154
  Variable.new('23 , 24').should be_numeric
@@ -156,14 +156,14 @@ module CiteProc
156
156
  Variable.new('23 ,24').should be_numeric
157
157
  Variable.new('23 ,24,25 , 26, 27').should be_numeric
158
158
  end
159
-
159
+
160
160
  it 'returns true for complex lists' do
161
161
  Variable.new('23rd, 24th & 25th').should be_numeric
162
162
  Variable.new('X23, A2-49th & 25th & A1, B2').should be_numeric
163
163
  end
164
164
  end
165
165
  end
166
-
166
+
167
167
  describe '#strip_markup' do
168
168
  let(:greeting) { '<h1>hello<b> world</b></h1>' }
169
169
  it 'returns a string stripped of html tags' do
@@ -184,13 +184,13 @@ module CiteProc
184
184
  v.should == 'hello world'
185
185
  end
186
186
  end
187
-
188
-
187
+
188
+
189
189
  describe 'sorting' do
190
190
  end
191
-
191
+
192
192
  describe '#to_json' do
193
193
  end
194
-
194
+
195
195
  end
196
- end
196
+ end