citeproc 1.0.0.pre12 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,304 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <locale xmlns="http://purl.org/net/xbiblio/csl" version="1.0" xml:lang="en-US">
3
+ <style-options punctuation-in-quote="true"/>
4
+ <date form="text">
5
+ <date-part name="month" suffix=" "/>
6
+ <date-part name="day" form="numeric-leading-zeros" suffix=", "/>
7
+ <date-part name="year"/>
8
+ </date>
9
+ <date form="numeric">
10
+ <date-part name="month" form="numeric-leading-zeros" suffix="/"/>
11
+ <date-part name="day" form="numeric-leading-zeros" suffix="/"/>
12
+ <date-part name="year"/>
13
+ </date>
14
+ <terms>
15
+ <term name="accessed">accessed</term>
16
+ <term name="and">and</term>
17
+ <term name="and others">and others</term>
18
+ <term name="anonymous">anonymous</term>
19
+ <term name="anonymous" form="short">anon.</term>
20
+ <term name="at">at</term>
21
+ <term name="by">by</term>
22
+ <term name="circa">circa</term>
23
+ <term name="circa" form="short">c.</term>
24
+ <term name="cited">cited</term>
25
+ <term name="edition">
26
+ <single>edition</single>
27
+ <multiple>editions</multiple>
28
+ </term>
29
+ <term name="edition" form="short">ed.</term>
30
+ <term name="et-al">et al.</term>
31
+ <term name="forthcoming">forthcoming</term>
32
+ <term name="from">from</term>
33
+ <term name="ibid">ibid.</term>
34
+ <term name="in">in</term>
35
+ <term name="in press">in press</term>
36
+ <term name="internet">internet</term>
37
+ <term name="interview">interview</term>
38
+ <term name="letter">letter</term>
39
+ <term name="no date">no date</term>
40
+ <term name="no date" form="short">n.d.</term>
41
+ <term name="online">online</term>
42
+ <term name="presented at">presented at the</term>
43
+ <term name="reference">
44
+ <single>reference</single>
45
+ <multiple>references</multiple>
46
+ </term>
47
+ <term name="reference" form="short">
48
+ <single>ref.</single>
49
+ <multiple>refs.</multiple>
50
+ </term>
51
+ <term name="retrieved">retrieved</term>
52
+
53
+ <!-- ANNO DOMINI; BEFORE CHRIST -->
54
+ <term name="ad">AD</term>
55
+ <term name="bc">BC</term>
56
+
57
+ <!-- QUOTES -->
58
+ <term name="open-quote">“</term>
59
+ <term name="close-quote">”</term>
60
+ <term name="open-inner-quote">‘</term>
61
+ <term name="close-inner-quote">’</term>
62
+
63
+ <!-- ORDINALS -->
64
+ <term name="ordinal-01">st</term>
65
+ <term name="ordinal-02">nd</term>
66
+ <term name="ordinal-03">rd</term>
67
+ <term name="ordinal-04">th</term>
68
+
69
+ <!-- LONG ORDINALS -->
70
+ <term name="long-ordinal-01">first</term>
71
+ <term name="long-ordinal-02">second</term>
72
+ <term name="long-ordinal-03">third</term>
73
+ <term name="long-ordinal-04">fourth</term>
74
+ <term name="long-ordinal-05">fifth</term>
75
+ <term name="long-ordinal-06">sixth</term>
76
+ <term name="long-ordinal-07">seventh</term>
77
+ <term name="long-ordinal-08">eighth</term>
78
+ <term name="long-ordinal-09">ninth</term>
79
+ <term name="long-ordinal-10">tenth</term>
80
+
81
+ <!-- CATEGORIES -->
82
+ <term name="anthropology">anthropology</term>
83
+ <term name="astronomy">astronomy</term>
84
+ <term name="biology">biology</term>
85
+ <term name="botany">botany</term>
86
+ <term name="chemistry">chemistry</term>
87
+ <term name="engineering">engineering</term>
88
+ <term name="generic-base">generic base</term>
89
+ <term name="geography">geography</term>
90
+ <term name="geology">geology</term>
91
+ <term name="history">history</term>
92
+ <term name="humanities">humanities</term>
93
+ <term name="linguistics">linguistics</term>
94
+ <term name="literature">literature</term>
95
+ <term name="math">math</term>
96
+ <term name="medicine">medicine</term>
97
+ <term name="philosophy">philosophy</term>
98
+ <term name="physics">physics</term>
99
+ <term name="psychology">psychology</term>
100
+ <term name="sociology">sociology</term>
101
+ <term name="science">science</term>
102
+ <term name="political_science">political science</term>
103
+ <term name="social_science">social science</term>
104
+ <term name="theology">theology</term>
105
+ <term name="zoology">zoology</term>
106
+
107
+ <!-- LONG LOCATOR FORMS -->
108
+ <term name="book">
109
+ <single>book</single>
110
+ <multiple>books</multiple>
111
+ </term>
112
+ <term name="chapter">
113
+ <single>chapter</single>
114
+ <multiple>chapters</multiple>
115
+ </term>
116
+ <term name="column">
117
+ <single>column</single>
118
+ <multiple>columns</multiple>
119
+ </term>
120
+ <term name="figure">
121
+ <single>figure</single>
122
+ <multiple>figures</multiple>
123
+ </term>
124
+ <term name="folio">
125
+ <single>folio</single>
126
+ <multiple>folios</multiple>
127
+ </term>
128
+ <term name="issue">
129
+ <single>number</single>
130
+ <multiple>numbers</multiple>
131
+ </term>
132
+ <term name="line">
133
+ <single>line</single>
134
+ <multiple>lines</multiple>
135
+ </term>
136
+ <term name="note">
137
+ <single>note</single>
138
+ <multiple>notes</multiple>
139
+ </term>
140
+ <term name="opus">
141
+ <single>opus</single>
142
+ <multiple>opera</multiple>
143
+ </term>
144
+ <term name="page">
145
+ <single>page</single>
146
+ <multiple>pages</multiple>
147
+ </term>
148
+ <term name="paragraph">
149
+ <single>paragraph</single>
150
+ <multiple>paragraph</multiple>
151
+ </term>
152
+ <term name="part">
153
+ <single>part</single>
154
+ <multiple>parts</multiple>
155
+ </term>
156
+ <term name="section">
157
+ <single>section</single>
158
+ <multiple>sections</multiple>
159
+ </term>
160
+ <term name="sub verbo">
161
+ <single>sub verbo</single>
162
+ <multiple>sub verbis</multiple>
163
+ </term>
164
+ <term name="verse">
165
+ <single>verse</single>
166
+ <multiple>verses</multiple>
167
+ </term>
168
+ <term name="volume">
169
+ <single>volume</single>
170
+ <multiple>volumes</multiple>
171
+ </term>
172
+
173
+ <!-- SHORT LOCATOR FORMS -->
174
+ <term name="book" form="short">bk.</term>
175
+ <term name="chapter" form="short">chap.</term>
176
+ <term name="column" form="short">col.</term>
177
+ <term name="figure" form="short">fig.</term>
178
+ <term name="folio" form="short">f.</term>
179
+ <term name="issue" form="short">no.</term>
180
+ <term name="opus" form="short">op.</term>
181
+ <term name="page" form="short">
182
+ <single>p.</single>
183
+ <multiple>pp.</multiple>
184
+ </term>
185
+ <term name="paragraph" form="short">para.</term>
186
+ <term name="part" form="short">pt.</term>
187
+ <term name="section" form="short">sec.</term>
188
+ <term name="sub verbo" form="short">
189
+ <single>s.v.</single>
190
+ <multiple>s.vv.</multiple>
191
+ </term>
192
+ <term name="verse" form="short">
193
+ <single>v.</single>
194
+ <multiple>vv.</multiple>
195
+ </term>
196
+ <term name="volume" form="short">
197
+ <single>vol.</single>
198
+ <multiple>vols.</multiple>
199
+ </term>
200
+
201
+ <!-- SYMBOL LOCATOR FORMS -->
202
+ <term name="paragraph" form="symbol">
203
+ <single>¶</single>
204
+ <multiple>¶¶</multiple>
205
+ </term>
206
+ <term name="section" form="symbol">
207
+ <single>§</single>
208
+ <multiple>§§</multiple>
209
+ </term>
210
+
211
+ <!-- LONG ROLE FORMS -->
212
+ <term name="author">
213
+ <single>author</single>
214
+ <multiple>authors</multiple>
215
+ </term>
216
+ <term name="editor">
217
+ <single>editor</single>
218
+ <multiple>editors</multiple>
219
+ </term>
220
+ <term name="editorial-director">
221
+ <single>editor</single>
222
+ <multiple>editors</multiple>
223
+ </term>
224
+ <term name="translator">
225
+ <single>translator</single>
226
+ <multiple>translators</multiple>
227
+ </term>
228
+ <term name="editortranslator">
229
+ <single>editor &amp; translator</single>
230
+ <multiple>editors &amp; translators</multiple>
231
+ </term>
232
+
233
+ <!-- SHORT ROLE FORMS -->
234
+ <term name="author" form="short">
235
+ <single/>
236
+ <multiple/>
237
+ </term>
238
+ <term name="editor" form="short">
239
+ <single>ed.</single>
240
+ <multiple>eds.</multiple>
241
+ </term>
242
+ <term name="editorial-director" form="short">
243
+ <single>ed.</single>
244
+ <multiple>eds.</multiple>
245
+ </term>
246
+ <term name="translator" form="short">
247
+ <single>tran.</single>
248
+ <multiple>trans.</multiple>
249
+ </term>
250
+ <term name="editortranslator" form="short">
251
+ <single>ed. &amp; tran.</single>
252
+ <multiple>eds. &amp; trans.</multiple>
253
+ </term>
254
+
255
+ <!-- VERB ROLE FORMS -->
256
+ <term name="editor" form="verb">edited by</term>
257
+ <term name="editorial-director" form="verb">edited by</term>
258
+ <term name="translator" form="verb">translated by</term>
259
+ <term name="editortranslator" form="verb">edited &amp; translated by</term>
260
+ <term name="recipient" form="verb">to</term>
261
+ <term name="interviewer" form="verb">interview by</term>
262
+
263
+ <!-- SHORT VERB ROLE FORMS -->
264
+ <term name="container-author" form="verb-short">by</term>
265
+ <term name="editor" form="verb-short">ed.</term>
266
+ <term name="editorial-director" form="verb-short">ed.</term>
267
+ <term name="translator" form="verb-short">trans.</term>
268
+ <term name="editortranslator" form="verb-short">ed. &amp; trans. by</term>
269
+
270
+ <!-- LONG MONTH FORMS -->
271
+ <term name="month-01">January</term>
272
+ <term name="month-02">February</term>
273
+ <term name="month-03">March</term>
274
+ <term name="month-04">April</term>
275
+ <term name="month-05">May</term>
276
+ <term name="month-06">June</term>
277
+ <term name="month-07">July</term>
278
+ <term name="month-08">August</term>
279
+ <term name="month-09">September</term>
280
+ <term name="month-10">October</term>
281
+ <term name="month-11">November</term>
282
+ <term name="month-12">December</term>
283
+
284
+ <!-- SHORT MONTH FORMS -->
285
+ <term name="month-01" form="short">Jan.</term>
286
+ <term name="month-02" form="short">Feb.</term>
287
+ <term name="month-03" form="short">Mar.</term>
288
+ <term name="month-04" form="short">Apr.</term>
289
+ <term name="month-05" form="short">May</term>
290
+ <term name="month-06" form="short">Jun.</term>
291
+ <term name="month-07" form="short">Jul.</term>
292
+ <term name="month-08" form="short">Aug.</term>
293
+ <term name="month-09" form="short">Sep.</term>
294
+ <term name="month-10" form="short">Oct.</term>
295
+ <term name="month-11" form="short">Nov.</term>
296
+ <term name="month-12" form="short">Dec.</term>
297
+
298
+ <!-- SEASONS -->
299
+ <term name="season-01">Spring</term>
300
+ <term name="season-02">Summer</term>
301
+ <term name="season-03">Autumn</term>
302
+ <term name="season-04">Winter</term>
303
+ </terms>
304
+ </locale>
@@ -1,10 +1,25 @@
1
1
  begin
2
2
  require 'simplecov'
3
- require 'debugger'
3
+ require 'coveralls' if ENV['CI']
4
4
  rescue LoadError
5
5
  # ignore
6
6
  end
7
7
 
8
+ begin
9
+ case
10
+ when RUBY_PLATFORM < 'java'
11
+ require 'debug'
12
+ Debugger.start
13
+ when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
14
+ require 'rubinius/debugger'
15
+ else
16
+ require 'debugger'
17
+ end
18
+ rescue LoadError
19
+ # ignore
20
+ end
21
+
22
+
8
23
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
24
  $:.unshift(File.dirname(__FILE__))
10
25
 
@@ -12,3 +27,19 @@ require 'tempfile'
12
27
 
13
28
  require 'rspec'
14
29
  require 'citeproc'
30
+ require 'citeproc/ruby'
31
+
32
+ require 'csl'
33
+ require 'csl/styles'
34
+
35
+ module Fixtures
36
+ PATH = File.expand_path('../fixtures', __FILE__)
37
+
38
+ Dir[File.join(PATH, '*.rb')].each do |fixture|
39
+ require fixture
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.include(Fixtures)
45
+ end
@@ -0,0 +1,209 @@
1
+ require 'rake'
2
+ require 'json'
3
+ require 'cucumber'
4
+
5
+ module CSL
6
+ module TestSuite
7
+
8
+ NON_STANDARD = %{
9
+ quotes_PunctuationWithInnerQuote # replaces single quotes and apostrophes
10
+ sort_SubstituteTitle # ---
11
+ substitute_SuppressOrdinaryVariable # citeproc-js bug?
12
+ sort_VariousNameMacros1 # ---
13
+ sort_VariousNameMacros2 # ---
14
+ sort_VariousNameMacros3 # ---
15
+ sort_FamilyOnly # invalid CSL (no layout) / ANZ after Aardvark?
16
+ name_ParticleCaps3 # " in family name
17
+ testers_SecondAutoGeneratedZoteroPluginTest # uses <sc> for small-caps
18
+ name_ParticleCaps2 # capitalizes particle of first name
19
+ parallel_HackedChicago # combines legal cases
20
+ parallel_Bibliography # ---
21
+ magic_SecondFieldAlign #
22
+ magic_CitationLabelInBibliography # Citation labels
23
+ locale_TermInSort # MLZ
24
+ label_EditorTranslator1 # ?
25
+ display_SecondFieldAlignMigratePunctuation # format
26
+ bibsection_Select # categories / collection variable
27
+ flipflop_ItalicsWithOk # HTML in input
28
+ flipflow_ItalicsWithOkAndTextcase # ---
29
+ variables_TitleShortOnShortTitleNoTitle # converts shortTitle to title-short
30
+ textcase_Uppercase # no-case input markup
31
+ textcase_TitleCapitalization # ---
32
+ textcase_SentenceCapitalization # ---
33
+ textcase_Lowercase # ---
34
+ textcase_CapitalizeFirstWithDecor # ---
35
+ textcase_CapitalizeFirst # ---
36
+ textcase_CapitalizeAll # ---
37
+ textcase_SkipNameParticlesInTitleCase #
38
+ }
39
+
40
+ module_function
41
+
42
+ def load(file)
43
+ JSON.parse(File.open(file, 'r:UTF-8').read)
44
+ end
45
+
46
+ def tags_for(json, feature, name)
47
+ tags = []
48
+
49
+ tags << "@#{json['mode']}"
50
+ tags << "@#{feature}"
51
+
52
+ tags << '@bibsection' if json['bibsection']
53
+ tags << '@bibentries' if json['bibentries']
54
+ tags << '@citations' if json['citations']
55
+ tags << '@citation-items' if json['citation_items']
56
+
57
+ if NON_STANDARD.include? "#{feature}_#{name}" || feature == 'display'
58
+ tags << '@non-standard'
59
+ end
60
+
61
+ tags.uniq
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ namespace :test do
68
+
69
+ desc 'Fetch the citeproc-test repository and generate the JSON test files'
70
+ task :init => [:clean] do
71
+ system "hg clone https://bitbucket.org/bdarcus/citeproc-test test"
72
+ system "cd test && python2.7 processor.py --grind"
73
+ end
74
+
75
+ desc 'Remove the citeproc-test repository'
76
+ task :clean do
77
+ system "rm -rf test"
78
+ end
79
+
80
+ desc 'Delete all generated CSL feature tests'
81
+ task :clear do
82
+ Dir['features/**/*'].sort.reverse.each do |path|
83
+ unless path =~ /features\/(support|step_definitions)/
84
+ if File.directory?(path)
85
+ system "rmdir #{path}"
86
+ else
87
+ system "rm #{path}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ desc 'Convert the processor tests to Cucumber features'
94
+ task :convert => [:clear] do
95
+ features = Dir['test/processor-tests/machines/*.json'].group_by { |path|
96
+ File.basename(path).split(/_/, 2)[0]
97
+ }
98
+
99
+ features.each_key do |feature|
100
+ system "mkdir features/#{feature}"
101
+
102
+ features[feature].each do |file|
103
+ json, name = CSL::TestSuite.load(file), File.basename(file, '.json').split(/_/, 2)[-1]
104
+
105
+ tags = CSL::TestSuite.tags_for(json, feature, name)
106
+
107
+ # Apply some filters
108
+ json['result'].gsub!('&#38;', '&amp;')
109
+
110
+ File.open("features/#{feature}/#{name}.feature", 'w:UTF-8') do |out|
111
+ out << "Feature: #{feature}\n"
112
+ out << " As a CSL cite processor hacker\n"
113
+ out << " I want the test #{File.basename(file, '.json')} to pass\n\n"
114
+ out << " " << tags.join(' ') << "\n"
115
+ out << " Scenario: #{name.gsub(/([[:lower:]])([[:upper:]])/, '\1 \2')}\n"
116
+
117
+ out << " Given the following style:\n"
118
+ out << " \"\"\"\n"
119
+
120
+ json['csl'].each_line do |line|
121
+ out << ' ' << line
122
+ end
123
+ out << "\n \"\"\"\n"
124
+
125
+ out << " And the following input:\n"
126
+ out << " \"\"\"\n"
127
+ out << " " << JSON.dump(json['input']) << "\n"
128
+ out << " \"\"\"\n"
129
+
130
+
131
+ if json['abbreviations']
132
+ out << " And the following abbreviations:\n"
133
+ out << " \"\"\"\n"
134
+ out << " " << JSON.dump(json['abbreviations']) << "\n"
135
+ out << " \"\"\"\n"
136
+ end
137
+
138
+ if json['bibentries']
139
+ out << " And the following items have been cited:\n"
140
+ out << " \"\"\"\n"
141
+ out << " " << JSON.dump(json['bibentries'][-1]) << "\n"
142
+ out << " \"\"\"\n"
143
+ end
144
+
145
+ case json['mode']
146
+ when 'citation'
147
+ if json['citations'] # TODO
148
+ out << " And I have a citations input\n"
149
+ end
150
+
151
+ if json['citation_items']
152
+ out << " When I cite the following items:\n"
153
+ out << " \"\"\"\n"
154
+ out << " " << JSON.dump(json['citation_items']) << "\n"
155
+ out << " \"\"\"\n"
156
+ out << " Then the results should be:\n"
157
+
158
+ lines = json['result'].each_line.to_a
159
+ padding = lines.max.length
160
+
161
+ lines.each do |line|
162
+ out << (" | %-#{padding}s |\n" % line.strip)
163
+ end
164
+
165
+ else
166
+ out << " When I cite all items\n"
167
+ out << " Then the result should be:\n"
168
+ out << " \"\"\"\n"
169
+ json['result'].each_line do |line|
170
+ out << " " << line.strip << "\n"
171
+ end
172
+ out << " \"\"\"\n"
173
+ end
174
+
175
+
176
+ when 'bibliography-header'
177
+ out << " When I render the entire bibliography\n"
178
+ out << " Then the bibliography's options should match:\n"
179
+
180
+ headers = Hash[json['result'].each_line.map { |s| s.split(/:\s*/, 2) }]
181
+
182
+ out << " | entry-spacing | line-spacing |\n"
183
+ out << (" | %s | %s |\n" % [headers['entryspacing'].strip, headers['linespacing'].strip])
184
+
185
+ when 'bibliography'
186
+
187
+ if json['bibsection']
188
+ out << " When I render the following bibliography selection:\n"
189
+ out << " \"\"\"\n"
190
+ out << " " << JSON.dump(json['bibsection']) << "\n"
191
+ out << " \"\"\"\n"
192
+ else
193
+ out << " When I render the entire bibliography\n"
194
+ end
195
+
196
+ out << " Then the bibliography should be:\n"
197
+ out << " \"\"\"\n"
198
+ json['result'].each_line do |line|
199
+ out << ' ' << line
200
+ end
201
+ out << "\n \"\"\"\n"
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+
209
+ end