citeproc-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/README.md +78 -0
  2. data/lib/citeproc.rb +100 -0
  3. data/lib/citeproc/bibliography.rb +57 -0
  4. data/lib/citeproc/data.rb +149 -0
  5. data/lib/citeproc/date.rb +133 -0
  6. data/lib/citeproc/formatter.rb +38 -0
  7. data/lib/citeproc/item.rb +53 -0
  8. data/lib/citeproc/name.rb +284 -0
  9. data/lib/citeproc/processor.rb +166 -0
  10. data/lib/citeproc/selector.rb +61 -0
  11. data/lib/citeproc/variable.rb +82 -0
  12. data/lib/citeproc/version.rb +3 -0
  13. data/lib/csl/locale.rb +223 -0
  14. data/lib/csl/node.rb +72 -0
  15. data/lib/csl/nodes.rb +1364 -0
  16. data/lib/csl/renderer.rb +88 -0
  17. data/lib/csl/sort.rb +53 -0
  18. data/lib/csl/style.rb +110 -0
  19. data/lib/csl/term.rb +124 -0
  20. data/lib/extensions/core.rb +43 -0
  21. data/lib/plugins/filters/bibtex.rb +12 -0
  22. data/lib/plugins/formats/default.rb +134 -0
  23. data/lib/plugins/formats/html.rb +67 -0
  24. data/lib/support/attributes.rb +99 -0
  25. data/lib/support/tree.rb +80 -0
  26. data/resource/locale/locales-af-ZA.xml +304 -0
  27. data/resource/locale/locales-ar-AR.xml +304 -0
  28. data/resource/locale/locales-bg-BG.xml +304 -0
  29. data/resource/locale/locales-ca-AD.xml +304 -0
  30. data/resource/locale/locales-cs-CZ.xml +304 -0
  31. data/resource/locale/locales-da-DK.xml +304 -0
  32. data/resource/locale/locales-de-AT.xml +304 -0
  33. data/resource/locale/locales-de-CH.xml +304 -0
  34. data/resource/locale/locales-de-DE.xml +332 -0
  35. data/resource/locale/locales-el-GR.xml +303 -0
  36. data/resource/locale/locales-en-US.xml +313 -0
  37. data/resource/locale/locales-es-ES.xml +304 -0
  38. data/resource/locale/locales-et-EE.xml +304 -0
  39. data/resource/locale/locales-fr-FR.xml +304 -0
  40. data/resource/locale/locales-he-IL.xml +304 -0
  41. data/resource/locale/locales-hu-HU.xml +304 -0
  42. data/resource/locale/locales-is-IS.xml +304 -0
  43. data/resource/locale/locales-it-IT.xml +304 -0
  44. data/resource/locale/locales-ja-JP.xml +304 -0
  45. data/resource/locale/locales-kh-KH.xml +303 -0
  46. data/resource/locale/locales-ko-KR.xml +304 -0
  47. data/resource/locale/locales-mn-MN.xml +304 -0
  48. data/resource/locale/locales-nb-NO.xml +304 -0
  49. data/resource/locale/locales-nl-NL.xml +304 -0
  50. data/resource/locale/locales-nn-NO.xml +304 -0
  51. data/resource/locale/locales-pl-PL.xml +304 -0
  52. data/resource/locale/locales-pt-BR.xml +304 -0
  53. data/resource/locale/locales-pt-PT.xml +304 -0
  54. data/resource/locale/locales-ro-RO.xml +304 -0
  55. data/resource/locale/locales-ru-RU.xml +304 -0
  56. data/resource/locale/locales-sk-SK.xml +304 -0
  57. data/resource/locale/locales-sl-SI.xml +304 -0
  58. data/resource/locale/locales-sr-RS.xml +304 -0
  59. data/resource/locale/locales-sv-SE.xml +304 -0
  60. data/resource/locale/locales-th-TH.xml +304 -0
  61. data/resource/locale/locales-tr-TR.xml +304 -0
  62. data/resource/locale/locales-uk-UA.xml +304 -0
  63. data/resource/locale/locales-vi-VN.xml +304 -0
  64. data/resource/locale/locales-zh-CN.xml +304 -0
  65. data/resource/locale/locales-zh-TW.xml +304 -0
  66. data/resource/schema/csl-categories.rnc +39 -0
  67. data/resource/schema/csl-data.rnc +98 -0
  68. data/resource/schema/csl-terms.rnc +106 -0
  69. data/resource/schema/csl-types.rnc +39 -0
  70. data/resource/schema/csl-variables.rnc +182 -0
  71. data/resource/schema/csl.rnc +941 -0
  72. data/resource/style/acta-materialia-x.csl +128 -0
  73. data/resource/style/advanced-engineering-materials-x.csl +121 -0
  74. data/resource/style/ama.csl +185 -0
  75. data/resource/style/ama2-x.csl +179 -0
  76. data/resource/style/apa-x.csl +324 -0
  77. data/resource/style/apa.csl +254 -0
  78. data/resource/style/apsa-x.csl +163 -0
  79. data/resource/style/apsa.csl +176 -0
  80. data/resource/style/asa-x.csl +203 -0
  81. data/resource/style/asa.csl +216 -0
  82. data/resource/style/asm-journals-x.csl +131 -0
  83. data/resource/style/bibtex-x2.csl +175 -0
  84. data/resource/style/bluebook-demo-x.csl +392 -0
  85. data/resource/style/bluebook-demo.csl +942 -0
  86. data/resource/style/chicago-author-date-listing.csl +434 -0
  87. data/resource/style/chicago-author-date.csl +369 -0
  88. data/resource/style/chicago-fullnote-bibliography-bb.csl +928 -0
  89. data/resource/style/chicago-fullnote-bibliography.csl +695 -0
  90. data/resource/style/chicago-note-bibliography.csl +446 -0
  91. data/resource/style/chicago-note.csl +388 -0
  92. data/resource/style/greek-chicago-x.csl +1182 -0
  93. data/resource/style/harvard1-institution-italic.csl +190 -0
  94. data/resource/style/harvard1.csl +181 -0
  95. data/resource/style/ieee.csl +129 -0
  96. data/resource/style/mhra-x.csl +312 -0
  97. data/resource/style/mhra.csl +390 -0
  98. data/resource/style/mhra_note_without_bibliography-x.csl +330 -0
  99. data/resource/style/mhra_note_without_bibliography.csl +338 -0
  100. data/resource/style/mla-x.csl +178 -0
  101. data/resource/style/mla.csl +189 -0
  102. data/resource/style/nature-x.csl +81 -0
  103. data/resource/style/nature.csl +88 -0
  104. data/resource/style/nlm.csl +117 -0
  105. data/spec/citeproc/bibliography_spec.rb +45 -0
  106. data/spec/citeproc/citeproc_spec.rb +76 -0
  107. data/spec/citeproc/date_spec.rb +85 -0
  108. data/spec/citeproc/formatter_spec.rb +101 -0
  109. data/spec/citeproc/item_spec.rb +71 -0
  110. data/spec/citeproc/name_spec.rb +30 -0
  111. data/spec/citeproc/processor_spec.rb +61 -0
  112. data/spec/citeproc/selector_spec.rb +82 -0
  113. data/spec/citeproc/variable_spec.rb +69 -0
  114. data/spec/csl/locale_spec.rb +208 -0
  115. data/spec/csl/node_spec.rb +25 -0
  116. data/spec/csl/nodes_spec.rb +140 -0
  117. data/spec/csl/style_spec.rb +62 -0
  118. data/spec/csl/term_spec.rb +56 -0
  119. data/spec/fixtures/dates.yaml +80 -0
  120. data/spec/fixtures/names.yaml +115 -0
  121. data/spec/fixtures/nodes.yaml +245 -0
  122. data/spec/spec_helper.rb +18 -0
  123. data/spec/support/attributes_spec.rb +39 -0
  124. data/spec/support/tree_spec.rb +163 -0
  125. metadata +264 -0
@@ -0,0 +1,245 @@
1
+ ---
2
+ - class: CSL::Nodes::Text
3
+ describe:
4
+ processing:
5
+ returns an empty string by default:
6
+ input:
7
+ - <text/>
8
+ expected:
9
+ - ""
10
+ item: {}
11
+ format: default
12
+ handles terms correctly:
13
+ item: {}
14
+ format: default
15
+ input:
16
+ - <text term="editorial-director" plural="false" />
17
+ - <text term="editorial-director" plural="true" />
18
+ - <text term="section" form="symbol" plural="false" />
19
+ - <text term="section" form="symbol" plural="true" />
20
+ expected:
21
+ - editor
22
+ - editors
23
+ - §
24
+ - §§
25
+ - class: CSL::Nodes::Number
26
+ describe:
27
+ processing:
28
+ returns an empty string by default:
29
+ format: default
30
+ input:
31
+ - <number/>
32
+ expected:
33
+ - ""
34
+ item: {}
35
+ supports variables and return numeric value by default:
36
+ format: default
37
+ item:
38
+ edition: '3'
39
+ input:
40
+ - <number variable="edition"/>
41
+ expected:
42
+ - '3'
43
+ supports ordinals and roman numbers:
44
+ format: default
45
+ item:
46
+ issue: '1'
47
+ volume: '2'
48
+ edition: '3'
49
+ number: '23'
50
+ input:
51
+ - <number variable="issue" form="ordinal"/>
52
+ - <number variable="volume" form="ordinal"/>
53
+ - <number variable="edition" form="ordinal"/>
54
+ - <number variable="number" form="ordinal"/>
55
+ - <number variable="issue" form="long-ordinal"/>
56
+ - <number variable="volume" form="long-ordinal"/>
57
+ - <number variable="edition" form="long-ordinal"/>
58
+ - <number variable="issue" form="roman"/>
59
+ - <number variable="volume" form="roman"/>
60
+ - <number variable="edition" form="roman"/>
61
+ - <number variable="number" form="roman"/>
62
+ - <number variable="number" form="roman" text-case="uppercase"/>
63
+ expected:
64
+ - 1st
65
+ - 2nd
66
+ - 3rd
67
+ - 23rd
68
+ - first
69
+ - second
70
+ - third
71
+ - i
72
+ - ii
73
+ - iii
74
+ - xxiii
75
+ - XXIII
76
+ - class: CSL::Nodes::Date
77
+ describe:
78
+ localized processing:
79
+ returns an empty string by default for numeric:
80
+ format: default
81
+ item: {}
82
+ input:
83
+ - <date form="numeric"/>
84
+ expected:
85
+ - ""
86
+ returns an empty string by default for text:
87
+ format: default
88
+ item: {}
89
+ input:
90
+ - <date form="text"/>
91
+ expected:
92
+ - ""
93
+ returns numeric result given date-parts:
94
+ format: default
95
+ item:
96
+ issued:
97
+ date-parts:
98
+ - - 1983
99
+ - 3
100
+ - 12
101
+ input:
102
+ - <date variable="issued" form="numeric"/>
103
+ - <date variable="issued" form="numeric" date-parts="year-month-day"/>
104
+ - <date variable="issued" form="numeric" date-parts="year-month"/>
105
+ - <date variable="issued" form="numeric" date-parts="year"/>
106
+ expected:
107
+ - '03/12/1983'
108
+ - '03/12/1983'
109
+ - '03/1983'
110
+ - '1983'
111
+ returns numeric season correctly:
112
+ format: default
113
+ item:
114
+ issued:
115
+ date-parts:
116
+ - - 1983
117
+ - 3
118
+ - 12
119
+ season: 1
120
+ input:
121
+ - <date variable="issued" form="numeric"/>
122
+ - <date variable="issued" form="numeric" date-parts="year-month-day"/>
123
+ - <date variable="issued" form="numeric" date-parts="year-month"/>
124
+ - <date variable="issued" form="numeric" date-parts="year"/>
125
+ expected:
126
+ - 'Spring/12/1983'
127
+ - 'Spring/12/1983'
128
+ - 'Spring/1983'
129
+ - '1983'
130
+ returns string-numeric season correctly:
131
+ format: default
132
+ item:
133
+ issued:
134
+ date-parts:
135
+ - - 1983
136
+ - 3
137
+ - 12
138
+ season: '2'
139
+ input:
140
+ - <date variable="issued" form="numeric"/>
141
+ - <date variable="issued" form="numeric" date-parts="year-month-day"/>
142
+ - <date variable="issued" form="numeric" date-parts="year-month"/>
143
+ - <date variable="issued" form="numeric" date-parts="year"/>
144
+ expected:
145
+ - 'Summer/12/1983'
146
+ - 'Summer/12/1983'
147
+ - 'Summer/1983'
148
+ - '1983'
149
+ returns literal season correctly:
150
+ format: default
151
+ item:
152
+ issued:
153
+ date-parts:
154
+ - - 1983
155
+ - 3
156
+ - 12
157
+ season: 'THE SEASON'
158
+ input:
159
+ - <date variable="issued" form="numeric"/>
160
+ - <date variable="issued" form="numeric" date-parts="year-month-day"/>
161
+ - <date variable="issued" form="numeric" date-parts="year-month"/>
162
+ - <date variable="issued" form="numeric" date-parts="year"/>
163
+ expected:
164
+ - 'THE SEASON/12/1983'
165
+ - 'THE SEASON/12/1983'
166
+ - 'THE SEASON/1983'
167
+ - '1983'
168
+ returns text result given date-parts:
169
+ format: default
170
+ item:
171
+ issued:
172
+ date-parts:
173
+ - - 1983
174
+ - 3
175
+ - 7
176
+ input:
177
+ - <date variable="issued" form="text"/>
178
+ - <date variable="issued" form="text" date-parts="year-month-day"/>
179
+ - <date variable="issued" form="text" date-parts="year-month"/>
180
+ - <date variable="issued" form="text" date-parts="year"/>
181
+ expected:
182
+ - 'March 07, 1983'
183
+ - 'March 07, 1983'
184
+ - 'March 1983'
185
+ - '1983'
186
+ returns text result given date-parts and overrule:
187
+ format: default
188
+ item:
189
+ issued:
190
+ date-parts:
191
+ - - 1983
192
+ - 3
193
+ - 7
194
+ input:
195
+ - <date variable="issued" form="text"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
196
+ - <date variable="issued" form="text" date-parts="year-month-day"><date-part name="month" form="verb-short"/><date-part name="day" form="numeric"/></date>
197
+ - <date variable="issued" form="text" date-parts="year-month"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
198
+ - <date variable="issued" form="text" date-parts="year"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
199
+ expected:
200
+ - 'Mar. 7, 1983'
201
+ - 'March 7, 1983'
202
+ - 'Mar. 1983'
203
+ - '1983'
204
+ returns text result given date-parts and overrule in HTML:
205
+ format: html
206
+ item:
207
+ issued:
208
+ date-parts:
209
+ - - 1983
210
+ - 3
211
+ - 7
212
+ input:
213
+ - <date variable="issued" form="text"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
214
+ - <date variable="issued" form="text" date-parts="year-month-day"><date-part name="month" form="verb-short" text-case="uppercase"/><date-part name="day" form="numeric"/></date>
215
+ expected:
216
+ - 'Mar. 7, 1983'
217
+ - '<span style="text-transform: uppercase">March </span>7, 1983'
218
+ non-localized processing:
219
+ returns an empty string by default:
220
+ format: default
221
+ item: {}
222
+ input:
223
+ - <date/>
224
+ expected:
225
+ - ""
226
+ returns result given date-parts:
227
+ format: default
228
+ item:
229
+ issued:
230
+ date-parts:
231
+ - - 1983
232
+ - 3
233
+ - 12
234
+ input:
235
+ - <date variable="issued"/>
236
+ - <date variable="issued"><date-part name="year" form="long" suffix="-"/><date-part name="month" form="numeric" suffix="-"/><date-part name="day" form="numeric"/></date>
237
+ - <date variable="issued"><date-part name="year" form="long" suffix="-"/><date-part name="month" form="numeric-leading-zeros" suffix=""/></date>
238
+ - <date variable="issued"><date-part name="year"/><date>
239
+ - <date variable="issued"><date-part name="year" form="short" suffix=" "/><date-part name="month" form="long" suffix=" "/><date-part name="day" form="ordinal"/></date>
240
+ expected:
241
+ - ''
242
+ - '1983-3-12'
243
+ - '1983-03'
244
+ - '1983'
245
+ - '83 March 12th'
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'citeproc'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ RSpec.configuration do |c|
7
+ end
8
+
9
+ module CiteProc
10
+ module Test
11
+ module Fixtures
12
+ Names = YAML.load(File.read(File.expand_path("../fixtures/names.yaml", __FILE__)))
13
+ Dates = YAML.load(File.read(File.expand_path("../fixtures/dates.yaml", __FILE__)))
14
+ Nodes = YAML.load(File.read(File.expand_path("../fixtures/nodes.yaml", __FILE__)))
15
+ Processor = Hash[Dir.glob(File.expand_path("../../resource/test/processor/*.json", __FILE__)).map { |file| [file, JSON.parse(File.read(file))] }]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Support::Attributes do
4
+
5
+ before(:each) { Object.instance_eval { include Support::Attributes } }
6
+
7
+ let(:instance) { o = Object.new }
8
+ let(:other) { o = Object.new; o['foo'] = 'bar'; o }
9
+
10
+ it { should_not be_nil }
11
+ it { should be_empty }
12
+
13
+ describe '#attributes' do
14
+
15
+ # before(:all) { class Object; attr_fields :value, %w[ is-numeric punctuation-mode ]; end }
16
+
17
+ it 'generates setters for attr_field values' do
18
+ pending
19
+ # lambda { Object.new.is_numeric }.should_not raise_error
20
+ end
21
+
22
+ it 'generates no other setters' do
23
+ lambda { Object.new.some_other_value }.should raise_error
24
+ end
25
+ end
26
+
27
+ describe '#merge' do
28
+
29
+ it 'merges non-existent values from other object' do
30
+ Object.new.merge(other)['foo'].should == 'bar'
31
+ end
32
+
33
+ # it 'does not overwrite existing values when merging other object' do
34
+ # instance.merge(other)['foo'].should == 'bar'
35
+ # end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+
3
+ describe Support::Tree do
4
+
5
+ before(:each) { Object.instance_eval { include Support::Tree } }
6
+
7
+ let(:node) { Object.new }
8
+
9
+ describe '#children' do
10
+ context 'when it has no children' do
11
+ it 'returns an empty list' do
12
+ node.children.should be_empty
13
+ end
14
+ end
15
+
16
+ context 'when it has children' do
17
+ before(:each) { node.add_children([Object.new, Object.new, Object.new]) }
18
+
19
+ it 'returns a list of all children' do
20
+ node.children.should have(3).items
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#name' do
26
+ it 'returns the class name in attribute form by default' do
27
+ node.name.should == 'object'
28
+ end
29
+ end
30
+
31
+ describe '#add_children' do
32
+ it 'adds a single node to the children array' do
33
+ node.add_children(Object.new).children.should have(1).item
34
+ end
35
+
36
+ it 'adds a list of nodes to the children array' do
37
+ node.add_children(Object.new, Object.new).children.should have(2).item
38
+ end
39
+
40
+ it 'adds an array of nodes to the children array' do
41
+ node.add_children([Object.new, Object.new]).children.should have(2).item
42
+ end
43
+
44
+ it 'sets self as parent of the added nodes' do
45
+ node.add_children([Object.new, Object.new]).children.map(&:parent).uniq.should == [node]
46
+ end
47
+
48
+ it 'does not alter the state if no argument given' do
49
+ node.add_children().children.should be_empty
50
+ end
51
+
52
+ it 'does not alter the state if nil argument given' do
53
+ node.add_children(nil).children.should be_empty
54
+ end
55
+
56
+ it 'does not alter the state if nil arguments given' do
57
+ node.add_children(nil, nil).children.should be_empty
58
+ end
59
+
60
+ it 'does not alter the state if empty list argument given' do
61
+ node.add_children([]).children.should be_empty
62
+ end
63
+
64
+ it 'does not alter the state if nil list argument given' do
65
+ node.add_children([nil, nil]).children.should be_empty
66
+ end
67
+
68
+ end
69
+
70
+ describe '#ancestors' do
71
+ context 'when it has no ancestors' do
72
+ it 'returns and empty list' do
73
+ node.ancestors.should be_empty
74
+ end
75
+ end
76
+
77
+ context 'when it has ancestors' do
78
+
79
+ let(:node1) { node.add_children(Object.new).children[0] }
80
+ let(:node2) { node1.add_children(Object.new).children[0] }
81
+ let(:node3) { node2.add_children(Object.new).children[0] }
82
+
83
+ it 'returns a list containing the ancestors (depth 0)' do
84
+ node.ancestors.should be_empty
85
+ end
86
+
87
+ it 'returns a list containing the ancestors (depth 1)' do
88
+ node1.ancestors.should == [node]
89
+ end
90
+
91
+ it 'returns a list containing the ancestors (depth 2)' do
92
+ node2.ancestors.should == [node1, node]
93
+ end
94
+
95
+ it 'returns a list containing the ancestors (depth 3)' do
96
+ node3.ancestors.should == [node2, node1, node]
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+ describe '#root' do
103
+ context 'when it has no ancestors' do
104
+ it 'returns itself' do
105
+ node.root.should == node
106
+ node.should be_root
107
+ end
108
+ end
109
+
110
+ context 'when it has ancestors' do
111
+
112
+ let(:node1) { node.add_children(Object.new).children[0] }
113
+ let(:node2) { node1.add_children(Object.new).children[0] }
114
+ let(:node3) { node2.add_children(Object.new).children[0] }
115
+
116
+ it 'returns the root node (depth 0)' do
117
+ node.root.should == node
118
+ node.should be_root
119
+ node.depth.should == 0
120
+ end
121
+
122
+ it 'returns the root node (depth 1)' do
123
+ node1.root.should == node
124
+ node1.should_not be_root
125
+ node1.depth.should == 1
126
+ end
127
+
128
+ it 'returns the root node (depth 2)' do
129
+ node2.root.should == node
130
+ node2.should_not be_root
131
+ node2.depth.should == 2
132
+ end
133
+
134
+ it 'returns the root node (depth 3)' do
135
+ node3.root.should == node
136
+ node3.should_not be_root
137
+ node3.depth.should == 3
138
+ end
139
+ end
140
+ end
141
+
142
+ describe 'named child accessors' do
143
+
144
+ before(:all) { Object.instance_eval { attr_children :object } }
145
+
146
+ context 'when it has no children' do
147
+ it 'returns an empty list by default' do
148
+ Object.new.object.should be_empty
149
+ end
150
+ end
151
+
152
+ context 'when it has children' do
153
+ it 'returns a list of a single child with the matching name' do
154
+ Object.new.add_children(Object.new).object.should have(1).item
155
+ end
156
+
157
+ it 'returns a list of all children with the matching name' do
158
+ Object.new.add_children(Object.new, Object.new).object.should have(2).items
159
+ end
160
+ end
161
+ end
162
+
163
+ end