citeproc-ruby 1.1.8 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +10 -32
  3. data/lib/citeproc/ruby/renderer.rb +2 -1
  4. data/lib/citeproc/ruby/version.rb +1 -1
  5. metadata +14 -84
  6. data/.rspec +0 -3
  7. data/.rubocop.yml +0 -1156
  8. data/.simplecov +0 -4
  9. data/Guardfile +0 -14
  10. data/features/bibliography.feature +0 -25
  11. data/features/locale_overrides.feature +0 -31
  12. data/features/name_options.feature +0 -37
  13. data/features/names.feature +0 -198
  14. data/features/renderer.feature +0 -94
  15. data/features/sort.feature +0 -50
  16. data/features/step_definitions/engine.rb +0 -21
  17. data/features/step_definitions/renderer.rb +0 -85
  18. data/features/style_immanent_locale_terms.feature +0 -30
  19. data/features/support/env.rb +0 -35
  20. data/features/support/hooks.rb +0 -10
  21. data/spec/citeproc/ruby/engine_spec.rb +0 -120
  22. data/spec/citeproc/ruby/formats/default_spec.rb +0 -168
  23. data/spec/citeproc/ruby/formats/html_spec.rb +0 -167
  24. data/spec/citeproc/ruby/renderer/choose_spec.rb +0 -293
  25. data/spec/citeproc/ruby/renderer/date_spec.rb +0 -173
  26. data/spec/citeproc/ruby/renderer/group_spec.rb +0 -114
  27. data/spec/citeproc/ruby/renderer/history_spec.rb +0 -47
  28. data/spec/citeproc/ruby/renderer/label_spec.rb +0 -225
  29. data/spec/citeproc/ruby/renderer/layout_spec.rb +0 -41
  30. data/spec/citeproc/ruby/renderer/macro_spec.rb +0 -31
  31. data/spec/citeproc/ruby/renderer/names_spec.rb +0 -396
  32. data/spec/citeproc/ruby/renderer/number_spec.rb +0 -120
  33. data/spec/citeproc/ruby/renderer/text_spec.rb +0 -125
  34. data/spec/citeproc/ruby/renderer_spec.rb +0 -65
  35. data/spec/fixtures/items.rb +0 -113
  36. data/spec/fixtures/locales/locales-de-DE.xml +0 -298
  37. data/spec/fixtures/locales/locales-en-US.xml +0 -304
  38. data/spec/fixtures/locales/locales-fr-FR.xml +0 -317
  39. data/spec/fixtures/styles/apa-with-different-translations.csl +0 -451
  40. data/spec/fixtures/styles/apa.csl +0 -443
  41. data/spec/fixtures/styles/modern-language-association-8th-edition.csl +0 -293
  42. data/spec/spec_helper.rb +0 -73
@@ -1,21 +0,0 @@
1
- Given(/^the following style:$/) do |string|
2
- @style = CSL::Style.parse!(string)
3
- end
4
-
5
- Given(/^the "(.*?)" style$/) do |style|
6
- @style = CSL::Style.load(style)
7
- end
8
-
9
- When(/^I (cite|reference) the following items as "(.*?)":$/) do |mode, format, items|
10
- processor = CiteProc::Processor.new :style => @style, format: format, locale: @locale
11
- mode = if mode == 'cite' then :citation else :bibliography end
12
-
13
- processor.import items.hashes.map.with_index { |data, idx|
14
- data[:id] = "ID-#{idx}"
15
- data
16
- }
17
-
18
- @results = processor.items.keys.map { |id|
19
- processor.render mode, :id => id
20
- }.flatten
21
- end
@@ -1,85 +0,0 @@
1
-
2
- Given(/^the "(.*?)" style's (bibliography|citation) node$/) do |style, mode|
3
- @node = CSL::Style.load(style).send(mode).layout
4
- end
5
-
6
- Given(/^the following style node:$/) do |string|
7
- @node = CSL.parse!(string, CSL::Style)
8
- end
9
-
10
- Given(/^the following sort keys:$/) do |string|
11
- @sort = CSL.parse!(string, CSL::Style)
12
- end
13
-
14
- Given(/^the following macro:$/) do |string|
15
- @macro = CSL.parse!(string, CSL::Style)
16
- end
17
-
18
- Given(/^the "(.*?)" locale$/) do |locale|
19
- @locale = locale
20
- end
21
-
22
- When(/^I render the following citation items as "(.*?)":$/) do |format, items|
23
- @locale ||= 'en'
24
- r = CiteProc::Ruby::Renderer.new(:format => format, :locale => @locale)
25
-
26
- @results = items.hashes.map.with_index do |data, idx|
27
- i = CiteProc::CitationItem.new(:id => "ID-#{idx}")
28
-
29
- data[:id] = "ID-#{idx}"
30
- i.data = CiteProc::Item.new(data)
31
-
32
- r.render i, @node
33
- end
34
- end
35
-
36
- When(/^I render the following citation item as "(.*?)":$/) do |format, item|
37
- r = CiteProc::Ruby::Renderer.new(:format => format)
38
-
39
- i = CiteProc::CitationItem.new(:id => 'ID-1')
40
- i.data = CiteProc::Item.new(item.rows_hash.merge(:id => 'ID-1'))
41
-
42
- @result = r.render i, @node
43
- end
44
-
45
- When(/^I sort the following items:$/) do |items|
46
- engine = CiteProc::Ruby::Engine.new
47
-
48
- @order = items.hashes.map.with_index do |data, idx|
49
- data[:id] = "ID-#{idx}"
50
- CiteProc::Item.new(data)
51
- end
52
-
53
- unless @macro.nil?
54
- @sort.each_child do |key|
55
- allow(key).to receive(:macro).and_return(@macro)
56
- allow(key).to receive(:macro?).and_return(true)
57
- end
58
- end
59
-
60
- engine.sort! @order, @sort.children
61
- end
62
-
63
- Then(/^the results should be:$/) do |expected|
64
- expected = expected.raw.map(&:first)
65
-
66
- expect(@results.length).to eq(expected.length)
67
-
68
- @results.zip(expected).each do |result, expectation|
69
- expect(result).to eq(expectation)
70
- end
71
- end
72
-
73
- Then(/^the result should be: (.*)$/) do |expected|
74
- expect(@result).to eq(expected)
75
- end
76
-
77
- Then(/^the order should be:$/) do |expected|
78
- expected = expected.raw.map(&:first)
79
-
80
- expect(@order.length).to eq(expected.length)
81
-
82
- @order.zip(expected).each do |order, expectation|
83
- expect(order['id']).to eq(expectation)
84
- end
85
- end
@@ -1,30 +0,0 @@
1
- Feature: Rendering bibliography nodes
2
- As a hacker of cite processors
3
- I want to render citation items
4
- Using bibliography nodes
5
-
6
- Scenario: Rendering APA style bibliographies as text in English
7
- Given the "apa-with-different-translations" style
8
- When I reference the following items as "text":
9
- | type | author | title | issued | translator |
10
- | book | Thomas Pynchon | The crying of lot 49 | July 7, 2006 | Harald Hard |
11
- Then the results should be:
12
- | Pynchon, T. (2006). The crying of lot 49. (H. Hard, Who translated this piece on her/his own). |
13
-
14
- Scenario: Rendering APA style bibliographies as text in French
15
- Given the "apa-with-different-translations" style
16
- Given the "fr" locale
17
- When I reference the following items as "text":
18
- | type | author | title | issued | translator |
19
- | book | Thomas Pynchon | The crying of lot 49 | July 7, 2006 | Harald Hard |
20
- Then the results should be:
21
- | Pynchon, T. (2006). The crying of lot 49. (H. Hard, Le merveilleux traducteur). |
22
-
23
- Scenario: Rendering APA style bibliographies as text in German (a language where the style has no explicit terms for)
24
- Given the "apa-with-different-translations" style
25
- Given the "de" locale
26
- When I reference the following items as "text":
27
- | type | author | title | issued | translator |
28
- | book | Thomas Pynchon | The crying of lot 49 | July 7, 2006 | Harald Hard |
29
- Then the results should be:
30
- | Pynchon, T. (2006). The crying of lot 49. (H. Hard, Übers.). |
@@ -1,35 +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 RUBY_VERSION < '2.0'
16
- require 'debugger'
17
- else
18
- require 'byebug'
19
- end
20
- rescue LoadError
21
- # ignore
22
- end
23
-
24
- require 'rspec/mocks/standalone'
25
- require 'citeproc/ruby'
26
-
27
- module Fixtures
28
- PATH = File.expand_path('../../../spec/fixtures', __FILE__)
29
-
30
- Dir[File.join(PATH, '*.rb')].each do |fixture|
31
- require fixture
32
- end
33
- end
34
-
35
- World(Fixtures)
@@ -1,10 +0,0 @@
1
- Before do
2
- @style_root, @locale_root = CSL::Style.root, CSL::Locale.root
3
-
4
- CSL::Style.root = File.join(Fixtures::PATH, 'styles')
5
- CSL::Locale.root = File.join(Fixtures::PATH, 'locales')
6
- end
7
-
8
- After do
9
- CSL::Style.root, CSL::Locale.root = @style_root, @locale_root
10
- end
@@ -1,120 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'spec_helper'
4
-
5
- module CiteProc
6
- module Ruby
7
-
8
- describe 'The CiteProc-Ruby Engine' do
9
- let(:cp) { CiteProc::Processor.new :style => 'apa', :format => 'text' }
10
- let(:engine) { cp.engine }
11
-
12
- it 'registers itself as "citeproc-ruby"' do
13
- expect(CiteProc::Engine.available).to include('citeproc-ruby')
14
- end
15
-
16
- it 'is the default engine' do
17
- expect(CiteProc::Engine.default).to equal(CiteProc::Ruby::Engine)
18
- expect(engine).to be_a(CiteProc::Ruby::Engine)
19
- end
20
-
21
- describe '#bibliography' do
22
-
23
- describe 'when there are no items in the processor' do
24
- it 'returns an empty bibliography for any selector' do
25
- expect(cp.bibliography()).to be_empty
26
- expect(cp.bibliography(:all => {})).to be_empty
27
- expect(cp.bibliography(:none => {})).to be_empty
28
- end
29
- end
30
- describe 'should order entries correctly' do
31
- describe 'mla 8' do
32
- let(:cp_mla) { CiteProc::Processor.new :style => 'modern-language-association-8th-edition', :format => 'html' }
33
- before(:each) do
34
- cp_mla << items(:aaron2).data
35
- cp_mla << items(:abbott).data
36
- cp_mla << items(:knuth1968).data
37
- end
38
-
39
- it 'should not add quotes around text items when rendering for sorting purposes' do
40
- cp_bib1_hash = cp_mla.bibliography.to_citeproc
41
- bib_entries = cp_bib1_hash[1]
42
- expect(bib_entries[0]).to start_with('Aaron')
43
- # no author specified on Abbott. In MLA8 title is a substitute for name, thus it was being rendered in text
44
- # format to get a sortable value for author. This produced a string starting with a quote character which
45
- # messed up sorting. Have created a special sort format which is overridden to not inject these quotes.
46
- # may be other things that could be prevented here (suffix/prefix) but I haven't run across them yet
47
- expect(bib_entries[1]).to start_with('“Abbott')
48
- expect(bib_entries[2]).to start_with('Knuth')
49
- end
50
- end
51
- end
52
- end
53
-
54
- describe '#render' do
55
-
56
- describe 'when there are no items in the processor' do
57
- end
58
-
59
- describe 'when there are items in the processor' do
60
- before(:each) do
61
- cp << items(:grammatology).data
62
- cp << items(:knuth1968).data
63
- cp << items(:difference).data
64
- cp << items(:literal_date).data
65
- end
66
-
67
- it 'renders the reference for the given id' do
68
- expect(cp.render(:bibliography, :id => 'grammatology')).to eq(['Derrida, J. (1976). Of Grammatology (corrected ed.). Baltimore: Johns Hopkins University Press.'])
69
- expect(cp.render(:citation, :id => 'grammatology', :locator => '3-4')).to eq('(Derrida, 1976, pp. 3-4)')
70
- expect(cp.render(:bibliography, :id => 'knuth1968')).to eq(['Knuth, D. (1968). The art of computer programming (Vol. 1). Boston: Addison-Wesley.'])
71
-
72
- node = cp.engine.style.macros['author']
73
- (node > 'names' > 'name')[:initialize] = 'false'
74
-
75
- cp.engine.format = 'html'
76
- expect(cp.render(:bibliography, :id => 'knuth1968')).to eq(['Knuth, Donald. (1968). <i>The art of computer programming</i> (Vol. 1). Boston: Addison-Wesley.'])
77
-
78
- expect(cp.render(:citation, :id => 'knuth1968', :locator => '23')).to eq('(Knuth, 1968, p. 23)')
79
- end
80
-
81
- it 'overrides locales if the processor option is set' do
82
- expect(cp.render(:bibliography, :id => 'difference')).to eq(['Derrida, J. (1967). L’écriture et la différence (1st ed.). Paris: Éditions du Seuil.'])
83
-
84
- cp.options[:allow_locale_overrides] = true
85
- expect(cp.render(:bibliography, :id => 'difference')).to eq(['Derrida, J. (1967). L’écriture et la différence (1ʳᵉ éd.). Paris: Éditions du Seuil.'])
86
- end
87
-
88
- it 'can handle literal dates' do
89
- expect(cp.render(:bibliography, :id => 'literal_date')).to eq(['Derrida, J. (sometime in 1967). L’écriture et la différence (1st ed.). Paris: Éditions du Seuil.'])
90
- end
91
- end
92
- end
93
-
94
- describe '#process' do
95
- describe 'when there are no items in the processor' do
96
- end
97
-
98
- describe 'when there are items in the processor' do
99
- before(:each) do
100
- cp << items(:grammatology).data
101
- cp << items(:knuth1968).data
102
- end
103
-
104
- it 'renders the citation for the given id' do
105
- expect(cp.process(:id => 'knuth1968', :locator => '23')).to eq('(Knuth, 1968, p. 23)')
106
- end
107
-
108
- it 'combines and sorts multiple cite items' do
109
- expect(cp.process([
110
- {:id => 'knuth1968', :locator => '23'},
111
- {:id => 'grammatology', :locator => '11-14'}
112
- ])).to eq('(Derrida, 1976, pp. 11-14; Knuth, 1968, p. 23)')
113
- end
114
- end
115
- end
116
-
117
- end
118
-
119
- end
120
- end
@@ -1,168 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- module CiteProc
6
- module Ruby
7
-
8
- describe 'Formats::Text#apply' do
9
- let(:format) { Format.load 'text' }
10
- let(:node) { CSL::Style::Text.new }
11
-
12
- it 'returns an empty string if input is nil' do
13
- expect(format.apply(nil, node)).to eq('')
14
- end
15
-
16
- it 'returns the string unchanged if empty' do
17
- input = ''
18
- expect(format.apply(input, node)).to be_equal(input)
19
- expect(input).to eq('')
20
- end
21
-
22
- it 'returns the string unchanged if node is nil' do
23
- input = 'foo'
24
- expect(format.apply(input, nil)).to be_equal(input)
25
- expect(input).to eq('foo')
26
- end
27
-
28
- it 'supports localized quotes' do
29
- locale = double(:locale)
30
- allow(locale).to receive(:punctuation_in_quotes?).and_return(true)
31
- allow(locale).to receive(:quote).and_return('bar')
32
-
33
- node[:quotes] = true
34
-
35
- expect(format.apply('foo', node, locale)).to eq('bar')
36
- end
37
-
38
- it 'disregards localized closing quotes when squeezing affixes' do
39
- locale = double(:locale)
40
- allow(locale).to receive(:punctuation_in_quotes?).and_return(true)
41
- allow(locale).to receive(:quote) { |t| '"' << t << '"' }
42
- allow(locale).to receive(:t) { |t| t == 'close-quote' ? '"' : "'" }
43
-
44
- node[:quotes] = true
45
- node[:suffix] = '.'
46
-
47
- expect(format.apply('foo', node, locale)).to eq('"foo."')
48
- expect(format.apply("'foo'", node, locale)).to eq("\"'foo.'\"")
49
- end
50
-
51
- describe 'text-case formats' do
52
- it 'supports lowercase' do
53
- node[:'text-case'] = 'lowercase'
54
- expect(format.apply('Foo BAR', node)).to eq('foo bar')
55
- end
56
-
57
- it 'supports lowercase for non-ascii letters' do
58
- node[:'text-case'] = 'lowercase'
59
- expect(format.apply('SCHÖN!', node)).to eq('schön!')
60
- end
61
-
62
- it 'supports uppercase' do
63
- node[:'text-case'] = 'uppercase'
64
- expect(format.apply('Foo BAR', node)).to eq('FOO BAR')
65
- end
66
-
67
- it 'supports uppercase for non-ascii letters' do
68
- node[:'text-case'] = 'uppercase'
69
- expect(format.apply('schön!', node)).to eq('SCHÖN!')
70
- end
71
-
72
- it 'does not alter the original string' do
73
- node[:'text-case'] = 'lowercase'
74
- input = 'fooBar'
75
-
76
- expect(format.apply(input, node)).to eq('foobar')
77
- expect(input).to eq('fooBar')
78
- end
79
-
80
- it 'supports capitalize-first' do
81
- node[:'text-case'] = 'capitalize-first'
82
-
83
- expect(format.apply('foo bar', node)).to eq('Foo bar')
84
- expect(format.apply('Foo bar', node)).to eq('Foo bar')
85
- expect(format.apply('!foo bar', node)).to eq('!Foo bar')
86
- expect(format.apply('én foo bar', node)).to eq('Én foo bar')
87
- end
88
-
89
- it 'supports capitalize-all' do
90
- node[:'text-case'] = 'capitalize-all'
91
-
92
- expect(format.apply('foo bar', node)).to eq('Foo Bar')
93
- expect(format.apply('!foo bar', node)).to eq('!Foo Bar')
94
- expect(format.apply('én foo bar', node)).to eq('Én Foo Bar')
95
- end
96
-
97
- it 'supports sentence case' do
98
- node[:'text-case'] = 'sentence'
99
-
100
- expect(format.apply('FOO bar', node)).to eq('Foo bar')
101
- expect(format.apply('foo Bar BAR', node)).to eq('Foo Bar Bar')
102
- expect(format.apply('én Foo bar', node)).to eq('Én Foo bar')
103
- end
104
-
105
- it 'supports title case' do
106
- node[:'text-case'] = 'title'
107
-
108
- expect(format.apply('The adventures of Huckleberry Finn', node)).to eq('The Adventures of Huckleberry Finn')
109
- expect(format.apply('This IS a pen that is a smith pencil', node)).to eq('This IS a Pen That Is a Smith Pencil')
110
- expect(format.apply('of mice and men', node)).to eq('Of Mice and Men')
111
- expect(format.apply('history of the word the', node)).to eq('History of the Word The')
112
- expect(format.apply('faster than the speed of sound', node)).to eq('Faster than the Speed of Sound')
113
- expect(format.apply('on the drug-resistance of enteric bacteria', node)).to eq('On the Drug-Resistance of Enteric Bacteria')
114
- expect(format.apply("The Mote in God's eye", node)).to eq("The Mote in God's Eye")
115
- expect(format.apply("The Mote in God eye", node)).to eq("The Mote in God Eye")
116
- expect(format.apply("Music community mourns death of one of its leaders", node)).to eq("Music Community Mourns Death of One of Its Leaders")
117
- expect(format.apply("Pride and Prejudice", node)).to eq("Pride and Prejudice")
118
- expect(format.apply("Check the page: easybib.com", node)).to eq("Check the Page: Easybib.com")
119
- expect(format.apply("Dogs life.obviously the best guide for pet owners", node)).to eq("Dogs Life.obviously the Best Guide for Pet Owners")
120
- end
121
- end
122
-
123
- describe 'strip-periods' do
124
- before { node[:'strip-periods'] = true }
125
-
126
- it 'strips all periods from the output' do
127
- expect(format.apply('hello there...! how.are.you?', node)).to eq('hello there! howareyou?')
128
- expect(format.apply('foo bar!', node)).to eq('foo bar!')
129
- end
130
-
131
- it 'does not strip periods from affixes' do
132
- node[:prefix] = '...('
133
- node[:suffix] = ').'
134
-
135
- expect(format.apply('foo.bar.', node)).to eq('...(foobar).')
136
- end
137
- end
138
-
139
- describe 'affixes' do
140
- it 'are added after text formats have been applied' do
141
- node[:prefix] = 'foo'
142
- node[:suffix] = 'ooo'
143
- node[:'text-case'] = 'uppercase'
144
-
145
- expect(format.apply('ooo', node)).to eq('fooOOOooo')
146
- end
147
-
148
- it 'drop squeezable characters at start/end' do
149
- node[:suffix] = ' '
150
-
151
- expect(format.apply('foo', node)).to eq('foo ')
152
- expect(format.apply('foo ', node)).to eq('foo ')
153
-
154
- node[:suffix] = '. '
155
- expect(format.apply('foo', node)).to eq('foo. ')
156
- expect(format.apply('foo.', node)).to eq('foo. ')
157
- expect(format.apply('foo?', node)).to eq('foo? ')
158
-
159
- node[:prefix] = '.'
160
- expect(format.apply('foo', node)).to eq('.foo. ')
161
- expect(format.apply('.foo', node)).to eq('.foo. ')
162
- expect(format.apply(',foo', node)).to eq('.,foo. ')
163
- end
164
- end
165
- end
166
-
167
- end
168
- end