csl 1.4.5 → 1.6.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 (55) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +26 -0
  3. data/BSDL +1 -1
  4. data/Gemfile +9 -30
  5. data/README.md +1 -5
  6. data/Rakefile +0 -8
  7. data/csl.gemspec +10 -13
  8. data/cucumber.yml +1 -1
  9. data/lib/csl/locale.rb +4 -4
  10. data/lib/csl/locale/term.rb +1 -1
  11. data/lib/csl/node.rb +2 -2
  12. data/lib/csl/treelike.rb +11 -7
  13. data/lib/csl/version.rb +1 -1
  14. metadata +30 -92
  15. data/.rspec +0 -3
  16. data/.simplecov +0 -4
  17. data/Guardfile +0 -15
  18. data/features/locales/loading.feature +0 -57
  19. data/features/locales/ordinalize.feature +0 -713
  20. data/features/parser/choose.feature +0 -16
  21. data/features/parser/info.feature +0 -27
  22. data/features/parser/localized_dates.feature +0 -35
  23. data/features/parser/terms.feature +0 -28
  24. data/features/step_definitions/locale_steps.rb +0 -36
  25. data/features/step_definitions/parser_steps.rb +0 -40
  26. data/features/step_definitions/style_steps.rb +0 -16
  27. data/features/style/loading.feature +0 -53
  28. data/features/support/env.rb +0 -24
  29. data/spec/csl/info_spec.rb +0 -278
  30. data/spec/csl/locale/date_spec.rb +0 -63
  31. data/spec/csl/locale/style_options_spec.rb +0 -19
  32. data/spec/csl/locale/term_spec.rb +0 -255
  33. data/spec/csl/locale_spec.rb +0 -245
  34. data/spec/csl/node_spec.rb +0 -273
  35. data/spec/csl/parser_spec.rb +0 -112
  36. data/spec/csl/schema_spec.rb +0 -112
  37. data/spec/csl/style/bibliography_spec.rb +0 -7
  38. data/spec/csl/style/choose_spec.rb +0 -66
  39. data/spec/csl/style/citation_spec.rb +0 -7
  40. data/spec/csl/style/date_spec.rb +0 -21
  41. data/spec/csl/style/group_spec.rb +0 -7
  42. data/spec/csl/style/label_spec.rb +0 -44
  43. data/spec/csl/style/layout_spec.rb +0 -7
  44. data/spec/csl/style/macro_spec.rb +0 -7
  45. data/spec/csl/style/names_spec.rb +0 -36
  46. data/spec/csl/style/number_spec.rb +0 -85
  47. data/spec/csl/style/sort_spec.rb +0 -11
  48. data/spec/csl/style/text_spec.rb +0 -7
  49. data/spec/csl/style_spec.rb +0 -137
  50. data/spec/csl/treelike_spec.rb +0 -151
  51. data/spec/fixtures/locales/locales-de-DE.xml +0 -298
  52. data/spec/fixtures/locales/locales-en-GB.xml +0 -304
  53. data/spec/fixtures/locales/locales-en-US.xml +0 -304
  54. data/spec/fixtures/styles/apa.csl +0 -443
  55. data/spec/spec_helper.rb +0 -57
@@ -1,16 +0,0 @@
1
- Feature: Parse CSL choose nodes
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL choose nodes
4
-
5
- Scenario: Single if nodes
6
- When I parse the CSL string
7
- """
8
- <choose>
9
- <if type="bill legal_case legislation" match="none"></if>
10
- </choose>
11
- """
12
- Then the nodename should be "choose"
13
- And the node should have 1 blocks
14
- And the block number 1's nodename should be "if"
15
- And the block number 1's class should be "CSL::Style::Choose::Block"
16
-
@@ -1,27 +0,0 @@
1
- Feature: Parse CSL info elements
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL info strings
4
-
5
- Scenario: A typical style info element
6
- When I parse the CSL string
7
- """
8
- <info>
9
- <title>American Medical Association</title>
10
- <id>http://www.zotero.org/styles/ama</id>
11
- <link href="http://www.zotero.org/styles/ama" rel="self"/>
12
- <author>
13
- <name>Julian Onions</name>
14
- <email>julian.onions@gmail.com</email>
15
- </author>
16
- <category citation-format="numeric"/>
17
- <category field="medicine"/>
18
- <updated/>
19
- <summary>The American Medical Association style as used in JAMA.</summary>
20
- <link href="http://www.samford.edu/schools/pharmacy/dic/amaquickref07.pdf" rel="documentation"/>
21
- <rights>This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
22
- </info>
23
- """
24
- Then the nodename should be "info"
25
- And the title should be "American Medical Association"
26
- And the author name should be "Julian Onions"
27
- And the author email should be "julian.onions@gmail.com"
@@ -1,35 +0,0 @@
1
- Feature: Parse CSL localized date elements
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL localized date strings
4
-
5
- Scenario: A text date
6
- When I parse the CSL string in the Locale scope
7
- """
8
- <date form="text">
9
- <date-part name="month" suffix=" "/>
10
- <date-part name="day" form="numeric-leading-zeros" suffix=", "/>
11
- <date-part name="year"/>
12
- </date>
13
- """
14
- Then the nodename should be "date"
15
- And the attribute "form" should be "text"
16
- And the node should have 3 parts
17
- And text? should be "true"
18
- And the part number 1 should have the attribute "name" set to "month"
19
-
20
- Scenario: A numeric date
21
- When I parse the CSL string in the Locale scope
22
- """
23
- <date form="numeric">
24
- <date-part name="month" form="numeric-leading-zeros" suffix="/"/>
25
- <date-part name="day" form="numeric-leading-zeros" suffix="/"/>
26
- <date-part name="year"/>
27
- </date>
28
- """
29
- Then the nodename should be "date"
30
- And the attribute "form" should be "numeric"
31
- And the node should have 3 parts
32
- And text? should be "false"
33
- And numeric? should be "true"
34
- And the part number 3 should have the attribute "name" set to "year"
35
-
@@ -1,28 +0,0 @@
1
- Feature: Parse CSL localized terms
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL localized terms
4
-
5
- Scenario: A few standard terms
6
- When I parse the CSL string
7
- """
8
- <terms>
9
- <term name="accessed">accessed</term>
10
- <term name="and">and</term>
11
- <term name="and others">and others</term>
12
- <term name="anonymous">anonymous</term>
13
- <term name="anonymous" form="short">anon.</term>
14
- <term name="circa">circa</term>
15
- <term name="circa" form="short">c.</term>
16
- <term name="cited">cited</term>
17
- <term name="edition">
18
- <single>edition</single>
19
- <multiple>editions</multiple>
20
- </term>
21
- </terms>
22
- """
23
- Then the nodename should be "terms"
24
- And the node should have 9 terms
25
- And the term number 1 should have the attribute "name" set to "accessed"
26
- And the term number 2 should be a textnode
27
- And the term number 9 should have the attribute "name" set to "edition"
28
- And the term number 9 should not be a textnode
@@ -1,36 +0,0 @@
1
- Given /^the(?: following)? locale:?$/ do |string|
2
- @csl = CSL::Locale.load(string)
3
- end
4
-
5
- When /^I load the locale from the string$/ do |string|
6
- @csl = CSL::Locale.load(string)
7
- end
8
-
9
- When /^I ordinalize the number (\d+)(?: using the (long) form(?: and (feminine|masculine) gender))?$/ do |num, form, gender|
10
- @ordinal = @locale.ordinalize(num, :form => form, :'gender-form' => gender)
11
- end
12
-
13
- Then /^the ordinal should (?:be|equal) "([^"]*)"$/ do |ord|
14
- expect(@ordinal).to eq(ord)
15
- end
16
-
17
- When /^I ordinalize these numbers:?$/ do |table|
18
- @ordinals = table.rows.map do |row|
19
- num, form, gender, number = *row
20
- @csl.ordinalize(num, :form => form, :'gender-form' => gender, :number => number)
21
- end
22
- end
23
-
24
- Then /^the ordinals should (?:be|equal):?$/ do |table|
25
- expect(@ordinals.join(' ')).to eq(table.rows.flatten.join(' '))
26
- end
27
-
28
- Then /^the locale should should have (\d+) terms$/ do |num|
29
- expect(@csl.terms.length).to eq(num.to_i)
30
- end
31
-
32
- Then /^the (\w+[\?!]?) of the term "([^"]*)" should be "([^"]*)"$/ do |method, name, expected|
33
- expect(
34
- @csl.terms.detect { |t| t.name == name }.send(method)
35
- ).to eq(expected)
36
- end
@@ -1,40 +0,0 @@
1
-
2
- When /^I parse the CSL string(?: in the (\w+) scope)?$/ do |scope, string|
3
- @csl = CSL.parse string, CSL.const_get(scope || 'Node')
4
- end
5
-
6
- Then /^(?:the )?(\w+[\?!]?) should be "([^"]*)"$/ do |name, expected|
7
- actual = @csl.send(name)
8
- actual = !!actual if expected =~ /^true|false$/
9
- expect(actual.to_s).to eq(expected)
10
- end
11
-
12
- Then /^the (\w+) (\w+) should be "([^"]*)"$/ do |outer, inner, expected|
13
- expect(@csl.send(outer).send(inner).to_s).to eq(expected)
14
- end
15
-
16
- Then /^the attribute "([^"]*)" should be "([^"]*)"$/ do |name, expected|
17
- expect(@csl[name.to_sym]).to eq(expected)
18
- end
19
-
20
- Then /^the node should have (\d+) (\w+)$/ do |length, name|
21
- expect(@csl.send(name).length).to eq(length.to_i)
22
- end
23
-
24
- Then /^the (\w+) number (\d+) should have the attribute "([^"]*)" set to "([^"]*)"$/ do |name, offset, attribute, expected|
25
- expect(@csl.send("#{name}s")[offset.to_i - 1][attribute.to_sym]).to eq(expected)
26
- end
27
-
28
- Then /^the (\w+) number (\d+) should( not)? be a (\w+)$/ do |name, offset, negate, predicate|
29
- expect(@csl.send("#{name}s")[offset.to_i - 1].send("#{predicate}?")).to eq(negate.nil?)
30
- end
31
-
32
- Then /^the (\w+) number (\d+)'s (\w+) should( not)? be "([^"]*)"$/ do |name, offset, method, negate, expected|
33
- actual = @csl.send("#{name}s")[offset.to_i - 1].send(method).to_s
34
-
35
- if negate.nil?
36
- expect(actual).to eq(expected)
37
- else
38
- expect(actual).not_to eq(expected)
39
- end
40
- end
@@ -1,16 +0,0 @@
1
-
2
- When /^I load the style from the string$/ do |string|
3
- @csl = CSL::Style.load string
4
- end
5
-
6
- Then /^the locale (\d+) should should have (\d+) terms?$/ do |locale, term|
7
- expect(@csl.locales[locale.to_i - 1].terms.length).to eq(term.to_i)
8
- end
9
-
10
- Then /^the locale (\d+) (\w+\??) should be "([^"]*)"$/ do |locale, method, expected|
11
- expect(@csl.locales[locale.to_i - 1].send(method).to_s).to eq(expected)
12
- end
13
-
14
- Then /^the style should have (\d+) contributors$/ do |num|
15
- expect(@csl.info.contributors.length).to eq(num.to_i)
16
- end
@@ -1,53 +0,0 @@
1
- Feature: Loading CSL Style
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL styles
4
-
5
- Scenario: Loading a style from a string
6
- When I load the style from the string
7
- """
8
- <?xml version="1.0" encoding="utf-8"?>
9
- <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
10
- <info>
11
- <title>American Psychological Association 6th Edition</title>
12
- <id>http://www.zotero.org/styles/apa</id>
13
- <link href="http://www.zotero.org/styles/apa" rel="self"/>
14
- <link href="http://owl.english.purdue.edu/owl/resource/560/01/" rel="documentation"/>
15
- <author>
16
- <name>Simon Kornblith</name>
17
- <email>simon@simonster.com</email>
18
- </author>
19
- <contributor>
20
- <name>Bruce D'Arcus</name>
21
- </contributor>
22
- <contributor>
23
- <name>Curtis M. Humphrey</name>
24
- </contributor>
25
- <contributor>
26
- <name>Richard Karnesky</name>
27
- <email>karnesky+zotero@gmail.com</email>
28
- <uri>http://arc.nucapt.northwestern.edu/Richard_Karnesky</uri>
29
- </contributor>
30
- <contributor>
31
- <name>Sebastian Karcher</name>
32
- </contributor>
33
- <category field="psychology"/>
34
- <category field="generic-base"/>
35
- <category citation-format="author-date"/>
36
- <updated>2010-01-27T20:08:03+00:00</updated>
37
- <rights>This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
38
- </info>
39
- <locale xml:lang="en">
40
- <terms>
41
- <term name="translator" form="short">
42
- <single>trans.</single>
43
- <multiple>trans.</multiple>
44
- </term>
45
- </terms>
46
- </locale>
47
- </style>
48
- """
49
- Then the info title should be "American Psychological Association 6th Edition"
50
- And the locale 1 should should have 1 term
51
- And the locale 1 language should be "en"
52
- And the locale 1 region should be "US"
53
- And the style should have 4 contributors
@@ -1,24 +0,0 @@
1
- begin
2
- require 'simplecov'
3
- require 'coveralls' if ENV['CI']
4
- rescue LoadError
5
- # ignore
6
- end
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
- when defined?(RUBY_VERSION) && RUBY_VERSION < '2.0'
16
- require 'debugger'
17
- else
18
- require 'byebug'
19
- end
20
- rescue LoadError
21
- # ignore
22
- end
23
-
24
- require 'csl'
@@ -1,278 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
-
5
- describe Info do
6
-
7
- it { is_expected.not_to be_nil }
8
- it { is_expected.not_to have_children }
9
-
10
- before { @info = Info.new }
11
-
12
- describe '#nodename' do
13
- it 'returns "info"' do
14
- expect(subject.nodename).to eq('info')
15
- end
16
- end
17
-
18
- describe 'license' do
19
- it { is_expected.not_to have_rights }
20
- it { is_expected.not_to be_default_license }
21
-
22
- it 'has no license by default' do
23
- expect(@info.license).to be_nil
24
- end
25
-
26
- it 'setting a license adds a rights node' do
27
- expect { @info.license = 'cc' }.to change { @info.has_rights? }
28
- end
29
-
30
- it 'setting the default license creates the default rights node' do
31
- @info.default_license!
32
- expect(@info).to have_rights
33
- expect(@info).to be_default_license
34
-
35
- @info.rights.text = 'cc'
36
- expect(@info).not_to be_default_license
37
-
38
- @info.default_license!
39
- expect(@info).to be_default_license
40
- end
41
- end
42
-
43
- describe '#children' do
44
- it 'returns a Info::Children instance' do
45
- expect(@info.children).to be_a(Info::Children)
46
- end
47
-
48
- it 'allows to set the id by array accessor' do
49
- expect { Info.new.children[:id] = 'foo' }.not_to raise_error
50
- end
51
- end
52
-
53
- describe '#category' do
54
- it 'returns an empty list by default' do
55
- expect(@info.category).to be_empty
56
- end
57
- end
58
-
59
- describe 'citation-format' do
60
- it 'has no citation-format by default' do
61
- expect(@info.citation_format).to be_nil
62
- end
63
-
64
- it 'setting a citation-format creates a new category node' do
65
- expect { @info.citation_format = 'foo' }.to change { @info.has_categories? }
66
- end
67
-
68
- it 'setting a citation-format actually sets the citation-format' do
69
- expect { @info.citation_format = 'bar' }.to change { @info.citation_format }.to(:bar)
70
- end
71
-
72
- describe 'given a category node with the citation-attribute set' do
73
- before { @info.add_child Info::Category.new(:'citation-format' => 'author') }
74
-
75
- it 'has a citation format' do
76
- expect(@info.citation_format).to eq(:author)
77
- end
78
-
79
- it 'setting a citation-format does not create a new category node' do
80
- expect { @info.citation_format = 'foo' }.not_to change { @info.categories.length }
81
- end
82
-
83
- it 'setting a citation-format actually sets the citation-format' do
84
- expect { @info.citation_format = 'bar' }.to change { @info.citation_format }.to(:bar)
85
- end
86
- end
87
-
88
- describe 'given a category node without the citation-attribute set' do
89
- before { @info.add_child Info::Category.new(:field => 'literature') }
90
-
91
- it 'has no citation-format by default' do
92
- expect(@info.citation_format).to be_nil
93
- end
94
-
95
- it 'setting a citation-format creates a new category node' do
96
- expect { @info.citation_format = 'foo' }.to change { @info.categories.length }.from(1).to(2)
97
- end
98
-
99
- it 'setting a citation-format actually sets the citation-format' do
100
- expect { @info.citation_format = 'bar' }.to change { @info.citation_format }.to(:bar)
101
- end
102
- end
103
- end
104
-
105
- describe 'link accessors' do
106
- it { is_expected.not_to have_self_link }
107
- it { is_expected.not_to have_documentation_link }
108
- it { is_expected.not_to have_template_link }
109
-
110
- it 'self_link is nil by default' do
111
- expect(@info.self_link).to be_nil
112
- end
113
-
114
- it 'returns nil if no suitable link is set' do
115
- expect(Info.new {|i| i.link = {:href => 'foo', :rel => 'documentation'} }.self_link).to be_nil
116
- end
117
-
118
- it 'returns the href value of the link if it is set' do
119
- expect(Info.new {|i| i.link = {:href => 'foo', :rel => 'self'} }.self_link).to eq('foo')
120
- end
121
-
122
- it 'setter changes the value of existing link' do
123
- info = Info.new {|i| i.link = {:href => 'foo', :rel => 'self'} }
124
- expect { info.self_link = 'bar' }.to change { info.self_link }.from('foo').to('bar')
125
- end
126
-
127
- it 'setter creates new link node if link did not exist' do
128
- expect { @info.self_link = 'bar' }.to change { @info.has_self_link? }
129
- expect(@info.links[0]).to be_a(Info::Link)
130
- end
131
-
132
- end
133
-
134
- describe '#to_xml' do
135
- it 'returns an empty info element by default' do
136
- expect(subject.to_xml).to eq('<info/>')
137
- end
138
-
139
- it 'prints the id if present' do
140
- expect(Info.new { |i| i.set_child_id 'apa' }.to_xml).to eq('<info><id>apa</id></info>')
141
- end
142
-
143
- it 'prints the category if present' do
144
- expect(Info.new { |i| i.category = {:'citation-format' => 'author'} }.to_xml).to eq('<info><category citation-format="author"/></info>')
145
- end
146
- end
147
-
148
- describe '#dup' do
149
- it 'does not copy ancestors' do
150
- apa = Style.load(:apa).info
151
- expect(apa).to be_a(Info)
152
-
153
- expect(apa).not_to be_root
154
- expect(apa.dup).to be_root
155
- end
156
- end
157
-
158
- describe '#deep_copy' do
159
- it 'copies the full sub-tree' do
160
- apa = Style.load(:apa).info
161
- expect(apa).to be_a(Info)
162
-
163
- xml = apa.to_xml
164
-
165
- copy = apa.deep_copy
166
-
167
- expect(apa.to_xml).to eq(xml) # original unchanged!
168
- expect(copy.to_xml).to eq(xml)
169
- end
170
- end
171
-
172
- describe '#pretty_print' do
173
- it 'returns an empty info element by default' do
174
- expect(subject.pretty_print).to eq('<info/>')
175
- end
176
-
177
- it 'prints the id indented if present' do
178
- expect(Info.new { |i| i.set_child_id 'apa' }.pretty_print).to eq("<info>\n <id>apa</id>\n</info>")
179
- end
180
- end
181
-
182
- describe '#tags' do
183
- it 'returns a list with an empty info element by default' do
184
- expect(subject.tags).to eq(['<info/>'])
185
- end
186
-
187
- it 'returns a nested list if id is present' do
188
- expect(Info.new { |i| i.set_child_id 'apa' }.tags).to eq(['<info>', ['<id>apa</id>'], '</info>'])
189
- end
190
-
191
- end
192
- end
193
-
194
- describe Info::Author do
195
- it { is_expected.not_to be_nil }
196
-
197
- let(:poe) {
198
- Info::Author.new { |a|
199
- a.name = 'E. A. Poe'
200
- a.email = 'poe@baltimore.com'
201
- }
202
- }
203
-
204
- describe '#name' do
205
- it 'returns nil by default' do
206
- expect(subject.name).to be nil
207
- end
208
-
209
- it 'returns the name if set' do
210
- expect(poe.name.to_s).to eq('E. A. Poe')
211
- end
212
- end
213
-
214
- describe '#family' do
215
- it "returns the author's family name" do
216
- expect(poe.family).to eq('Poe')
217
- end
218
- end
219
-
220
- describe '#email' do
221
- it 'returns the email' do
222
- expect(poe.email.to_s).to eq('poe@baltimore.com')
223
- end
224
- end
225
-
226
- describe '#to_xml' do
227
- it 'returns an empty author by default' do
228
- expect(subject.to_xml).to eq('<author/>')
229
- end
230
-
231
- it 'prints all children' do
232
- expect(poe.to_xml).to eq('<author><name>E. A. Poe</name><email>poe@baltimore.com</email></author>')
233
- end
234
- end
235
-
236
- end
237
-
238
- describe Info::Contributor do
239
-
240
- it { is_expected.not_to be_nil }
241
-
242
- let(:bruce) { Info::Contributor.new { |c| c.name = "Bruce D'Arcus" } }
243
-
244
- describe '#name' do
245
- it 'returns the name' do
246
- expect(bruce.name.to_s).to eq("Bruce D'Arcus")
247
- end
248
- end
249
-
250
-
251
- describe '#to_xml' do
252
- it 'returns an empty contributor by default' do
253
- expect(subject.to_xml).to eq('<contributor/>')
254
- end
255
-
256
- it 'prints the name tag if present' do
257
- expect(bruce.to_xml).to eq("<contributor><name>Bruce D'Arcus</name></contributor>")
258
- end
259
- end
260
-
261
- end
262
-
263
- describe Info::Rights do
264
- it { is_expected.not_to be_nil }
265
-
266
- describe '#dup' do
267
- it 'copies attributes and text' do
268
- r = Info::Rights.new('foo')
269
- r[:license] = 'bar'
270
-
271
- c = r.dup
272
- expect(c.text).to eq('foo')
273
- expect(c[:license]).to eq('bar')
274
- end
275
- end
276
- end
277
-
278
- end