citeproc-ruby 0.0.6 → 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 (186) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.document +4 -0
  4. data/.gitignore +10 -0
  5. data/.rspec +3 -0
  6. data/.simplecov +4 -0
  7. data/.travis.yml +17 -0
  8. data/.yardopts +2 -0
  9. data/AGPL +662 -0
  10. data/BSDL +29 -0
  11. data/Gemfile +42 -0
  12. data/Guardfile +14 -0
  13. data/README.md +32 -76
  14. data/Rakefile +60 -0
  15. data/citeproc-ruby.gemspec +46 -0
  16. data/cucumber.yml +1 -0
  17. data/features/bibliography.feature +25 -0
  18. data/features/name_options.feature +37 -0
  19. data/features/names.feature +192 -0
  20. data/features/renderer.feature +74 -0
  21. data/features/sort.feature +50 -0
  22. data/features/step_definitions/renderer.rb +80 -0
  23. data/features/support/env.rb +33 -0
  24. data/features/support/hooks.rb +10 -0
  25. data/lib/citeproc/ruby.rb +32 -0
  26. data/lib/citeproc/ruby/engine.rb +122 -0
  27. data/lib/citeproc/ruby/format.rb +303 -0
  28. data/lib/citeproc/ruby/formats/default.rb +25 -0
  29. data/lib/citeproc/ruby/formats/html.rb +221 -0
  30. data/lib/citeproc/ruby/renderer.rb +140 -0
  31. data/lib/citeproc/ruby/renderer/choose.rb +106 -0
  32. data/lib/citeproc/ruby/renderer/date.rb +90 -0
  33. data/lib/citeproc/ruby/renderer/format.rb +129 -0
  34. data/lib/citeproc/ruby/renderer/group.rb +34 -0
  35. data/lib/citeproc/ruby/renderer/history.rb +40 -0
  36. data/lib/citeproc/ruby/renderer/label.rb +66 -0
  37. data/lib/citeproc/ruby/renderer/layout.rb +20 -0
  38. data/lib/citeproc/ruby/renderer/locale.rb +26 -0
  39. data/lib/citeproc/ruby/renderer/macro.rb +20 -0
  40. data/lib/citeproc/ruby/renderer/names.rb +401 -0
  41. data/lib/citeproc/ruby/renderer/number.rb +41 -0
  42. data/lib/citeproc/ruby/renderer/observer.rb +44 -0
  43. data/lib/citeproc/ruby/renderer/state.rb +96 -0
  44. data/lib/citeproc/ruby/renderer/text.rb +62 -0
  45. data/lib/citeproc/ruby/sort.rb +82 -0
  46. data/lib/citeproc/ruby/version.rb +5 -0
  47. data/spec/citeproc/ruby/engine_spec.rb +94 -0
  48. data/spec/citeproc/ruby/formats/default_spec.rb +159 -0
  49. data/spec/citeproc/ruby/formats/html_spec.rb +162 -0
  50. data/spec/citeproc/ruby/renderer/choose_spec.rb +293 -0
  51. data/spec/citeproc/ruby/renderer/date_spec.rb +173 -0
  52. data/spec/citeproc/ruby/renderer/group_spec.rb +88 -0
  53. data/spec/citeproc/ruby/renderer/history_spec.rb +38 -0
  54. data/spec/citeproc/ruby/renderer/label_spec.rb +225 -0
  55. data/spec/citeproc/ruby/renderer/layout_spec.rb +41 -0
  56. data/spec/citeproc/ruby/renderer/macro_spec.rb +31 -0
  57. data/spec/citeproc/ruby/renderer/names_spec.rb +396 -0
  58. data/spec/citeproc/ruby/renderer/number_spec.rb +120 -0
  59. data/spec/citeproc/ruby/renderer/text_spec.rb +120 -0
  60. data/spec/citeproc/ruby/renderer_spec.rb +65 -0
  61. data/spec/fixtures/items.rb +80 -0
  62. data/{resource/locale → spec/fixtures/locales}/locales-en-US.xml +2 -11
  63. data/{resource/locale → spec/fixtures/locales}/locales-fr-FR.xml +77 -66
  64. data/{resource/style → spec/fixtures/styles}/apa.csl +5 -5
  65. data/spec/spec_helper.rb +67 -14
  66. metadata +121 -211
  67. data/lib/citeproc.rb +0 -100
  68. data/lib/citeproc/bibliography.rb +0 -57
  69. data/lib/citeproc/data.rb +0 -149
  70. data/lib/citeproc/date.rb +0 -133
  71. data/lib/citeproc/formatter.rb +0 -38
  72. data/lib/citeproc/item.rb +0 -53
  73. data/lib/citeproc/name.rb +0 -284
  74. data/lib/citeproc/processor.rb +0 -166
  75. data/lib/citeproc/selector.rb +0 -61
  76. data/lib/citeproc/variable.rb +0 -82
  77. data/lib/citeproc/version.rb +0 -3
  78. data/lib/csl/locale.rb +0 -223
  79. data/lib/csl/node.rb +0 -72
  80. data/lib/csl/nodes.rb +0 -1418
  81. data/lib/csl/renderer.rb +0 -88
  82. data/lib/csl/sort.rb +0 -61
  83. data/lib/csl/style.rb +0 -110
  84. data/lib/csl/term.rb +0 -124
  85. data/lib/extensions/core.rb +0 -43
  86. data/lib/plugins/filters/bibtex.rb +0 -12
  87. data/lib/plugins/formats/default.rb +0 -134
  88. data/lib/plugins/formats/html.rb +0 -67
  89. data/lib/support/attributes.rb +0 -99
  90. data/lib/support/compatibility.rb +0 -83
  91. data/lib/support/tree.rb +0 -80
  92. data/resource/locale/locales-af-ZA.xml +0 -305
  93. data/resource/locale/locales-ar-AR.xml +0 -306
  94. data/resource/locale/locales-bg-BG.xml +0 -305
  95. data/resource/locale/locales-ca-AD.xml +0 -305
  96. data/resource/locale/locales-cs-CZ.xml +0 -305
  97. data/resource/locale/locales-da-DK.xml +0 -305
  98. data/resource/locale/locales-de-AT.xml +0 -304
  99. data/resource/locale/locales-de-CH.xml +0 -304
  100. data/resource/locale/locales-de-DE.xml +0 -332
  101. data/resource/locale/locales-el-GR.xml +0 -305
  102. data/resource/locale/locales-en-GB.xml +0 -304
  103. data/resource/locale/locales-es-ES.xml +0 -305
  104. data/resource/locale/locales-et-EE.xml +0 -304
  105. data/resource/locale/locales-eu.xml +0 -305
  106. data/resource/locale/locales-fa-IR.xml +0 -304
  107. data/resource/locale/locales-fi-FI.xml +0 -304
  108. data/resource/locale/locales-fr-CA.xml +0 -306
  109. data/resource/locale/locales-he-IL.xml +0 -304
  110. data/resource/locale/locales-hu-HU.xml +0 -305
  111. data/resource/locale/locales-is-IS.xml +0 -304
  112. data/resource/locale/locales-it-IT.xml +0 -305
  113. data/resource/locale/locales-ja-JP.xml +0 -305
  114. data/resource/locale/locales-kh-KH.xml +0 -303
  115. data/resource/locale/locales-km-KH.xml +0 -304
  116. data/resource/locale/locales-ko-KR.xml +0 -305
  117. data/resource/locale/locales-mn-MN.xml +0 -306
  118. data/resource/locale/locales-nb-NO.xml +0 -304
  119. data/resource/locale/locales-nl-NL.xml +0 -304
  120. data/resource/locale/locales-nn-NO.xml +0 -304
  121. data/resource/locale/locales-pl-PL.xml +0 -305
  122. data/resource/locale/locales-pt-BR.xml +0 -304
  123. data/resource/locale/locales-pt-PT.xml +0 -305
  124. data/resource/locale/locales-ro-RO.xml +0 -305
  125. data/resource/locale/locales-ru-RU.xml +0 -306
  126. data/resource/locale/locales-sk-SK.xml +0 -304
  127. data/resource/locale/locales-sl-SI.xml +0 -305
  128. data/resource/locale/locales-sr-RS.xml +0 -305
  129. data/resource/locale/locales-sv-SE.xml +0 -305
  130. data/resource/locale/locales-th-TH.xml +0 -304
  131. data/resource/locale/locales-tr-TR.xml +0 -305
  132. data/resource/locale/locales-uk-UA.xml +0 -306
  133. data/resource/locale/locales-vi-VN.xml +0 -305
  134. data/resource/locale/locales-zh-CN.xml +0 -304
  135. data/resource/locale/locales-zh-TW.xml +0 -305
  136. data/resource/schema/csl-categories.rnc +0 -39
  137. data/resource/schema/csl-data.rnc +0 -98
  138. data/resource/schema/csl-terms.rnc +0 -106
  139. data/resource/schema/csl-types.rnc +0 -39
  140. data/resource/schema/csl-variables.rnc +0 -182
  141. data/resource/schema/csl.rnc +0 -941
  142. data/resource/style/bibtex.csl +0 -177
  143. data/resource/style/chicago-annotated-bibliography.csl +0 -513
  144. data/resource/style/chicago-author-date-basque.csl +0 -707
  145. data/resource/style/chicago-author-date-de.csl +0 -394
  146. data/resource/style/chicago-author-date-listing.csl +0 -434
  147. data/resource/style/chicago-author-date.csl +0 -425
  148. data/resource/style/chicago-dated-note-biblio-no-ibid.csl +0 -472
  149. data/resource/style/chicago-fullnote-bibliography-bb.csl +0 -928
  150. data/resource/style/chicago-fullnote-bibliography-delimiter-fixes.csl +0 -972
  151. data/resource/style/chicago-fullnote-bibliography-no-ibid-delimiter-fixes.csl +0 -963
  152. data/resource/style/chicago-fullnote-bibliography-no-ibid.csl +0 -785
  153. data/resource/style/chicago-fullnote-bibliography.csl +0 -803
  154. data/resource/style/chicago-library-list.csl +0 -511
  155. data/resource/style/chicago-note-biblio-no-ibid.csl +0 -514
  156. data/resource/style/chicago-note-bibliography.csl +0 -530
  157. data/resource/style/chicago-note.csl +0 -388
  158. data/resource/style/chicago-quick-copy.csl +0 -685
  159. data/resource/style/ieee.csl +0 -299
  160. data/resource/style/mla-notes.csl +0 -796
  161. data/resource/style/mla-underline.csl +0 -175
  162. data/resource/style/mla-url.csl +0 -214
  163. data/resource/style/mla.csl +0 -394
  164. data/resource/style/vancouver-brackets.csl +0 -256
  165. data/resource/style/vancouver-superscript-bracket-only-year.csl +0 -165
  166. data/resource/style/vancouver-superscript.csl +0 -256
  167. data/resource/style/vancouver.csl +0 -256
  168. data/spec/citeproc/bibliography_spec.rb +0 -45
  169. data/spec/citeproc/citeproc_spec.rb +0 -80
  170. data/spec/citeproc/date_spec.rb +0 -89
  171. data/spec/citeproc/formatter_spec.rb +0 -101
  172. data/spec/citeproc/item_spec.rb +0 -71
  173. data/spec/citeproc/name_spec.rb +0 -30
  174. data/spec/citeproc/processor_spec.rb +0 -61
  175. data/spec/citeproc/selector_spec.rb +0 -82
  176. data/spec/citeproc/variable_spec.rb +0 -69
  177. data/spec/csl/locale_spec.rb +0 -208
  178. data/spec/csl/node_spec.rb +0 -25
  179. data/spec/csl/nodes_spec.rb +0 -145
  180. data/spec/csl/style_spec.rb +0 -62
  181. data/spec/csl/term_spec.rb +0 -56
  182. data/spec/fixtures/dates.yaml +0 -80
  183. data/spec/fixtures/names.yaml +0 -115
  184. data/spec/fixtures/nodes.yaml +0 -245
  185. data/spec/support/attributes_spec.rb +0 -39
  186. data/spec/support/tree_spec.rb +0 -163
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ module CiteProc
4
+ module Ruby
5
+
6
+ describe 'Formats::Html' do
7
+ it 'can be created with an options hash' do
8
+ Formats::Html.new(:css_only => true).should be_css_only
9
+ end
10
+ end
11
+
12
+ describe 'Formats::Html#apply' do
13
+ let(:format) { Format.load 'html' }
14
+ let(:node) { CSL::Style::Text.new }
15
+
16
+ describe 'text-case formats' do
17
+ it 'supports lowercase' do
18
+ node[:'text-case'] = 'lowercase'
19
+ format.apply('Foo BAR', node).should == 'foo bar'
20
+ end
21
+ end
22
+
23
+ describe 'entity escaping' do
24
+ it 'escapes entities in the original text' do
25
+ node[:'text-case'] = 'lowercase'
26
+ format.apply('Foo & BAR', node).should == 'foo & bar'
27
+ end
28
+
29
+ it 'escapes entities in affixes' do
30
+ node[:prefix] = '<'
31
+ node[:suffix] = '>'
32
+ format.apply('foo', node).should == '&lt;foo&gt;'
33
+ end
34
+
35
+ it 'escapes entities in quotes' do
36
+ locale = CSL::Locale.new
37
+ locale.store 'open-quote', '<'
38
+ locale.store 'close-quote', '>'
39
+
40
+ node[:quotes] = true
41
+ format.apply('foo', node, locale).should == '&lt;foo&gt;'
42
+ end
43
+ end
44
+
45
+ describe 'affixes' do
46
+ it 'are added after text formats have been applied' do
47
+ node[:prefix] = 'foo'
48
+ node[:suffix] = 'ooo'
49
+ node[:'font-style'] = 'italic'
50
+
51
+ format.apply('ooo', node).should == 'foo<i>ooo</i>ooo'
52
+ end
53
+
54
+ it 'are added before text formats have been applied for layout nodes' do
55
+ layout = CSL::Style::Layout.new
56
+
57
+ layout[:prefix] = 'foo'
58
+ layout[:suffix] = 'ooo'
59
+ layout[:'font-style'] = 'italic'
60
+
61
+ format.apply('ooo', layout).should == '<i>foooooooo</i>'
62
+ end
63
+ end
64
+
65
+ describe 'font-style' do
66
+ it 'supports italic in both modes' do
67
+ node[:'font-style'] = 'italic'
68
+
69
+ format.apply('foo bar', node).should == '<i>foo bar</i>'
70
+
71
+ format.config[:italic] = 'em'
72
+ format.apply('foo bar', node).should == '<em>foo bar</em>'
73
+
74
+ format.config[:css_only] = true
75
+ format.apply('foo bar', node).should == '<span style="font-style: italic">foo bar</span>'
76
+ end
77
+
78
+ it 'supports normal and oblique via css' do
79
+ node[:'font-style'] = 'oblique'
80
+ format.apply('foo bar', node).should == '<span style="font-style: oblique">foo bar</span>'
81
+
82
+ node[:'font-style'] = 'normal'
83
+ format.apply('foo bar', node).should == '<span style="font-style: normal">foo bar</span>'
84
+ end
85
+ end
86
+
87
+ it 'supports font-variant via css' do
88
+ node[:'font-variant'] = 'small-caps'
89
+ format.apply('foo bar', node).should == '<span style="font-variant: small-caps">foo bar</span>'
90
+ end
91
+
92
+ describe 'font-weight' do
93
+ it 'supports bold in both modes' do
94
+ node[:'font-weight'] = 'bold'
95
+
96
+ format.apply('foo bar', node).should == '<b>foo bar</b>'
97
+
98
+ format.config[:bold] = 'strong'
99
+ format.apply('foo bar', node).should == '<strong>foo bar</strong>'
100
+
101
+ format.config[:css_only] = true
102
+ format.apply('foo bar', node).should == '<span style="font-weight: bold">foo bar</span>'
103
+ end
104
+
105
+ it 'supports normal and light via css' do
106
+ node[:'font-weight'] = 'light'
107
+ format.apply('foo bar', node).should == '<span style="font-weight: light">foo bar</span>'
108
+
109
+ node[:'font-weight'] = 'normal'
110
+ format.apply('foo bar', node).should == '<span style="font-weight: normal">foo bar</span>'
111
+ end
112
+ end
113
+
114
+ it 'supports text-decoration via css' do
115
+ node[:'text-decoration'] = 'underline'
116
+ format.apply('foo bar', node).should == '<span style="text-decoration: underline">foo bar</span>'
117
+ end
118
+
119
+ it 'supports vertical-align via css' do
120
+ node[:'vertical-align'] = 'sup'
121
+ format.apply('foo bar', node).should == '<span style="vertical-align: sup">foo bar</span>'
122
+ end
123
+
124
+ describe 'display' do
125
+ it 'is supported in an outer container' do
126
+ node[:'display'] = 'block'
127
+ node[:'text-decoration'] = 'underline'
128
+ format.apply('foo bar', node).should == '<div class="csl-block"><span style="text-decoration: underline">foo bar</span></div>'
129
+
130
+ node[:prefix] = '('
131
+ format.apply('foo bar', node).should == '<div class="csl-block">(<span style="text-decoration: underline">foo bar</span></div>'
132
+ end
133
+ end
134
+
135
+ describe 'bibliography formats' do
136
+ let(:bibliography) do
137
+ CiteProc::Bibliography.new do |b|
138
+ b.push 'id-1', 'foo'
139
+ b.push 'id-2', 'bar'
140
+ end
141
+ end
142
+
143
+ it 'can be applied' do
144
+ format.config[:bib_indent] = nil
145
+ format.bibliography(bibliography)
146
+ bibliography.join.should == '<ol class="csl-bibliography"><li class="csl-entry">foo</li><li class="csl-entry">bar</li></ol>'
147
+ end
148
+
149
+ it 'can be customized' do
150
+ format.config[:bib_indent] = nil
151
+ format.config[:bib_entry_class] = nil
152
+ format.config[:bib_entry] = 'span'
153
+ format.config[:bib_container] = 'div'
154
+
155
+ format.bibliography(bibliography)
156
+ bibliography.join.should == '<div class="csl-bibliography"><span>foo</span><span>bar</span></div>'
157
+ end
158
+ end
159
+ end
160
+
161
+ end
162
+ end
@@ -0,0 +1,293 @@
1
+ require 'spec_helper'
2
+
3
+ module CiteProc
4
+ module Ruby
5
+ describe 'Conditional Rendering Elements' do
6
+ let(:renderer) { Renderer.new }
7
+
8
+ let(:item) {
9
+ i = CiteProc::CitationItem.new(:id => 'ID-1')
10
+ i.data = CiteProc::Item.new(:id => 'ID-1')
11
+ i
12
+ }
13
+
14
+ describe 'Renderer#render_choose' do
15
+ let(:node) { CSL::Style::Choose.new }
16
+
17
+ it 'returns an empty string by default' do
18
+ renderer.render(item, node).should == ''
19
+ end
20
+
21
+ describe 'when there is a single nested block' do
22
+ let(:block) do
23
+ CSL::Style::Choose::Block.new do |b|
24
+ b << CSL::Style::Text.new( :term => 'retrieved')
25
+ end
26
+ end
27
+
28
+ before(:each) { node << block }
29
+
30
+ it 'returns the content of the nested node when the condition evaluates' do
31
+ block[:variable] = 'issue'
32
+ item.data[:issue] = 1
33
+ renderer.render(item, node).should == 'retrieved'
34
+ end
35
+
36
+ it 'returns an empty string when the condition does not hold' do
37
+ block[:variable] = 'issue'
38
+ renderer.render(item, node).should == ''
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'Renderer#render_block' do
44
+ let(:node) { CSL::Style::Choose::Block.new }
45
+
46
+ it 'returns an empty string by default' do
47
+ renderer.render(item, node).should == ''
48
+ end
49
+
50
+ describe 'when there is a text node in the block' do
51
+ before(:each) { node << CSL::Style::Text.new( :term => 'retrieved') }
52
+
53
+ it 'returns the content of the nested node when there is no condition' do
54
+ renderer.render(item, node).should == 'retrieved'
55
+ end
56
+ end
57
+ end
58
+
59
+ describe 'Renderer#evaluates?' do
60
+ let(:node) { CSL::Style::Choose::Block.new }
61
+
62
+ it 'returns true by default (else block)' do
63
+ renderer.evaluates?(item, node).should be_true
64
+ end
65
+
66
+ it 'fails if there is an unknown condition type' do
67
+ node.stub(:conditions).and_return([[:unknown, :all?, 'x']])
68
+ lambda { renderer.evaluates?(item, node) }.should raise_error
69
+ end
70
+
71
+ it 'returns false for disambiguate (implementation pending)' do
72
+ node[:disambiguate] = true
73
+ renderer.evaluates?(item, node).should be_false
74
+ end
75
+
76
+ it 'returns false for position (implementation pending)' do
77
+ node[:position] = 'first'
78
+ renderer.evaluates?(item, node).should be_false
79
+ end
80
+
81
+ describe 'for is-numeric conditions' do
82
+ before { node[:'is-numeric'] = 'note archive' }
83
+
84
+ it 'returns false unless all variables are numeric' do
85
+ renderer.evaluates?(item, node).should be_false
86
+
87
+ item.data[:archive] = 1
88
+ renderer.evaluates?(item, node).should be_false
89
+
90
+ item.data[:note] = 'L2d'
91
+ renderer.evaluates?(item, node).should be_true
92
+
93
+ item.data[:archive] = 'second'
94
+ renderer.evaluates?(item, node).should be_false
95
+ end
96
+ end
97
+
98
+ describe 'for is-uncertain-date conditions' do
99
+ before { node[:'is-uncertain-date'] = 'issued' }
100
+
101
+ it 'returns false unless all variables contain uncertain dates' do
102
+ renderer.evaluates?(item, node).should be_false
103
+
104
+ item.data[:issued] = 2012
105
+ renderer.evaluates?(item, node).should be_false
106
+
107
+ item.data[:issued].uncertain!
108
+ renderer.evaluates?(item, node).should be_true
109
+ end
110
+ end
111
+
112
+ describe 'for locator conditions' do
113
+ before { node[:locator] = 'figure book sub-verbo' }
114
+
115
+ it 'returns false unless the locator matches all of the given locators' do
116
+ renderer.evaluates?(item, node).should be_false
117
+
118
+ item.locator = :book
119
+ renderer.evaluates?(item, node).should be_false
120
+
121
+ item.locator = 'volume'
122
+ renderer.evaluates?(item, node).should be_false
123
+
124
+ item.locator = 'figure'
125
+ renderer.evaluates?(item, node).should be_false
126
+ end
127
+
128
+ describe 'when the match attribute is set to "any"' do
129
+ before { node[:match] = 'any' }
130
+
131
+ it 'returns false unless the locator matches any of the given locators' do
132
+ renderer.evaluates?(item, node).should be_false
133
+
134
+ item.locator = :book
135
+ renderer.evaluates?(item, node).should be_true
136
+
137
+ item.locator = 'volume'
138
+ renderer.evaluates?(item, node).should be_false
139
+
140
+ item.locator = 'figure'
141
+ renderer.evaluates?(item, node).should be_true
142
+ end
143
+
144
+ it 'matches "sub verbo" as "sub-verbo"' do
145
+ item.locator = 'sub-verbo'
146
+ renderer.evaluates?(item, node).should be_true
147
+
148
+ item.locator = 'sub verbo'
149
+ renderer.evaluates?(item, node).should be_true
150
+ end
151
+ end
152
+ end
153
+
154
+ describe 'for type conditions' do
155
+ before { node[:type] = 'book treaty' }
156
+
157
+ it 'returns false unless the type matches all of the given types' do
158
+ renderer.evaluates?(item, node).should be_false
159
+
160
+ item.data[:type] = :book
161
+ renderer.evaluates?(item, node).should be_false
162
+
163
+ item.data[:type] = 'article'
164
+ renderer.evaluates?(item, node).should be_false
165
+
166
+ item.data[:type] = 'treaty'
167
+ renderer.evaluates?(item, node).should be_false
168
+ end
169
+
170
+ describe 'when the match attribute is set to "any"' do
171
+ before { node[:match] = 'any' }
172
+
173
+ it 'returns false unless the locator matches any of the given locators' do
174
+ renderer.evaluates?(item, node).should be_false
175
+
176
+ item.data[:type] = :book
177
+ renderer.evaluates?(item, node).should be_true
178
+
179
+ item.data[:type] = 'article'
180
+ renderer.evaluates?(item, node).should be_false
181
+
182
+ item.data[:type] = 'treaty'
183
+ renderer.evaluates?(item, node).should be_true
184
+ end
185
+ end
186
+ end
187
+
188
+ describe 'for variable conditions' do
189
+ before { node[:variable] = 'volume issue' }
190
+
191
+ it 'returns false unless the item has all variables' do
192
+ renderer.evaluates?(item, node).should be_false
193
+
194
+ item.data[:volume] = 1
195
+ renderer.evaluates?(item, node).should be_false
196
+
197
+ item.data[:issue] = 1
198
+ renderer.evaluates?(item, node).should be_true
199
+
200
+ item.data[:volume] = nil
201
+ renderer.evaluates?(item, node).should be_false
202
+ end
203
+
204
+ describe 'with internal negations' do
205
+ before { node[:variable] = 'volume not:issue' }
206
+
207
+ it 'returns false unless the item has (or does not have) all variables' do
208
+ renderer.evaluates?(item, node).should be_false
209
+
210
+ item.data[:volume] = 1
211
+ renderer.evaluates?(item, node).should be_true
212
+
213
+ item.data[:issue] = 1
214
+ renderer.evaluates?(item, node).should be_false
215
+
216
+ item.data[:volume] = nil
217
+ renderer.evaluates?(item, node).should be_false
218
+ end
219
+ end
220
+
221
+ describe 'and the any-matcher' do
222
+ before { node[:match] = 'any' }
223
+
224
+ it 'returns false unless the item has any of the variables' do
225
+ renderer.evaluates?(item, node).should be_false
226
+
227
+ item.data[:volume] = 1
228
+ renderer.evaluates?(item, node).should be_true
229
+
230
+ item.data[:issue] = 1
231
+ renderer.evaluates?(item, node).should be_true
232
+
233
+ item.data[:volume] = nil
234
+ renderer.evaluates?(item, node).should be_true
235
+ end
236
+
237
+ describe 'with internal negations' do
238
+ before { node[:variable] = 'volume not:issue' }
239
+
240
+ it 'returns false unless the item has (or does not have) any of the variables' do
241
+ renderer.evaluates?(item, node).should be_true
242
+
243
+ item.data[:volume] = 1
244
+ renderer.evaluates?(item, node).should be_true
245
+
246
+ item.data[:issue] = 1
247
+ renderer.evaluates?(item, node).should be_true
248
+
249
+ item.data[:volume] = nil
250
+ renderer.evaluates?(item, node).should be_false
251
+ end
252
+ end
253
+ end
254
+
255
+ describe 'and the none-matcher' do
256
+ before { node[:match] = 'none' }
257
+
258
+ it 'returns false unless the item has none of the variables' do
259
+ renderer.evaluates?(item, node).should be_true
260
+
261
+ item.data[:volume] = 1
262
+ renderer.evaluates?(item, node).should be_false
263
+
264
+ item.data[:issue] = 1
265
+ renderer.evaluates?(item, node).should be_false
266
+
267
+ item.data[:volume] = nil
268
+ renderer.evaluates?(item, node).should be_false
269
+ end
270
+
271
+ describe 'with internal negations' do
272
+ before { node[:variable] = 'volume not:issue' }
273
+
274
+ it 'returns false unless the item has (or does not have) none of the variables' do
275
+ renderer.evaluates?(item, node).should be_false
276
+
277
+ item.data[:volume] = 1
278
+ renderer.evaluates?(item, node).should be_false
279
+
280
+ item.data[:issue] = 1
281
+ renderer.evaluates?(item, node).should be_false
282
+
283
+ item.data[:volume] = nil
284
+ renderer.evaluates?(item, node).should be_true
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
290
+
291
+ end
292
+ end
293
+ end