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,73 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe 'Array#symbolize_keys' do
4
-
5
- it 'should convert keys to symbols' do
6
- array_old = [ :abc, 'xyz', { 'foo' => 'bar', :baz => :qux } ]
7
- array_new = [ :abc, 'xyz', { :foo => 'bar', :baz => :qux } ]
8
- array_old.symbolize_keys.must_equal array_new
9
- end
10
-
11
- end
12
-
13
- describe 'Array#stringify_keys' do
14
-
15
- it 'should convert keys to strings' do
16
- array_old = [ :abc, 'xyz', { :foo => 'bar', 'baz' => :qux } ]
17
- array_new = [ :abc, 'xyz', { 'foo' => 'bar', 'baz' => :qux } ]
18
- array_old.stringify_keys.must_equal array_new
19
- end
20
-
21
- end
22
-
23
- describe 'Array#freeze_recursively' do
24
-
25
- it 'should prevent first-level elements from being modified' do
26
- array = [ :a, [ :b, :c ], :d ]
27
- array.freeze_recursively
28
-
29
- raised = false
30
- begin
31
- array[0] = 123
32
- rescue => e
33
- raised = true
34
- assert_match /^can't modify frozen /, e.message
35
- end
36
- assert raised
37
- end
38
-
39
- it 'should prevent second-level elements from being modified' do
40
- array = [ :a, [ :b, :c ], :d ]
41
- array.freeze_recursively
42
-
43
- raised = false
44
- begin
45
- array[1][0] = 123
46
- rescue => e
47
- raised = true
48
- assert_match /^can't modify frozen /, e.message
49
- end
50
- assert raised
51
- end
52
-
53
- it 'should not freeze infinitely' do
54
- a = []
55
- a << a
56
-
57
- a.freeze_recursively
58
-
59
- assert a.frozen?
60
- assert a[0].frozen?
61
- assert_equal a, a[0]
62
- end
63
-
64
- end
65
-
66
- describe 'Array#checksum' do
67
-
68
- it 'should work' do
69
- expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
70
- [ [ :foo, 123 ]].checksum.must_equal expectation
71
- end
72
-
73
- end
@@ -1,98 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe 'Hash#symbolize_keys' do
4
-
5
- it 'should convert keys to symbols' do
6
- hash_old = { 'foo' => 'bar' }
7
- hash_new = { :foo => 'bar' }
8
- hash_old.symbolize_keys.must_equal hash_new
9
- end
10
-
11
- end
12
-
13
- describe 'Hash#stringify_keys' do
14
-
15
- it 'should leave strings as strings' do
16
- hash_old = { 'foo' => 'bar' }
17
- hash_new = { 'foo' => 'bar' }
18
- hash_old.stringify_keys.must_equal hash_new
19
- end
20
-
21
- it 'should convert symbols to strings' do
22
- hash_old = { :foo => 'bar' }
23
- hash_new = { 'foo' => 'bar' }
24
- hash_old.stringify_keys.must_equal hash_new
25
- end
26
-
27
- it 'should convert integers to strings' do
28
- hash_old = { 123 => 'bar' }
29
- hash_new = { '123' => 'bar' }
30
- hash_old.stringify_keys.must_equal hash_new
31
- end
32
-
33
- it 'should convert nil to an empty string' do
34
- hash_old = { nil => 'bar' }
35
- hash_new = { '' => 'bar' }
36
- hash_old.stringify_keys.must_equal hash_new
37
- end
38
-
39
- end
40
-
41
- describe 'Hash#freeze_recursively' do
42
-
43
- it 'should prevent first-level elements from being modified' do
44
- hash = { :a => { :b => :c } }
45
- hash.freeze_recursively
46
-
47
- raised = false
48
- begin
49
- hash[:a] = 123
50
- rescue => e
51
- raised = true
52
- assert_match /^can't modify frozen /, e.message
53
- end
54
- assert raised
55
- end
56
-
57
- it 'should prevent second-level elements from being modified' do
58
- hash = { :a => { :b => :c } }
59
- hash.freeze_recursively
60
-
61
- raised = false
62
- begin
63
- hash[:a][:b] = 123
64
- rescue => e
65
- raised = true
66
- assert_match /^can't modify frozen /, e.message
67
- end
68
- assert raised
69
- end
70
-
71
- it 'should not freeze infinitely' do
72
- a = {}
73
- a[:x] = a
74
-
75
- a.freeze_recursively
76
-
77
- assert a.frozen?
78
- assert a[:x].frozen?
79
- assert_equal a, a[:x]
80
- end
81
-
82
- end
83
-
84
- describe 'Hash#checksum' do
85
-
86
- it 'should work' do
87
- expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
88
- { :foo => 123 }.checksum.must_equal expectation
89
- [ [ :foo, 123 ]].checksum.must_equal expectation
90
- end
91
-
92
- it 'should sort keys' do
93
- a = { :a => 1, :c => 2, :b => 3 }.checksum
94
- b = { :a => 1, :b => 3, :c => 2 }.checksum
95
- a.must_equal b
96
- end
97
-
98
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe 'Pathname#checksum' do
4
-
5
- it 'should work on empty files' do
6
- begin
7
- FileUtils.mkdir_p('tmp')
8
- File.open('tmp/myfile', 'w') { |io| io.write('') }
9
- pathname = Pathname.new('tmp/myfile')
10
- pathname.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
11
- ensure
12
- FileUtils.rm_rf('tmp')
13
- end
14
- end
15
-
16
- it 'should work on all files' do
17
- begin
18
- FileUtils.mkdir_p('tmp')
19
- File.open('tmp/myfile', 'w') { |io| io.write('abc') }
20
- pathname = Pathname.new('tmp/myfile')
21
- pathname.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
22
- ensure
23
- FileUtils.rm_rf('tmp')
24
- end
25
- end
26
-
27
- end
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe 'String#cleaned_identifier' do
4
-
5
- it 'should not convert already clean paths' do
6
- '/foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
7
- end
8
-
9
- it 'should prepend slash if necessary' do
10
- 'foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
11
- end
12
-
13
- it 'should append slash if necessary' do
14
- '/foo/bar'.cleaned_identifier.must_equal '/foo/bar/'
15
- end
16
-
17
- it 'should remove double slashes at start' do
18
- '//foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
19
- end
20
-
21
- it 'should remove double slashes at end' do
22
- '/foo/bar//'.cleaned_identifier.must_equal '/foo/bar/'
23
- end
24
-
25
- end
26
-
27
- describe 'String#checksum' do
28
-
29
- it 'should work on empty strings' do
30
- ''.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
31
- end
32
-
33
- it 'should work on all strings' do
34
- 'abc'.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
35
- end
36
-
37
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc3::ChecksumStoreTest < MiniTest::Unit::TestCase
4
-
5
- include Nanoc3::TestHelpers
6
-
7
- def test_get_with_existing_object
8
- require 'pstore'
9
-
10
- # Create store
11
- FileUtils.mkdir_p('tmp')
12
- pstore = PStore.new('tmp/checksums')
13
- pstore.transaction do
14
- pstore[:data] = { [ :item, '/moo/' ] => 'zomg' }
15
- pstore[:version] = 1
16
- end
17
-
18
- # Check
19
- store = Nanoc3::ChecksumStore.new
20
- store.load
21
- obj = Nanoc3::Item.new('Moo?', {}, '/moo/')
22
- assert_equal 'zomg', store[obj]
23
- end
24
-
25
- def test_get_with_nonexistant_object
26
- store = Nanoc3::ChecksumStore.new
27
- store.load
28
-
29
- # Check
30
- obj = Nanoc3::Item.new('Moo?', {}, '/animals/cow/')
31
- new_checksum = 'Moo?'.checksum + '-' + {}.checksum
32
- assert_equal nil, store[obj]
33
- end
34
-
35
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc3::CodeSnippetTest < MiniTest::Unit::TestCase
4
-
5
- include Nanoc3::TestHelpers
6
-
7
- def test_load
8
- # Initialize
9
- $complete_insane_parrot = 'meow'
10
-
11
- # Create code and load it
12
- code_snippet = Nanoc3::CodeSnippet.new("$complete_insane_parrot = 'woof'", 'parrot.rb')
13
- code_snippet.load
14
-
15
- # Ensure code is loaded
16
- assert_equal('woof', $complete_insane_parrot)
17
- end
18
-
19
- def test_load_with_toplevel_binding
20
- # Initialize
21
- @foo = 'meow'
22
-
23
- # Create code and load it
24
- code_snippet = Nanoc3::CodeSnippet.new("@foo = 'woof'", 'dog.rb')
25
- code_snippet.load
26
-
27
- # Ensure binding is correct
28
- assert_equal('meow', @foo)
29
- end
30
-
31
- end
@@ -1,316 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc3::CompilerTest < MiniTest::Unit::TestCase
4
-
5
- include Nanoc3::TestHelpers
6
-
7
- def test_compilation_rule_for
8
- # Mock rules
9
- rules = [ mock, mock, mock ]
10
- rules[0].expects(:applicable_to?).returns(false)
11
- rules[1].expects(:applicable_to?).returns(true)
12
- rules[1].expects(:rep_name).returns('wrong')
13
- rules[2].expects(:applicable_to?).returns(true)
14
- rules[2].expects(:rep_name).returns('right')
15
-
16
- # Create compiler
17
- compiler = Nanoc3::Compiler.new(nil)
18
- compiler.rules_collection.instance_eval { @item_compilation_rules = rules }
19
-
20
- # Mock rep
21
- rep = mock
22
- rep.stubs(:name).returns('right')
23
- item = mock
24
- rep.stubs(:item).returns(item)
25
-
26
- # Test
27
- assert_equal rules[2], compiler.rules_collection.compilation_rule_for(rep)
28
- end
29
-
30
- def test_routing_rule_for
31
- # Mock rules
32
- rules = [ mock, mock, mock ]
33
- rules[0].expects(:applicable_to?).returns(false)
34
- rules[1].expects(:applicable_to?).returns(true)
35
- rules[1].expects(:rep_name).returns('wrong')
36
- rules[2].expects(:applicable_to?).returns(true)
37
- rules[2].expects(:rep_name).returns('right')
38
-
39
- # Create compiler
40
- compiler = Nanoc3::Compiler.new(nil)
41
- compiler.rules_collection.instance_eval { @item_routing_rules = rules }
42
-
43
- # Mock rep
44
- rep = mock
45
- rep.stubs(:name).returns('right')
46
- item = mock
47
- rep.stubs(:item).returns(item)
48
-
49
- # Test
50
- assert_equal rules[2], compiler.rules_collection.routing_rule_for(rep)
51
- end
52
-
53
- def test_filter_for_layout_with_existant_layout
54
- # Mock site
55
- site = mock
56
-
57
- # Create compiler
58
- compiler = Nanoc3::Compiler.new(site)
59
- compiler.rules_collection.layout_filter_mapping[/.*/] = [ :erb, { :foo => 'bar' } ]
60
-
61
- # Mock layout
62
- layout = MiniTest::Mock.new
63
- layout.expect(:identifier, '/some_layout/')
64
-
65
- # Check
66
- assert_equal([ :erb, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
67
- end
68
-
69
- def test_filter_for_layout_with_existant_layout_and_unknown_filter
70
- # Mock site
71
- site = mock
72
-
73
- # Create compiler
74
- compiler = Nanoc3::Compiler.new(site)
75
- compiler.rules_collection.layout_filter_mapping[/.*/] = [ :some_unknown_filter, { :foo => 'bar' } ]
76
-
77
- # Mock layout
78
- layout = MiniTest::Mock.new
79
- layout.expect(:identifier, '/some_layout/')
80
-
81
- # Check
82
- assert_equal([ :some_unknown_filter, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
83
- end
84
-
85
- def test_filter_for_layout_with_nonexistant_layout
86
- # Mock site
87
- site = mock
88
-
89
- # Create compiler
90
- compiler = Nanoc3::Compiler.new(site)
91
- compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [ :erb, { :foo => 'bar' } ]
92
-
93
- # Mock layout
94
- layout = MiniTest::Mock.new
95
- layout.expect(:identifier, '/bar/')
96
-
97
- # Check
98
- assert_equal(nil, compiler.rules_collection.filter_for_layout(layout))
99
- end
100
-
101
- def test_filter_for_layout_with_many_layouts
102
- # Mock site
103
- site = mock
104
-
105
- # Create compiler
106
- compiler = Nanoc3::Compiler.new(site)
107
- compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [ :erb, { :char => 'd' } ]
108
- compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [ :erb, { :char => 'b' } ]
109
- compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [ :erb, { :char => 'c' } ] # never used!
110
- compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [ :erb, { :char => 'a' } ]
111
-
112
- # Mock layout
113
- layouts = [ mock, mock, mock, mock ]
114
- layouts[0].stubs(:identifier).returns('/a/b/c/d/')
115
- layouts[1].stubs(:identifier).returns('/a/b/c/')
116
- layouts[2].stubs(:identifier).returns('/a/b/')
117
- layouts[3].stubs(:identifier).returns('/a/')
118
-
119
- # Get expectations
120
- expectations = {
121
- 0 => 'd',
122
- 1 => 'b', # never used! not c, because b takes priority
123
- 2 => 'b',
124
- 3 => 'a'
125
- }
126
-
127
- # Check
128
- expectations.each_pair do |num, char|
129
- filter_and_args = compiler.rules_collection.filter_for_layout(layouts[num])
130
- refute_nil(filter_and_args)
131
- assert_equal(char, filter_and_args[1][:char])
132
- end
133
- end
134
-
135
- def test_compile_rep_should_write_proper_snapshots
136
- # Mock rep
137
- item = Nanoc3::Item.new('<%= 1 %> <%%= 2 %> <%%%= 3 %>', {}, '/moo/')
138
- rep = Nanoc3::ItemRep.new(item, :blah)
139
-
140
- # Set snapshot filenames
141
- rep.raw_paths = {
142
- :raw => 'raw.txt',
143
- :pre => 'pre.txt',
144
- :post => 'post.txt',
145
- :last => 'last.txt'
146
- }
147
-
148
- # Create rule
149
- rule_block = proc do
150
- filter :erb
151
- filter :erb
152
- layout '/blah/'
153
- filter :erb
154
- end
155
- rule = Nanoc3::Rule.new(/blah/, :meh, rule_block)
156
-
157
- # Create layout
158
- layout = Nanoc3::Layout.new('head <%= yield %> foot', {}, '/blah/')
159
-
160
- # Create site
161
- site = mock
162
- site.stubs(:config).returns({})
163
- site.stubs(:items).returns([])
164
- site.stubs(:layouts).returns([ layout ])
165
-
166
- # Create compiler
167
- compiler = Nanoc3::Compiler.new(site)
168
- compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
169
- compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [ :erb, {} ]
170
- site.stubs(:compiler).returns(compiler)
171
-
172
- # Compile
173
- compiler.send(:compile_rep, rep)
174
-
175
- # Test
176
- assert File.file?('raw.txt')
177
- assert File.file?('pre.txt')
178
- assert File.file?('post.txt')
179
- assert File.file?('last.txt')
180
- assert_equal '<%= 1 %> <%%= 2 %> <%%%= 3 %>', File.read('raw.txt')
181
- assert_equal '1 2 <%= 3 %>', File.read('pre.txt')
182
- assert_equal 'head 1 2 3 foot', File.read('post.txt')
183
- assert_equal 'head 1 2 3 foot', File.read('last.txt')
184
- end
185
-
186
- def test_compile_with_no_reps
187
- with_site do |site|
188
- site.compile
189
-
190
- assert Dir['output/*'].empty?
191
- end
192
- end
193
-
194
- def test_compile_with_one_rep
195
- with_site do |site|
196
- File.open('content/index.html', 'w') { |io| io.write('o hello') }
197
-
198
- site.compile
199
-
200
- assert Dir['output/*'].size == 1
201
- assert File.file?('output/index.html')
202
- assert File.read('output/index.html') == 'o hello'
203
- end
204
- end
205
-
206
- def test_compile_with_two_independent_reps
207
- with_site do |site|
208
- File.open('content/foo.html', 'w') { |io| io.write('o hai') }
209
- File.open('content/bar.html', 'w') { |io| io.write('o bai') }
210
-
211
- site.compile
212
-
213
- assert Dir['output/*'].size == 2
214
- assert File.file?('output/foo/index.html')
215
- assert File.file?('output/bar/index.html')
216
- assert File.read('output/foo/index.html') == 'o hai'
217
- assert File.read('output/bar/index.html') == 'o bai'
218
- end
219
- end
220
-
221
- def test_compile_with_two_dependent_reps
222
- with_site(:compilation_rule_content => 'filter :erb') do |site|
223
- File.open('content/foo.html', 'w') do |io|
224
- io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>!!!')
225
- end
226
- File.open('content/bar.html', 'w') do |io|
227
- io.write('manatee')
228
- end
229
-
230
- site.compile
231
-
232
- assert Dir['output/*'].size == 2
233
- assert File.file?('output/foo/index.html')
234
- assert File.file?('output/bar/index.html')
235
- assert File.read('output/foo/index.html') == 'manatee!!!'
236
- assert File.read('output/bar/index.html') == 'manatee'
237
- end
238
- end
239
-
240
- def test_compile_with_two_mutually_dependent_reps
241
- with_site(:compilation_rule_content => 'filter :erb') do |site|
242
- File.open('content/foo.html', 'w') do |io|
243
- io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>')
244
- end
245
- File.open('content/bar.html', 'w') do |io|
246
- io.write('<%= @items.find { |i| i.identifier == "/foo/" }.compiled_content %>')
247
- end
248
-
249
- assert_raises Nanoc3::Errors::RecursiveCompilation do
250
- site.compile
251
- end
252
- end
253
- end
254
-
255
- def test_disallow_routes_not_starting_with_slash
256
- # Create site
257
- Nanoc3::CLI.run %w( create_site bar)
258
-
259
- FileUtils.cd('bar') do
260
- # Create routes
261
- File.open('Rules', 'w') do |io|
262
- io.write "compile '*' do\n"
263
- io.write " layout 'default'\n"
264
- io.write "end\n"
265
- io.write "\n"
266
- io.write "route '*' do\n"
267
- io.write " 'index.html'\n"
268
- io.write "end\n"
269
- io.write "\n"
270
- io.write "layout '*', :erb\n"
271
- end
272
-
273
- # Create site
274
- site = Nanoc3::Site.new('.')
275
- error = assert_raises(RuntimeError) do
276
- site.compile
277
- end
278
- assert_match /^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message
279
- end
280
- end
281
-
282
- def test_load_should_be_idempotent
283
- # Create site
284
- Nanoc3::CLI.run %w( create_site bar)
285
-
286
- FileUtils.cd('bar') do
287
- site = Nanoc3::Site.new('.')
288
-
289
- compiler = Nanoc3::Compiler.new(site)
290
- def compiler.route_reps
291
- raise 'oh my gosh it is borken'
292
- end
293
-
294
- assert site.instance_eval { !@loaded }
295
- assert_raises(RuntimeError) { compiler.load }
296
- assert site.instance_eval { !@loaded }
297
- assert_raises(RuntimeError) { compiler.load }
298
- end
299
- end
300
-
301
- def test_compile_should_recompile_all_reps
302
- Nanoc3::CLI.run %w( create_site bar )
303
-
304
- FileUtils.cd('bar') do
305
- Nanoc3::CLI.run %w( compile )
306
-
307
- site = Nanoc3::Site.new('.')
308
- site.compile
309
-
310
- # At this point, even the already compiled items in the previous pass
311
- # should have their compiled content assigned, so this should work:
312
- site.items[0].reps[0].compiled_content
313
- end
314
- end
315
-
316
- end