nanoc3 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. metadata +14 -313
  2. data/.gemtest +0 -0
  3. data/ChangeLog +0 -3
  4. data/Gemfile +0 -29
  5. data/LICENSE +0 -19
  6. data/NEWS.md +0 -449
  7. data/README.md +0 -108
  8. data/Rakefile +0 -14
  9. data/bin/nanoc3 +0 -12
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  11. data/lib/nanoc3.rb +0 -28
  12. data/lib/nanoc3/base.rb +0 -49
  13. data/lib/nanoc3/base/compilation/checksum_store.rb +0 -57
  14. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +0 -62
  15. data/lib/nanoc3/base/compilation/compiler.rb +0 -455
  16. data/lib/nanoc3/base/compilation/compiler_dsl.rb +0 -214
  17. data/lib/nanoc3/base/compilation/dependency_tracker.rb +0 -196
  18. data/lib/nanoc3/base/compilation/filter.rb +0 -165
  19. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +0 -102
  20. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +0 -88
  21. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +0 -223
  22. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +0 -46
  23. data/lib/nanoc3/base/compilation/rule.rb +0 -73
  24. data/lib/nanoc3/base/compilation/rule_context.rb +0 -84
  25. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -40
  26. data/lib/nanoc3/base/compilation/rule_memory_store.rb +0 -53
  27. data/lib/nanoc3/base/compilation/rules_collection.rb +0 -231
  28. data/lib/nanoc3/base/context.rb +0 -47
  29. data/lib/nanoc3/base/core_ext.rb +0 -6
  30. data/lib/nanoc3/base/core_ext/array.rb +0 -62
  31. data/lib/nanoc3/base/core_ext/hash.rb +0 -63
  32. data/lib/nanoc3/base/core_ext/pathname.rb +0 -26
  33. data/lib/nanoc3/base/core_ext/string.rb +0 -46
  34. data/lib/nanoc3/base/directed_graph.rb +0 -275
  35. data/lib/nanoc3/base/errors.rb +0 -174
  36. data/lib/nanoc3/base/memoization.rb +0 -67
  37. data/lib/nanoc3/base/notification_center.rb +0 -84
  38. data/lib/nanoc3/base/ordered_hash.rb +0 -200
  39. data/lib/nanoc3/base/plugin_registry.rb +0 -165
  40. data/lib/nanoc3/base/result_data/item_rep.rb +0 -488
  41. data/lib/nanoc3/base/source_data/code_snippet.rb +0 -58
  42. data/lib/nanoc3/base/source_data/configuration.rb +0 -24
  43. data/lib/nanoc3/base/source_data/data_source.rb +0 -234
  44. data/lib/nanoc3/base/source_data/item.rb +0 -301
  45. data/lib/nanoc3/base/source_data/layout.rb +0 -130
  46. data/lib/nanoc3/base/source_data/site.rb +0 -361
  47. data/lib/nanoc3/base/store.rb +0 -135
  48. data/lib/nanoc3/cli.rb +0 -133
  49. data/lib/nanoc3/cli/command.rb +0 -139
  50. data/lib/nanoc3/cli/commands/autocompile.rb +0 -60
  51. data/lib/nanoc3/cli/commands/compile.rb +0 -280
  52. data/lib/nanoc3/cli/commands/create_item.rb +0 -62
  53. data/lib/nanoc3/cli/commands/create_layout.rb +0 -75
  54. data/lib/nanoc3/cli/commands/create_site.rb +0 -410
  55. data/lib/nanoc3/cli/commands/debug.rb +0 -119
  56. data/lib/nanoc3/cli/commands/info.rb +0 -98
  57. data/lib/nanoc3/cli/commands/nanoc.rb +0 -37
  58. data/lib/nanoc3/cli/commands/update.rb +0 -72
  59. data/lib/nanoc3/cli/commands/view.rb +0 -84
  60. data/lib/nanoc3/cli/commands/watch.rb +0 -125
  61. data/lib/nanoc3/cli/error_handler.rb +0 -193
  62. data/lib/nanoc3/cli/logger.rb +0 -91
  63. data/lib/nanoc3/data_sources.rb +0 -29
  64. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -42
  65. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -87
  66. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -38
  67. data/lib/nanoc3/data_sources/filesystem.rb +0 -299
  68. data/lib/nanoc3/data_sources/filesystem_unified.rb +0 -116
  69. data/lib/nanoc3/data_sources/filesystem_verbose.rb +0 -86
  70. data/lib/nanoc3/extra.rb +0 -22
  71. data/lib/nanoc3/extra/auto_compiler.rb +0 -103
  72. data/lib/nanoc3/extra/chick.rb +0 -125
  73. data/lib/nanoc3/extra/core_ext.rb +0 -4
  74. data/lib/nanoc3/extra/core_ext/enumerable.rb +0 -33
  75. data/lib/nanoc3/extra/core_ext/time.rb +0 -19
  76. data/lib/nanoc3/extra/deployers.rb +0 -11
  77. data/lib/nanoc3/extra/deployers/rsync.rb +0 -114
  78. data/lib/nanoc3/extra/file_proxy.rb +0 -40
  79. data/lib/nanoc3/extra/validators.rb +0 -12
  80. data/lib/nanoc3/extra/validators/links.rb +0 -264
  81. data/lib/nanoc3/extra/validators/w3c.rb +0 -95
  82. data/lib/nanoc3/extra/vcs.rb +0 -66
  83. data/lib/nanoc3/extra/vcses.rb +0 -17
  84. data/lib/nanoc3/extra/vcses/bazaar.rb +0 -25
  85. data/lib/nanoc3/extra/vcses/dummy.rb +0 -24
  86. data/lib/nanoc3/extra/vcses/git.rb +0 -25
  87. data/lib/nanoc3/extra/vcses/mercurial.rb +0 -25
  88. data/lib/nanoc3/extra/vcses/subversion.rb +0 -25
  89. data/lib/nanoc3/filters.rb +0 -53
  90. data/lib/nanoc3/filters/asciidoc.rb +0 -38
  91. data/lib/nanoc3/filters/bluecloth.rb +0 -19
  92. data/lib/nanoc3/filters/coderay.rb +0 -21
  93. data/lib/nanoc3/filters/colorize_syntax.rb +0 -261
  94. data/lib/nanoc3/filters/erb.rb +0 -35
  95. data/lib/nanoc3/filters/erubis.rb +0 -27
  96. data/lib/nanoc3/filters/haml.rb +0 -27
  97. data/lib/nanoc3/filters/kramdown.rb +0 -20
  98. data/lib/nanoc3/filters/less.rb +0 -53
  99. data/lib/nanoc3/filters/markaby.rb +0 -20
  100. data/lib/nanoc3/filters/maruku.rb +0 -20
  101. data/lib/nanoc3/filters/mustache.rb +0 -24
  102. data/lib/nanoc3/filters/rainpress.rb +0 -19
  103. data/lib/nanoc3/filters/rdiscount.rb +0 -22
  104. data/lib/nanoc3/filters/rdoc.rb +0 -33
  105. data/lib/nanoc3/filters/redcarpet.rb +0 -27
  106. data/lib/nanoc3/filters/redcloth.rb +0 -47
  107. data/lib/nanoc3/filters/relativize_paths.rb +0 -45
  108. data/lib/nanoc3/filters/rubypants.rb +0 -20
  109. data/lib/nanoc3/filters/sass.rb +0 -66
  110. data/lib/nanoc3/filters/slim.rb +0 -25
  111. data/lib/nanoc3/filters/typogruby.rb +0 -23
  112. data/lib/nanoc3/filters/uglify_js.rb +0 -42
  113. data/lib/nanoc3/helpers.rb +0 -16
  114. data/lib/nanoc3/helpers/blogging.rb +0 -319
  115. data/lib/nanoc3/helpers/breadcrumbs.rb +0 -40
  116. data/lib/nanoc3/helpers/capturing.rb +0 -138
  117. data/lib/nanoc3/helpers/filtering.rb +0 -50
  118. data/lib/nanoc3/helpers/html_escape.rb +0 -55
  119. data/lib/nanoc3/helpers/link_to.rb +0 -151
  120. data/lib/nanoc3/helpers/rendering.rb +0 -140
  121. data/lib/nanoc3/helpers/tagging.rb +0 -71
  122. data/lib/nanoc3/helpers/text.rb +0 -44
  123. data/lib/nanoc3/helpers/xml_sitemap.rb +0 -76
  124. data/lib/nanoc3/tasks.rb +0 -10
  125. data/lib/nanoc3/tasks/clean.rake +0 -16
  126. data/lib/nanoc3/tasks/clean.rb +0 -29
  127. data/lib/nanoc3/tasks/deploy/rsync.rake +0 -14
  128. data/lib/nanoc3/tasks/validate.rake +0 -92
  129. data/nanoc3.gemspec +0 -49
  130. data/tasks/doc.rake +0 -16
  131. data/tasks/test.rake +0 -44
  132. data/test/base/core_ext/array_spec.rb +0 -73
  133. data/test/base/core_ext/hash_spec.rb +0 -98
  134. data/test/base/core_ext/pathname_spec.rb +0 -27
  135. data/test/base/core_ext/string_spec.rb +0 -37
  136. data/test/base/test_checksum_store.rb +0 -35
  137. data/test/base/test_code_snippet.rb +0 -31
  138. data/test/base/test_compiler.rb +0 -316
  139. data/test/base/test_compiler_dsl.rb +0 -161
  140. data/test/base/test_context.rb +0 -31
  141. data/test/base/test_data_source.rb +0 -46
  142. data/test/base/test_dependency_tracker.rb +0 -262
  143. data/test/base/test_directed_graph.rb +0 -283
  144. data/test/base/test_filter.rb +0 -83
  145. data/test/base/test_item.rb +0 -179
  146. data/test/base/test_item_rep.rb +0 -553
  147. data/test/base/test_layout.rb +0 -59
  148. data/test/base/test_memoization.rb +0 -90
  149. data/test/base/test_notification_center.rb +0 -34
  150. data/test/base/test_outdatedness_checker.rb +0 -394
  151. data/test/base/test_plugin.rb +0 -30
  152. data/test/base/test_rule.rb +0 -19
  153. data/test/base/test_rule_context.rb +0 -65
  154. data/test/base/test_site.rb +0 -190
  155. data/test/cli/commands/test_compile.rb +0 -33
  156. data/test/cli/commands/test_create_item.rb +0 -14
  157. data/test/cli/commands/test_create_layout.rb +0 -28
  158. data/test/cli/commands/test_create_site.rb +0 -24
  159. data/test/cli/commands/test_help.rb +0 -12
  160. data/test/cli/commands/test_info.rb +0 -11
  161. data/test/cli/commands/test_update.rb +0 -10
  162. data/test/cli/test_cli.rb +0 -102
  163. data/test/cli/test_error_handler.rb +0 -29
  164. data/test/cli/test_logger.rb +0 -10
  165. data/test/data_sources/test_filesystem.rb +0 -433
  166. data/test/data_sources/test_filesystem_unified.rb +0 -536
  167. data/test/data_sources/test_filesystem_verbose.rb +0 -357
  168. data/test/extra/core_ext/test_enumerable.rb +0 -30
  169. data/test/extra/core_ext/test_time.rb +0 -15
  170. data/test/extra/deployers/test_rsync.rb +0 -232
  171. data/test/extra/test_auto_compiler.rb +0 -417
  172. data/test/extra/test_file_proxy.rb +0 -19
  173. data/test/extra/test_vcs.rb +0 -22
  174. data/test/extra/validators/test_links.rb +0 -51
  175. data/test/extra/validators/test_w3c.rb +0 -47
  176. data/test/filters/test_asciidoc.rb +0 -22
  177. data/test/filters/test_bluecloth.rb +0 -18
  178. data/test/filters/test_coderay.rb +0 -44
  179. data/test/filters/test_colorize_syntax.rb +0 -283
  180. data/test/filters/test_erb.rb +0 -99
  181. data/test/filters/test_erubis.rb +0 -70
  182. data/test/filters/test_haml.rb +0 -96
  183. data/test/filters/test_kramdown.rb +0 -18
  184. data/test/filters/test_less.rb +0 -113
  185. data/test/filters/test_markaby.rb +0 -24
  186. data/test/filters/test_maruku.rb +0 -18
  187. data/test/filters/test_mustache.rb +0 -25
  188. data/test/filters/test_rainpress.rb +0 -29
  189. data/test/filters/test_rdiscount.rb +0 -31
  190. data/test/filters/test_rdoc.rb +0 -18
  191. data/test/filters/test_redcarpet.rb +0 -63
  192. data/test/filters/test_redcloth.rb +0 -33
  193. data/test/filters/test_relativize_paths.rb +0 -332
  194. data/test/filters/test_rubypants.rb +0 -18
  195. data/test/filters/test_sass.rb +0 -229
  196. data/test/filters/test_slim.rb +0 -35
  197. data/test/filters/test_typogruby.rb +0 -21
  198. data/test/filters/test_uglify_js.rb +0 -30
  199. data/test/gem_loader.rb +0 -11
  200. data/test/helper.rb +0 -179
  201. data/test/helpers/test_blogging.rb +0 -754
  202. data/test/helpers/test_breadcrumbs.rb +0 -81
  203. data/test/helpers/test_capturing.rb +0 -41
  204. data/test/helpers/test_filtering.rb +0 -106
  205. data/test/helpers/test_html_escape.rb +0 -32
  206. data/test/helpers/test_link_to.rb +0 -249
  207. data/test/helpers/test_rendering.rb +0 -89
  208. data/test/helpers/test_tagging.rb +0 -87
  209. data/test/helpers/test_text.rb +0 -24
  210. data/test/helpers/test_xml_sitemap.rb +0 -103
  211. data/test/tasks/test_clean.rb +0 -67
@@ -1,553 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc3::ItemRepTest < MiniTest::Unit::TestCase
4
-
5
- include Nanoc3::TestHelpers
6
-
7
- def test_created_modified_compiled
8
- # TODO implement
9
- end
10
-
11
- def test_compiled_content_with_only_last_available
12
- # Create rep
13
- item = Nanoc3::Item.new(
14
- 'blah blah blah', {}, '/',
15
- :binary => false, :mtime => Time.now-500
16
- )
17
- rep = Nanoc3::ItemRep.new(item, nil)
18
- rep.instance_eval { @content = { :last => 'last content' } }
19
- rep.expects(:compiled?).returns(true)
20
-
21
- # Check
22
- assert_equal 'last content', rep.compiled_content
23
- end
24
-
25
- def test_compiled_content_with_pre_and_last_available
26
- # Create rep
27
- item = Nanoc3::Item.new(
28
- 'blah blah blah', {}, '/',
29
- :binary => false, :mtime => Time.now-500
30
- )
31
- rep = Nanoc3::ItemRep.new(item, nil)
32
- rep.instance_eval { @content = { :pre => 'pre content', :last => 'last content' } }
33
- rep.expects(:compiled?).returns(true)
34
-
35
- # Check
36
- assert_equal 'pre content', rep.compiled_content
37
- end
38
-
39
- def test_compiled_content_with_custom_snapshot
40
- # Create rep
41
- item = Nanoc3::Item.new(
42
- 'blah blah blah', {}, '/',
43
- :binary => false, :mtime => Time.now-500
44
- )
45
- rep = Nanoc3::ItemRep.new(item, nil)
46
- rep.instance_eval { @content = { :pre => 'pre content', :last => 'last content' } }
47
- rep.expects(:compiled?).returns(true)
48
-
49
- # Check
50
- assert_equal 'last content', rep.compiled_content(:snapshot => :last)
51
- end
52
-
53
- def test_compiled_content_with_invalid_snapshot
54
- # Create rep
55
- item = Nanoc3::Item.new(
56
- 'blah blah blah', {}, '/',
57
- :binary => false, :mtime => Time.now-500
58
- )
59
- rep = Nanoc3::ItemRep.new(item, nil)
60
- rep.instance_eval { @content = { :pre => 'pre content', :last => 'last content' } }
61
- rep.expects(:compiled?).returns(true)
62
-
63
- # Check
64
- assert_equal nil, rep.compiled_content(:snapshot => :klsjflkasdfl)
65
- end
66
-
67
- def test_compiled_content_with_uncompiled_content
68
- # Create rep
69
- item = Nanoc3::Item.new(
70
- "blah blah", {}, '/',
71
- :binary => false
72
- )
73
- rep = Nanoc3::ItemRep.new(item, nil)
74
- rep.expects(:compiled?).returns(false)
75
-
76
- # Check
77
- assert_raises(Nanoc3::Errors::UnmetDependency) do
78
- rep.compiled_content
79
- end
80
- end
81
-
82
- def test_filter
83
- # Mock site
84
- site = MiniTest::Mock.new
85
- site.expect(:items, [])
86
- site.expect(:config, [])
87
- site.expect(:layouts, [])
88
-
89
- # Mock item
90
- item = Nanoc3::Item.new(
91
- %[<%= '<%= "blah" %' + '>' %>], {}, '/',
92
- :binary => false
93
- )
94
-
95
- # Create item rep
96
- item_rep = Nanoc3::ItemRep.new(item, :foo)
97
- item_rep.instance_eval do
98
- @content[:raw] = item.raw_content
99
- @content[:last] = @content[:raw]
100
- end
101
-
102
- # Filter once
103
- item_rep.assigns = {}
104
- item_rep.filter(:erb)
105
- assert_equal(%[<%= "blah" %>], item_rep.instance_eval { @content[:last] })
106
-
107
- # Filter twice
108
- item_rep.assigns = {}
109
- item_rep.filter(:erb)
110
- assert_equal(%[blah], item_rep.instance_eval { @content[:last] })
111
- end
112
-
113
- def test_layout
114
- # Mock layout
115
- layout = Nanoc3::Layout.new(%[<%= "blah" %>], {}, '/somelayout/')
116
-
117
- # Mock item
118
- item = Nanoc3::Item.new(
119
- "blah blah", {}, '/',
120
- :binary => false
121
- )
122
-
123
- # Create item rep
124
- item_rep = Nanoc3::ItemRep.new(item, :foo)
125
- item_rep.instance_eval do
126
- @content[:raw] = item.raw_content
127
- @content[:last] = @content[:raw]
128
- end
129
-
130
- # Layout
131
- item_rep.assigns = {}
132
- item_rep.layout(layout, :erb, {})
133
- assert_equal(%[blah], item_rep.instance_eval { @content[:last] })
134
- end
135
-
136
- def test_snapshot
137
- # Mock site
138
- site = MiniTest::Mock.new
139
- site.expect(:items, [])
140
- site.expect(:config, [])
141
- site.expect(:layouts, [])
142
-
143
- # Mock item
144
- item = Nanoc3::Item.new(
145
- %[<%= '<%= "blah" %' + '>' %>], {}, '/foobar/',
146
- :binary => false
147
- )
148
-
149
- # Create item rep
150
- item_rep = Nanoc3::ItemRep.new(item, :foo)
151
- item_rep.instance_eval do
152
- @content[:raw] = item.raw_content
153
- @content[:last] = @content[:raw]
154
- end
155
-
156
- # Filter while taking snapshots
157
- item_rep.assigns = {}
158
- item_rep.snapshot(:foo)
159
- item_rep.filter(:erb)
160
- item_rep.snapshot(:bar)
161
- item_rep.filter(:erb)
162
- item_rep.snapshot(:qux)
163
-
164
- # Check snapshots
165
- assert_equal(%[<%= '<%= "blah" %' + '>' %>], item_rep.instance_eval { @content[:foo] })
166
- assert_equal(%[<%= "blah" %>], item_rep.instance_eval { @content[:bar] })
167
- assert_equal(%[blah], item_rep.instance_eval { @content[:qux] })
168
- end
169
-
170
- def test_snapshot_should_be_written
171
- # Mock item
172
- item = Nanoc3::Item.new(
173
- "blah blah", {}, '/',
174
- :binary => false
175
- )
176
-
177
- # Create rep
178
- item_rep = Nanoc3::ItemRep.new(item, :foo)
179
- item_rep.instance_eval { @content[:last] = 'Lorem ipsum, etc.' }
180
- item_rep.raw_paths = { :moo => 'foo-moo.txt' }
181
-
182
- # Test non-final
183
- refute File.file?(item_rep.raw_path(:snapshot => :moo))
184
- item_rep.snapshot(:moo, :final => false)
185
- refute File.file?(item_rep.raw_path(:snapshot => :moo))
186
-
187
- # Test final 1
188
- item_rep.snapshot(:moo, :final => true)
189
- assert File.file?(item_rep.raw_path(:snapshot => :moo))
190
- assert_equal 'Lorem ipsum, etc.', File.read(item_rep.raw_path(:snapshot => :moo))
191
- FileUtils.rm_f(item_rep.raw_path(:snapshot => :moo))
192
-
193
- # Test final 2
194
- item_rep.snapshot(:moo)
195
- assert File.file?(item_rep.raw_path(:snapshot => :moo))
196
- assert_equal 'Lorem ipsum, etc.', File.read(item_rep.raw_path(:snapshot => :moo))
197
- end
198
-
199
- def test_write_should_not_touch_identical_textual_files
200
- # Mock item
201
- item = Nanoc3::Item.new(
202
- "blah blah", {}, '/',
203
- :binary => false
204
- )
205
-
206
- # Create rep
207
- item_rep = Nanoc3::ItemRep.new(item, :foo)
208
- def item_rep.generate_diff ; end
209
- item_rep.instance_eval { @content[:last] = 'Lorem ipsum, etc.' }
210
- item_rep.raw_path = 'foo/bar/baz/quux.txt'
211
-
212
- # Write once
213
- item_rep.write
214
- a_long_time_ago = Time.now-1_000_000
215
- File.utime(a_long_time_ago, a_long_time_ago, item_rep.raw_path)
216
-
217
- # Write again
218
- assert_equal a_long_time_ago.to_s, File.mtime(item_rep.raw_path).to_s
219
- item_rep.write
220
- assert_equal a_long_time_ago.to_s, File.mtime(item_rep.raw_path).to_s
221
- end
222
-
223
- def test_write_should_not_touch_identical_binary_files
224
- # Create temporary source file
225
- File.open('blahblah', 'w') { |io| io.write("Blah blah…") }
226
- full_file_path = File.expand_path('blahblah')
227
-
228
- # Mock item
229
- item = Nanoc3::Item.new(
230
- full_file_path, {}, '/',
231
- :binary => true
232
- )
233
-
234
- # Create rep
235
- item_rep = Nanoc3::ItemRep.new(item, :foo)
236
- item_rep.raw_path = 'foo/bar/baz/quux'
237
-
238
- # Write once
239
- item_rep.write
240
- a_long_time_ago = Time.now-1_000_000
241
- File.utime(a_long_time_ago, a_long_time_ago, item_rep.raw_path)
242
-
243
- # Write again
244
- assert_equal a_long_time_ago.to_s, File.mtime(item_rep.raw_path).to_s
245
- item_rep.write
246
- assert_equal a_long_time_ago.to_s, File.mtime(item_rep.raw_path).to_s
247
- end
248
-
249
- def test_write
250
- # Mock item
251
- item = Nanoc3::Item.new(
252
- "blah blah", {}, '/',
253
- :binary => false
254
- )
255
-
256
- # Create rep
257
- item_rep = Nanoc3::ItemRep.new(item, :foo)
258
- item_rep.instance_eval { @content[:last] = 'Lorem ipsum, etc.' }
259
- item_rep.raw_path = 'foo/bar/baz/quux.txt'
260
-
261
- # Write
262
- item_rep.write
263
-
264
- # Check
265
- assert(File.file?('foo/bar/baz/quux.txt'))
266
- assert_equal('Lorem ipsum, etc.', File.read('foo/bar/baz/quux.txt'))
267
- end
268
-
269
- def test_filter_text_to_binary
270
- # Mock item
271
- item = Nanoc3::Item.new(
272
- "blah blah", {}, '/',
273
- :binary => false
274
- )
275
-
276
- # Create rep
277
- rep = Nanoc3::ItemRep.new(item, :foo)
278
- def rep.assigns ; {} ; end
279
-
280
- # Create fake filter
281
- def rep.filter_named(name)
282
- @filter ||= Class.new(::Nanoc3::Filter) do
283
- type :text => :binary
284
- def run(content, params={})
285
- File.open(output_filename, 'w') { |io| io.write(content) }
286
- end
287
- end
288
- end
289
-
290
- # Run
291
- rep.filter(:foo)
292
-
293
- # Check
294
- assert rep.binary?
295
- end
296
-
297
- def test_filter_with_textual_rep_and_binary_filter
298
- # Mock item
299
- item = Nanoc3::Item.new(
300
- "blah blah", {}, '/',
301
- :binary => false
302
- )
303
-
304
- # Create rep
305
- rep = Nanoc3::ItemRep.new(item, :foo)
306
- def rep.assigns ; {} ; end
307
-
308
- # Create fake filter
309
- def rep.filter_named(name)
310
- @filter ||= Class.new(::Nanoc3::Filter) do
311
- type :binary
312
- def run(content, params={})
313
- File.open(output_filename, 'w') { |io| io.write(content) }
314
- end
315
- end
316
- end
317
-
318
- # Run
319
- assert_raises ::Nanoc3::Errors::CannotUseBinaryFilter do
320
- rep.filter(:foo)
321
- end
322
- end
323
-
324
- def test_filter_get_compiled_content_from_binary_item
325
- # Mock item
326
- item = Nanoc3::Item.new(
327
- "blah blah", {}, '/',
328
- :binary => true
329
- )
330
-
331
- # Create rep
332
- rep = Nanoc3::ItemRep.new(item, :foo)
333
- def rep.compiled? ; true ; end
334
-
335
- # Check
336
- assert_nil rep.compiled_content
337
- end
338
-
339
- def test_using_textual_filters_on_binary_reps_raises
340
- item = create_binary_item
341
- site = mock_and_stub(:items => [item],
342
- :layouts => [],
343
- :config => []
344
- )
345
- item.stubs(:site).returns(site)
346
- rep = create_rep_for(item, :foo)
347
- create_textual_filter
348
-
349
- assert rep.binary?
350
- assert_raises(Nanoc3::Errors::CannotUseTextualFilter) { rep.filter(:text_filter) }
351
- end
352
-
353
- def test_writing_binary_reps_uses_content_in_last_filename
354
- require 'tempfile'
355
-
356
- in_filename = 'nanoc-in'
357
- out_filename = 'nanoc-out'
358
- file_content = 'Some content for this test'
359
- File.open(in_filename, 'w') { |io| io.write(file_content) }
360
-
361
- item = create_binary_item
362
- rep = create_rep_for(item, :foo)
363
- rep.temporary_filenames[:last] = in_filename
364
- rep.raw_paths[:last] = out_filename
365
-
366
- rep.write
367
-
368
- assert(File.exist?(out_filename))
369
- assert_equal(file_content, File.read(out_filename))
370
- end
371
-
372
- def test_converted_binary_rep_can_be_layed_out
373
- # Mock layout
374
- layout = Nanoc3::Layout.new(%[<%= "blah" %> <%= yield %>], {}, '/somelayout/')
375
-
376
- # Create item and item rep
377
- item = create_binary_item
378
- rep = create_rep_for(item, :foo)
379
- rep.assigns = { :content => 'meh' }
380
-
381
- # Create filter
382
- Class.new(::Nanoc3::Filter) do
383
- type :binary => :text
384
- identifier :binary_to_text
385
- def run(content, params={})
386
- content + ' textified'
387
- end
388
- end
389
-
390
- # Run and check
391
- rep.filter(:binary_to_text)
392
- rep.layout(layout, :erb, {})
393
- assert_equal('blah meh', rep.instance_eval { @content[:last] })
394
- end
395
-
396
- def test_converted_binary_rep_can_be_filtered_with_textual_filters
397
- item = create_binary_item
398
- site = mock_and_stub(:items => [item],
399
- :layouts => [],
400
- :config => []
401
- )
402
- item.stubs(:site).returns(site)
403
- rep = create_rep_for(item, :foo)
404
- rep.assigns = {}
405
- create_textual_filter
406
-
407
- assert rep.binary?
408
-
409
- def rep.filter_named(name)
410
- Class.new(::Nanoc3::Filter) do
411
- type :binary => :text
412
- def run(content, params={})
413
- "Some textual content"
414
- end
415
- end
416
- end
417
- rep.filter(:binary_to_text)
418
- assert !rep.binary?
419
-
420
- def rep.filter_named(name)
421
- Class.new(::Nanoc3::Filter) do
422
- type :text
423
- def run(content, params={})
424
- "Some textual content"
425
- end
426
- end
427
- end
428
- rep.filter(:text_filter)
429
- assert !rep.binary?
430
- end
431
-
432
- def test_converted_binary_rep_cannot_be_filtered_with_binary_filters
433
- item = create_binary_item
434
- site = mock_and_stub(
435
- :items => [item],
436
- :layouts => [],
437
- :config => []
438
- )
439
- item.stubs(:site).returns(site)
440
- rep = create_rep_for(item, :foo)
441
- rep.assigns = {}
442
- create_binary_filter
443
-
444
- assert rep.binary?
445
- def rep.filter_named(name)
446
- @filter ||= Class.new(::Nanoc3::Filter) do
447
- type :binary => :text
448
- def run(content, params={})
449
- "Some textual content"
450
- end
451
- end
452
- end
453
- rep.filter(:binary_to_text)
454
- refute rep.binary?
455
- assert_raises(Nanoc3::Errors::CannotUseBinaryFilter) { rep.filter(:binary_filter) }
456
- end
457
-
458
- def test_new_content_should_be_frozen
459
- filter_class = Class.new(::Nanoc3::Filter) do
460
- def run(content, params={})
461
- content.gsub!('foo', 'moo')
462
- content
463
- end
464
- end
465
-
466
- item = Nanoc3::Item.new("foo bar", {}, '/foo/')
467
- rep = Nanoc3::ItemRep.new(item, :default)
468
- rep.instance_eval { @filter_class = filter_class }
469
- def rep.filter_named(name) ; @filter_class ; end
470
-
471
- raised = false
472
- begin
473
- rep.filter(:whatever)
474
- rescue => e
475
- raised = true
476
- assert_match /^can't modify frozen /, e.message
477
- end
478
- assert raised
479
- end
480
-
481
- def test_filter_should_freeze_content
482
- filter_class = Class.new(::Nanoc3::Filter) do
483
- def run(content, params={})
484
- content.gsub!('foo', 'moo')
485
- content
486
- end
487
- end
488
-
489
- item = Nanoc3::Item.new("foo bar", {}, '/foo/')
490
- rep = Nanoc3::ItemRep.new(item, :default)
491
- rep.instance_eval { @filter_class = filter_class }
492
- def rep.filter_named(name) ; @filter_class ; end
493
-
494
- raised = false
495
- begin
496
- rep.filter(:erb)
497
- rep.filter(:whatever)
498
- rescue => e
499
- raised = true
500
- assert_match /^can't modify frozen /, e.message
501
- end
502
- assert raised
503
- end
504
-
505
- private
506
-
507
- def create_binary_item
508
- Nanoc3::Item.new(
509
- "/a/file/name.dat", {}, '/',
510
- :binary => true
511
- )
512
- end
513
-
514
- def mock_and_stub(params)
515
- m = mock
516
- params.each do |method, return_value|
517
- m.stubs(method.to_sym).returns( return_value )
518
- end
519
- m
520
- end
521
-
522
- def create_rep_for(item, name)
523
- Nanoc3::ItemRep.new(item, name)
524
- end
525
-
526
- def create_textual_filter
527
- f = create_filter(:text)
528
- f.class_eval do
529
- def run(content, params={})
530
- ""
531
- end
532
- end
533
- f
534
- end
535
-
536
- def create_binary_filter
537
- f = create_filter(:binary)
538
- f.class_eval do
539
- def run(content, params={})
540
- File.open(output_filename, 'w') { |io| io.write(content) }
541
- end
542
- end
543
- f
544
- end
545
-
546
- def create_filter(type)
547
- filter_klass = Class.new(Nanoc3::Filter)
548
- filter_klass.type(type)
549
- Nanoc3::Filter.register filter_klass, "#{type}_filter".to_sym
550
- filter_klass
551
- end
552
-
553
- end