nanoc 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 (230) hide show
  1. data/.gemtest +0 -0
  2. data/ChangeLog +3 -0
  3. data/Gemfile +32 -0
  4. data/LICENSE +19 -0
  5. data/NEWS.md +470 -0
  6. data/README.md +114 -0
  7. data/Rakefile +14 -0
  8. data/bin/nanoc +7 -27
  9. data/bin/nanoc3 +3 -0
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  11. data/lib/nanoc.rb +41 -0
  12. data/lib/nanoc/base.rb +49 -0
  13. data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
  14. data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
  15. data/lib/nanoc/base/compilation/compiler.rb +458 -0
  16. data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
  17. data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
  18. data/lib/nanoc/base/compilation/filter.rb +165 -0
  19. data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
  20. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
  21. data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
  22. data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
  23. data/lib/nanoc/base/compilation/rule.rb +73 -0
  24. data/lib/nanoc/base/compilation/rule_context.rb +84 -0
  25. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
  26. data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
  27. data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
  28. data/lib/nanoc/base/context.rb +47 -0
  29. data/lib/nanoc/base/core_ext.rb +6 -0
  30. data/lib/nanoc/base/core_ext/array.rb +62 -0
  31. data/lib/nanoc/base/core_ext/hash.rb +63 -0
  32. data/lib/nanoc/base/core_ext/pathname.rb +26 -0
  33. data/lib/nanoc/base/core_ext/string.rb +46 -0
  34. data/lib/nanoc/base/directed_graph.rb +275 -0
  35. data/lib/nanoc/base/errors.rb +211 -0
  36. data/lib/nanoc/base/memoization.rb +67 -0
  37. data/lib/nanoc/base/notification_center.rb +84 -0
  38. data/lib/nanoc/base/ordered_hash.rb +200 -0
  39. data/lib/nanoc/base/plugin_registry.rb +181 -0
  40. data/lib/nanoc/base/result_data/item_rep.rb +492 -0
  41. data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
  42. data/lib/nanoc/base/source_data/configuration.rb +24 -0
  43. data/lib/nanoc/base/source_data/data_source.rb +234 -0
  44. data/lib/nanoc/base/source_data/item.rb +301 -0
  45. data/lib/nanoc/base/source_data/layout.rb +130 -0
  46. data/lib/nanoc/base/source_data/site.rb +361 -0
  47. data/lib/nanoc/base/store.rb +135 -0
  48. data/lib/nanoc/cli.rb +137 -0
  49. data/lib/nanoc/cli/command_runner.rb +104 -0
  50. data/lib/nanoc/cli/commands/autocompile.rb +58 -0
  51. data/lib/nanoc/cli/commands/compile.rb +297 -0
  52. data/lib/nanoc/cli/commands/create_item.rb +60 -0
  53. data/lib/nanoc/cli/commands/create_layout.rb +73 -0
  54. data/lib/nanoc/cli/commands/create_site.rb +411 -0
  55. data/lib/nanoc/cli/commands/debug.rb +117 -0
  56. data/lib/nanoc/cli/commands/deploy.rb +79 -0
  57. data/lib/nanoc/cli/commands/info.rb +98 -0
  58. data/lib/nanoc/cli/commands/nanoc.rb +38 -0
  59. data/lib/nanoc/cli/commands/prune.rb +50 -0
  60. data/lib/nanoc/cli/commands/update.rb +70 -0
  61. data/lib/nanoc/cli/commands/view.rb +82 -0
  62. data/lib/nanoc/cli/commands/watch.rb +124 -0
  63. data/lib/nanoc/cli/error_handler.rb +199 -0
  64. data/lib/nanoc/cli/logger.rb +92 -0
  65. data/lib/nanoc/data_sources.rb +29 -0
  66. data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
  67. data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
  68. data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
  69. data/lib/nanoc/data_sources/filesystem.rb +299 -0
  70. data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
  71. data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
  72. data/lib/nanoc/extra.rb +24 -0
  73. data/lib/nanoc/extra/auto_compiler.rb +103 -0
  74. data/lib/nanoc/extra/chick.rb +125 -0
  75. data/lib/nanoc/extra/core_ext.rb +6 -0
  76. data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
  77. data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
  78. data/lib/nanoc/extra/core_ext/time.rb +19 -0
  79. data/lib/nanoc/extra/deployer.rb +47 -0
  80. data/lib/nanoc/extra/deployers.rb +15 -0
  81. data/lib/nanoc/extra/deployers/fog.rb +98 -0
  82. data/lib/nanoc/extra/deployers/rsync.rb +70 -0
  83. data/lib/nanoc/extra/file_proxy.rb +40 -0
  84. data/lib/nanoc/extra/pruner.rb +86 -0
  85. data/lib/nanoc/extra/validators.rb +12 -0
  86. data/lib/nanoc/extra/validators/links.rb +268 -0
  87. data/lib/nanoc/extra/validators/w3c.rb +95 -0
  88. data/lib/nanoc/extra/vcs.rb +66 -0
  89. data/lib/nanoc/extra/vcses.rb +17 -0
  90. data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
  91. data/lib/nanoc/extra/vcses/dummy.rb +24 -0
  92. data/lib/nanoc/extra/vcses/git.rb +25 -0
  93. data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
  94. data/lib/nanoc/extra/vcses/subversion.rb +25 -0
  95. data/lib/nanoc/filters.rb +59 -0
  96. data/lib/nanoc/filters/asciidoc.rb +38 -0
  97. data/lib/nanoc/filters/bluecloth.rb +19 -0
  98. data/lib/nanoc/filters/coderay.rb +21 -0
  99. data/lib/nanoc/filters/coffeescript.rb +20 -0
  100. data/lib/nanoc/filters/colorize_syntax.rb +298 -0
  101. data/lib/nanoc/filters/erb.rb +38 -0
  102. data/lib/nanoc/filters/erubis.rb +34 -0
  103. data/lib/nanoc/filters/haml.rb +27 -0
  104. data/lib/nanoc/filters/kramdown.rb +20 -0
  105. data/lib/nanoc/filters/less.rb +53 -0
  106. data/lib/nanoc/filters/markaby.rb +20 -0
  107. data/lib/nanoc/filters/maruku.rb +20 -0
  108. data/lib/nanoc/filters/mustache.rb +24 -0
  109. data/lib/nanoc/filters/rainpress.rb +19 -0
  110. data/lib/nanoc/filters/rdiscount.rb +22 -0
  111. data/lib/nanoc/filters/rdoc.rb +33 -0
  112. data/lib/nanoc/filters/redcarpet.rb +62 -0
  113. data/lib/nanoc/filters/redcloth.rb +47 -0
  114. data/lib/nanoc/filters/relativize_paths.rb +94 -0
  115. data/lib/nanoc/filters/rubypants.rb +20 -0
  116. data/lib/nanoc/filters/sass.rb +74 -0
  117. data/lib/nanoc/filters/slim.rb +25 -0
  118. data/lib/nanoc/filters/typogruby.rb +23 -0
  119. data/lib/nanoc/filters/uglify_js.rb +42 -0
  120. data/lib/nanoc/filters/xsl.rb +46 -0
  121. data/lib/nanoc/filters/yui_compressor.rb +23 -0
  122. data/lib/nanoc/helpers.rb +16 -0
  123. data/lib/nanoc/helpers/blogging.rb +319 -0
  124. data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
  125. data/lib/nanoc/helpers/capturing.rb +138 -0
  126. data/lib/nanoc/helpers/filtering.rb +50 -0
  127. data/lib/nanoc/helpers/html_escape.rb +55 -0
  128. data/lib/nanoc/helpers/link_to.rb +151 -0
  129. data/lib/nanoc/helpers/rendering.rb +140 -0
  130. data/lib/nanoc/helpers/tagging.rb +71 -0
  131. data/lib/nanoc/helpers/text.rb +44 -0
  132. data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
  133. data/lib/nanoc/tasks.rb +10 -0
  134. data/lib/nanoc/tasks/clean.rake +16 -0
  135. data/lib/nanoc/tasks/clean.rb +29 -0
  136. data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
  137. data/lib/nanoc/tasks/validate.rake +92 -0
  138. data/nanoc.gemspec +49 -0
  139. data/tasks/doc.rake +16 -0
  140. data/tasks/test.rake +46 -0
  141. data/test/base/core_ext/array_spec.rb +73 -0
  142. data/test/base/core_ext/hash_spec.rb +98 -0
  143. data/test/base/core_ext/pathname_spec.rb +27 -0
  144. data/test/base/core_ext/string_spec.rb +37 -0
  145. data/test/base/test_checksum_store.rb +35 -0
  146. data/test/base/test_code_snippet.rb +31 -0
  147. data/test/base/test_compiler.rb +403 -0
  148. data/test/base/test_compiler_dsl.rb +161 -0
  149. data/test/base/test_context.rb +31 -0
  150. data/test/base/test_data_source.rb +46 -0
  151. data/test/base/test_dependency_tracker.rb +262 -0
  152. data/test/base/test_directed_graph.rb +288 -0
  153. data/test/base/test_filter.rb +83 -0
  154. data/test/base/test_item.rb +179 -0
  155. data/test/base/test_item_rep.rb +579 -0
  156. data/test/base/test_layout.rb +59 -0
  157. data/test/base/test_memoization.rb +90 -0
  158. data/test/base/test_notification_center.rb +34 -0
  159. data/test/base/test_outdatedness_checker.rb +394 -0
  160. data/test/base/test_plugin.rb +30 -0
  161. data/test/base/test_rule.rb +19 -0
  162. data/test/base/test_rule_context.rb +65 -0
  163. data/test/base/test_site.rb +190 -0
  164. data/test/cli/commands/test_compile.rb +33 -0
  165. data/test/cli/commands/test_create_item.rb +14 -0
  166. data/test/cli/commands/test_create_layout.rb +28 -0
  167. data/test/cli/commands/test_create_site.rb +24 -0
  168. data/test/cli/commands/test_deploy.rb +74 -0
  169. data/test/cli/commands/test_help.rb +12 -0
  170. data/test/cli/commands/test_info.rb +11 -0
  171. data/test/cli/commands/test_prune.rb +98 -0
  172. data/test/cli/commands/test_update.rb +10 -0
  173. data/test/cli/test_cli.rb +102 -0
  174. data/test/cli/test_error_handler.rb +29 -0
  175. data/test/cli/test_logger.rb +10 -0
  176. data/test/data_sources/test_filesystem.rb +433 -0
  177. data/test/data_sources/test_filesystem_unified.rb +536 -0
  178. data/test/data_sources/test_filesystem_verbose.rb +357 -0
  179. data/test/extra/core_ext/test_enumerable.rb +30 -0
  180. data/test/extra/core_ext/test_pathname.rb +17 -0
  181. data/test/extra/core_ext/test_time.rb +15 -0
  182. data/test/extra/deployers/test_fog.rb +67 -0
  183. data/test/extra/deployers/test_rsync.rb +100 -0
  184. data/test/extra/test_auto_compiler.rb +417 -0
  185. data/test/extra/test_file_proxy.rb +19 -0
  186. data/test/extra/test_vcs.rb +22 -0
  187. data/test/extra/validators/test_links.rb +62 -0
  188. data/test/extra/validators/test_w3c.rb +47 -0
  189. data/test/filters/test_asciidoc.rb +22 -0
  190. data/test/filters/test_bluecloth.rb +18 -0
  191. data/test/filters/test_coderay.rb +44 -0
  192. data/test/filters/test_coffeescript.rb +18 -0
  193. data/test/filters/test_colorize_syntax.rb +379 -0
  194. data/test/filters/test_erb.rb +105 -0
  195. data/test/filters/test_erubis.rb +78 -0
  196. data/test/filters/test_haml.rb +96 -0
  197. data/test/filters/test_kramdown.rb +18 -0
  198. data/test/filters/test_less.rb +113 -0
  199. data/test/filters/test_markaby.rb +24 -0
  200. data/test/filters/test_maruku.rb +18 -0
  201. data/test/filters/test_mustache.rb +25 -0
  202. data/test/filters/test_rainpress.rb +29 -0
  203. data/test/filters/test_rdiscount.rb +31 -0
  204. data/test/filters/test_rdoc.rb +18 -0
  205. data/test/filters/test_redcarpet.rb +73 -0
  206. data/test/filters/test_redcloth.rb +33 -0
  207. data/test/filters/test_relativize_paths.rb +533 -0
  208. data/test/filters/test_rubypants.rb +18 -0
  209. data/test/filters/test_sass.rb +229 -0
  210. data/test/filters/test_slim.rb +35 -0
  211. data/test/filters/test_typogruby.rb +21 -0
  212. data/test/filters/test_uglify_js.rb +30 -0
  213. data/test/filters/test_xsl.rb +105 -0
  214. data/test/filters/test_yui_compressor.rb +44 -0
  215. data/test/gem_loader.rb +11 -0
  216. data/test/helper.rb +207 -0
  217. data/test/helpers/test_blogging.rb +754 -0
  218. data/test/helpers/test_breadcrumbs.rb +81 -0
  219. data/test/helpers/test_capturing.rb +41 -0
  220. data/test/helpers/test_filtering.rb +106 -0
  221. data/test/helpers/test_html_escape.rb +32 -0
  222. data/test/helpers/test_link_to.rb +249 -0
  223. data/test/helpers/test_rendering.rb +89 -0
  224. data/test/helpers/test_tagging.rb +87 -0
  225. data/test/helpers/test_text.rb +24 -0
  226. data/test/helpers/test_xml_sitemap.rb +103 -0
  227. data/test/tasks/test_clean.rb +67 -0
  228. metadata +327 -15
  229. data/bin/nanoc-select +0 -86
  230. data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::Commands::HelpTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_run
8
+ Nanoc::CLI.run %w( help )
9
+ Nanoc::CLI.run %w( help co )
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::Commands::InfoTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_run
8
+ Nanoc::CLI.run %w( info )
9
+ end
10
+
11
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::Commands::PruneTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_run_without_yes
8
+ with_site do |site|
9
+ # Set output dir
10
+ File.open('config.yaml', 'w') { |io| io.write 'output_dir: output2' }
11
+ FileUtils.mkdir_p('output2')
12
+
13
+ # Create source files
14
+ File.open('content/index.html', 'w') { |io| io.write 'stuff' }
15
+
16
+ # Create output files
17
+ File.open('output2/foo.html', 'w') { |io| io.write 'this is a foo.' }
18
+ File.open('output2/index.html', 'w') { |io| io.write 'this is a index.' }
19
+
20
+ assert_raises SystemExit do
21
+ Nanoc::CLI.run %w( prune )
22
+ end
23
+
24
+ assert File.file?('output2/index.html')
25
+ assert File.file?('output2/foo.html')
26
+ end
27
+ end
28
+
29
+ def test_run_with_yes
30
+ with_site do |site|
31
+ # Set output dir
32
+ File.open('config.yaml', 'w') { |io| io.write 'output_dir: output2' }
33
+ FileUtils.mkdir_p('output2')
34
+
35
+ # Create source files
36
+ File.open('content/index.html', 'w') { |io| io.write 'stuff' }
37
+
38
+ # Create output files
39
+ File.open('output2/foo.html', 'w') { |io| io.write 'this is a foo.' }
40
+ File.open('output2/index.html', 'w') { |io| io.write 'this is a index.' }
41
+
42
+ Nanoc::CLI.run %w( prune --yes )
43
+
44
+ assert File.file?('output2/index.html')
45
+ assert !File.file?('output2/foo.html')
46
+ end
47
+ end
48
+
49
+ def test_run_with_dry_run
50
+ with_site do |site|
51
+ # Set output dir
52
+ File.open('config.yaml', 'w') { |io| io.write 'output_dir: output2' }
53
+ FileUtils.mkdir_p('output2')
54
+
55
+ # Create source files
56
+ File.open('content/index.html', 'w') { |io| io.write 'stuff' }
57
+
58
+ # Create output files
59
+ File.open('output2/foo.html', 'w') { |io| io.write 'this is a foo.' }
60
+ File.open('output2/index.html', 'w') { |io| io.write 'this is a index.' }
61
+
62
+ Nanoc::CLI.run %w( prune --dry-run )
63
+
64
+ assert File.file?('output2/index.html')
65
+ assert File.file?('output2/foo.html')
66
+ end
67
+ end
68
+
69
+ def test_run_with_exclude
70
+ with_site do |site|
71
+ # Set output dir
72
+ File.open('config.yaml', 'w') { |io| io.write "prune:\n exclude: [ 'good-dir', 'good-file.html' ]" }
73
+ FileUtils.mkdir_p('output')
74
+
75
+ # Create source files
76
+ File.open('content/index.html', 'w') { |io| io.write 'stuff' }
77
+
78
+ # Create output files
79
+ FileUtils.mkdir_p('output/good-dir')
80
+ FileUtils.mkdir_p('output/bad-dir')
81
+ File.open('output/good-file.html', 'w') { |io| io.write 'stuff' }
82
+ File.open('output/good-dir/blah', 'w') { |io| io.write 'stuff' }
83
+ File.open('output/bad-file.html', 'w') { |io| io.write 'stuff' }
84
+ File.open('output/bad-dir/blah', 'w') { |io| io.write 'stuff' }
85
+ File.open('output/index.html', 'w') { |io| io.write 'stuff' }
86
+
87
+ Nanoc::CLI.run %w( prune --yes )
88
+
89
+ assert File.file?('output/index.html')
90
+ assert File.file?('output/good-dir/blah')
91
+ assert File.file?('output/good-file.html')
92
+ assert !File.file?('output/bad-dir/blah')
93
+ assert !File.file?('output/bad-file.html')
94
+ end
95
+ end
96
+
97
+ end
98
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::Commands::UpdateTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_stub
8
+ end
9
+
10
+ end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLITest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ COMMAND_CODE = <<EOS
8
+ # encoding: utf-8
9
+
10
+ usage '_test [options]'
11
+ summary 'meh'
12
+ description 'longer meh'
13
+
14
+ run do |opts, args, cmd|
15
+ File.open('_test.out', 'w') { |io| io.write('It works!') }
16
+ end
17
+ EOS
18
+
19
+ SUBCOMMAND_CODE = <<EOS
20
+ # encoding: utf-8
21
+
22
+ usage '_sub [options]'
23
+ summary 'meh sub'
24
+ description 'longer meh sub'
25
+
26
+ run do |opts, args, cmd|
27
+ File.open('_test_sub.out', 'w') { |io| io.write('It works sub!') }
28
+ end
29
+ EOS
30
+
31
+ def test_load_custom_commands
32
+ Nanoc::CLI.run %w( create_site foo )
33
+
34
+ FileUtils.cd('foo') do
35
+ # Create command
36
+ FileUtils.mkdir_p('commands')
37
+ File.open('commands/_test.rb', 'w') { |io| io.write(COMMAND_CODE) }
38
+
39
+ # Run command
40
+ begin
41
+ Nanoc::CLI.run %w( _test )
42
+ rescue SystemExit
43
+ assert false, 'Running _test should not cause system exit'
44
+ end
45
+
46
+ # Check
47
+ assert File.file?('_test.out')
48
+ assert_equal 'It works!', File.read('_test.out')
49
+ end
50
+ end
51
+
52
+ def test_load_custom_commands_nested
53
+ Nanoc::CLI.run %w( create_site foo )
54
+ FileUtils.cd('foo') do
55
+ # Create command
56
+ FileUtils.mkdir_p('commands')
57
+ File.open('commands/_test.rb', 'w') do |io|
58
+ io.write(COMMAND_CODE)
59
+ end
60
+
61
+ # Create subcommand
62
+ FileUtils.mkdir_p('commands/_test')
63
+ File.open('commands/_test/_sub.rb', 'w') do |io|
64
+ io.write(SUBCOMMAND_CODE)
65
+ end
66
+
67
+ # Run command
68
+ begin
69
+ Nanoc::CLI.run %w( _test _sub )
70
+ rescue SystemExit
71
+ assert false, 'Running _test sub should not cause system exit'
72
+ end
73
+
74
+ # Check
75
+ assert File.file?('_test_sub.out')
76
+ assert_equal 'It works sub!', File.read('_test_sub.out')
77
+ end
78
+ end
79
+
80
+ def test_load_custom_commands_broken
81
+ Nanoc::CLI.run %w( create_site foo )
82
+
83
+ FileUtils.cd('foo') do
84
+ # Create command
85
+ FileUtils.mkdir_p('commands')
86
+ File.open('commands/_test.rb', 'w') { |io| io.write('raise "meh"') }
87
+
88
+ # Run command
89
+ position_before = $stderr.tell
90
+ assert_raises SystemExit do
91
+ Nanoc::CLI.run %w( _test )
92
+ end
93
+ position_after = $stderr.tell
94
+
95
+ # Check error output
96
+ stderr_addition = $stderr.string[position_before, position_after]
97
+ assert_match(/=== BACKTRACE:/, stderr_addition)
98
+ assert_match(/commands\/_test.rb/, stderr_addition)
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::ErrorHandlerTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_resolution_for_with_unknown_gem
8
+ error = LoadError.new('no such file to load -- afjlrestjlsgrshter')
9
+ assert_nil handler.send(:resolution_for, error)
10
+ end
11
+
12
+ def test_resolution_for_with_known_gem
13
+ $loud = true
14
+ error = LoadError.new('no such file to load -- kramdown')
15
+ assert_match /^Try installing /, handler.send(:resolution_for, error)
16
+ ensure
17
+ $loud = false
18
+ end
19
+
20
+ def test_resolution_for_with_not_load_error
21
+ error = RuntimeError.new('nuclear meltdown detected')
22
+ assert_nil handler.send(:resolution_for, error)
23
+ end
24
+
25
+ def handler
26
+ Nanoc::CLI::ErrorHandler.new
27
+ end
28
+
29
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CLI::LoggerTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_stub
8
+ end
9
+
10
+ end
@@ -0,0 +1,433 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::DataSources::FilesystemTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ class SampleFilesystemDataSource < Nanoc::DataSource
8
+ include Nanoc::DataSources::Filesystem
9
+ end
10
+
11
+ def test_setup
12
+ # Create data source
13
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
14
+
15
+ # Remove files to make sure they are recreated
16
+ FileUtils.rm_rf('content')
17
+ FileUtils.rm_rf('layouts/default')
18
+ FileUtils.rm_rf('lib')
19
+
20
+ # Mock VCS
21
+ vcs = mock
22
+ vcs.expects(:add).times(2) # One time for each directory
23
+ data_source.vcs = vcs
24
+
25
+ # Recreate files
26
+ data_source.setup
27
+
28
+ # Ensure essential files have been recreated
29
+ assert(File.directory?('content/'))
30
+ assert(File.directory?('layouts/'))
31
+
32
+ # Ensure no non-essential files have been recreated
33
+ assert(!File.file?('content/index.html'))
34
+ assert(!File.file?('layouts/default.html'))
35
+ refute(File.directory?('lib/'))
36
+ end
37
+
38
+ def test_items
39
+ # Create data source
40
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
41
+
42
+ # Check
43
+ data_source.expects(:load_objects).with('content', 'item', Nanoc::Item)
44
+ data_source.items
45
+ end
46
+
47
+ def test_layouts
48
+ # Create data source
49
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
50
+
51
+ # Check
52
+ data_source.expects(:load_objects).with('layouts', 'layout', Nanoc::Layout)
53
+ data_source.layouts
54
+ end
55
+
56
+ def test_create_item
57
+ # Create data source
58
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
59
+
60
+ # Check
61
+ data_source.expects(:create_object).with('content', 'the content', 'the attributes', 'the identifier', {})
62
+ data_source.create_item('the content', 'the attributes', 'the identifier')
63
+ end
64
+
65
+ def test_create_layout
66
+ # Create data source
67
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
68
+
69
+ # Check
70
+ data_source.expects(:create_object).with('layouts', 'the content', 'the attributes', 'the identifier', {})
71
+ data_source.create_layout('the content', 'the attributes', 'the identifier')
72
+ end
73
+
74
+ def test_all_split_files_in_allowing_periods_in_identifiers
75
+ # Create data source
76
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
77
+
78
+ # Write sample files
79
+ FileUtils.mkdir_p('foo')
80
+ %w( foo.html foo.yaml bar.entry.html foo/qux.yaml ).each do |filename|
81
+ File.open(filename, 'w') { |io| io.write('test') }
82
+ end
83
+
84
+ # Write stray files
85
+ %w( foo.html~ foo.yaml.orig bar.entry.html.bak ).each do |filename|
86
+ File.open(filename, 'w') { |io| io.write('test') }
87
+ end
88
+
89
+ # Get all files
90
+ output_expected = {
91
+ './foo' => [ 'yaml', 'html' ],
92
+ './bar.entry' => [ nil, 'html' ],
93
+ './foo/qux' => [ 'yaml', nil ]
94
+ }
95
+ output_actual = data_source.send :all_split_files_in, '.'
96
+
97
+ # Check
98
+ assert_equal output_expected, output_actual
99
+ end
100
+
101
+ def test_all_split_files_in_disallowing_periods_in_identifiers
102
+ # Create data source
103
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
104
+
105
+ # Write sample files
106
+ FileUtils.mkdir_p('foo')
107
+ %w( foo.html foo.yaml bar.html.erb foo/qux.yaml ).each do |filename|
108
+ File.open(filename, 'w') { |io| io.write('test') }
109
+ end
110
+
111
+ # Write stray files
112
+ %w( foo.html~ foo.yaml.orig bar.entry.html.bak ).each do |filename|
113
+ File.open(filename, 'w') { |io| io.write('test') }
114
+ end
115
+
116
+ # Get all files
117
+ output_expected = {
118
+ './foo' => [ 'yaml', 'html' ],
119
+ './bar' => [ nil, 'html.erb' ],
120
+ './foo/qux' => [ 'yaml', nil ]
121
+ }
122
+ output_actual = data_source.send :all_split_files_in, '.'
123
+
124
+ # Check
125
+ assert_equal output_expected, output_actual
126
+ end
127
+
128
+ def test_all_split_files_in_with_multiple_dirs
129
+ # Create data source
130
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
131
+
132
+ # Write sample files
133
+ %w( aaa/foo.html bbb/foo.html ccc/foo.html ).each do |filename|
134
+ FileUtils.mkdir_p(File.dirname(filename))
135
+ File.open(filename, 'w') { |io| io.write('test') }
136
+ end
137
+
138
+ # Check
139
+ expected = {
140
+ './aaa/foo' => [ nil, 'html' ],
141
+ './bbb/foo' => [ nil, 'html' ],
142
+ './ccc/foo' => [ nil, 'html' ]
143
+ }
144
+ assert_equal expected, data_source.send(:all_split_files_in, '.')
145
+ end
146
+
147
+ def test_all_split_files_in_with_multiple_content_files
148
+ # Create data source
149
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
150
+
151
+ # Write sample files
152
+ %w( foo.html foo.xhtml foo.txt foo.yaml bar.html qux.yaml ).each do |filename|
153
+ File.open(filename, 'w') { |io| io.write('test') }
154
+ end
155
+
156
+ # Check
157
+ assert_raises RuntimeError do
158
+ data_source.send(:all_split_files_in, '.')
159
+ end
160
+ end
161
+
162
+ def test_basename_of_allowing_periods_in_identifiers
163
+ # Create data source
164
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
165
+
166
+ # Get input and expected output
167
+ expected = {
168
+ '/' => '/',
169
+ '/foo' => '/foo',
170
+ '/foo.html' => '/foo',
171
+ '/foo.xyz.html' => '/foo.xyz',
172
+ '/foo/' => '/foo/',
173
+ '/foo.xyz/' => '/foo.xyz/',
174
+ '/foo/bar' => '/foo/bar',
175
+ '/foo/bar.html' => '/foo/bar',
176
+ '/foo/bar.xyz.html' => '/foo/bar.xyz',
177
+ '/foo/bar/' => '/foo/bar/',
178
+ '/foo/bar.xyz/' => '/foo/bar.xyz/',
179
+ '/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/'
180
+ }
181
+
182
+ # Check
183
+ expected.each_pair do |input, expected_output|
184
+ actual_output = data_source.send(:basename_of, input)
185
+ assert_equal(
186
+ expected_output, actual_output,
187
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
188
+ )
189
+ end
190
+ end
191
+
192
+ def test_basename_of_disallowing_periods_in_identifiers
193
+ # Create data source
194
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
195
+
196
+ # Get input and expected output
197
+ expected = {
198
+ '/' => '/',
199
+ '/foo' => '/foo',
200
+ '/foo.html' => '/foo',
201
+ '/foo.xyz.html' => '/foo',
202
+ '/foo/' => '/foo/',
203
+ '/foo.xyz/' => '/foo.xyz/',
204
+ '/foo/bar' => '/foo/bar',
205
+ '/foo/bar.html' => '/foo/bar',
206
+ '/foo/bar.xyz.html' => '/foo/bar',
207
+ '/foo/bar/' => '/foo/bar/',
208
+ '/foo/bar.xyz/' => '/foo/bar.xyz/',
209
+ '/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/'
210
+ }
211
+
212
+ # Check
213
+ expected.each_pair do |input, expected_output|
214
+ actual_output = data_source.send(:basename_of, input)
215
+ assert_equal(
216
+ expected_output, actual_output,
217
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
218
+ )
219
+ end
220
+ end
221
+
222
+ def test_ext_of_allowing_periods_in_identifiers
223
+ # Create data source
224
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
225
+
226
+ # Get input and expected output
227
+ expected = {
228
+ '/' => '',
229
+ '/foo' => '',
230
+ '/foo.html' => '.html',
231
+ '/foo.xyz.html' => '.html',
232
+ '/foo/' => '',
233
+ '/foo.xyz/' => '',
234
+ '/foo/bar' => '',
235
+ '/foo/bar.html' => '.html',
236
+ '/foo/bar.xyz.html' => '.html',
237
+ '/foo/bar/' => '',
238
+ '/foo/bar.xyz/' => '',
239
+ '/foo.xyz/bar.xyz/' => ''
240
+ }
241
+
242
+ # Check
243
+ expected.each_pair do |input, expected_output|
244
+ actual_output = data_source.send(:ext_of, input)
245
+ assert_equal(
246
+ expected_output, actual_output,
247
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
248
+ )
249
+ end
250
+ end
251
+
252
+ def test_ext_of_disallowing_periods_in_identifiers
253
+ # Create data source
254
+ data_source = Nanoc::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
255
+
256
+ # Get input and expected output
257
+ expected = {
258
+ '/' => '',
259
+ '/foo' => '',
260
+ '/foo.html' => '.html',
261
+ '/foo.xyz.html' => '.xyz.html',
262
+ '/foo/' => '',
263
+ '/foo.xyz/' => '',
264
+ '/foo/bar' => '',
265
+ '/foo/bar.html' => '.html',
266
+ '/foo/bar.xyz.html' => '.xyz.html',
267
+ '/foo/bar/' => '',
268
+ '/foo/bar.xyz/' => '',
269
+ '/foo.xyz/bar.xyz/' => ''
270
+ }
271
+
272
+ # Check
273
+ expected.each_pair do |input, expected_output|
274
+ actual_output = data_source.send(:ext_of, input)
275
+ assert_equal(
276
+ expected_output, actual_output,
277
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
278
+ )
279
+ end
280
+ end
281
+
282
+ def test_parse_embedded_invalid_2
283
+ # Create a file
284
+ File.open('test.html', 'w') do |io|
285
+ io.write "-----\n"
286
+ io.write "blah blah\n"
287
+ end
288
+
289
+ # Create data source
290
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
291
+
292
+ # Parse it
293
+ assert_raises(RuntimeError) do
294
+ data_source.instance_eval { parse('test.html', nil, 'foobar') }
295
+ end
296
+ end
297
+
298
+ def test_parse_embedded_separators_but_not_metadata
299
+ # Create a file
300
+ File.open('test.html', 'w') do |io|
301
+ io.write "blah blah\n"
302
+ io.write "-----\n"
303
+ io.write "blah blah\n"
304
+ end
305
+
306
+ # Create data source
307
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
308
+
309
+ # Parse it
310
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
311
+ assert_equal(File.read('test.html'), result[1])
312
+ assert_equal({}, result[0])
313
+ end
314
+
315
+ def test_parse_embedded_full_meta
316
+ # Create a file
317
+ File.open('test.html', 'w') do |io|
318
+ io.write "-----\n"
319
+ io.write "foo: bar\n"
320
+ io.write "-----\n"
321
+ io.write "blah blah\n"
322
+ end
323
+
324
+ # Create data source
325
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
326
+
327
+ # Parse it
328
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
329
+ assert_equal({ 'foo' => 'bar' }, result[0])
330
+ assert_equal('blah blah', result[1])
331
+ end
332
+
333
+ def test_parse_embedded_with_extra_spaces
334
+ # Create a file
335
+ File.open('test.html', 'w') do |io|
336
+ io.write "----- \n"
337
+ io.write "foo: bar\n"
338
+ io.write "-----\t\t\t\t\t\n"
339
+ io.write "blah blah\n"
340
+ end
341
+
342
+ # Create data source
343
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
344
+
345
+ # Parse it
346
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
347
+ assert_equal({ 'foo' => 'bar' }, result[0])
348
+ assert_equal('blah blah', result[1])
349
+ end
350
+
351
+ def test_parse_embedded_empty_meta
352
+ # Create a file
353
+ File.open('test.html', 'w') do |io|
354
+ io.write "-----\n"
355
+ io.write "-----\n"
356
+ io.write "blah blah\n"
357
+ end
358
+
359
+ # Create data source
360
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
361
+
362
+ # Parse it
363
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
364
+ assert_equal({}, result[0])
365
+ assert_equal('blah blah', result[1])
366
+ end
367
+
368
+ def test_parse_utf8_bom
369
+ File.open('test.html', 'w') do |io|
370
+ io.write [ 0xEF, 0xBB, 0xBF ].map { |i| i.chr }.join
371
+ io.write "-----\n"
372
+ io.write "utf8bomawareness: high\n"
373
+ io.write "-----\n"
374
+ io.write "content goes here\n"
375
+ end
376
+
377
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
378
+
379
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
380
+ assert_equal({ 'utf8bomawareness' => 'high' }, result[0])
381
+ assert_equal('content goes here', result[1])
382
+ end
383
+
384
+ def test_parse_embedded_no_meta
385
+ content = "blah\n" \
386
+ "blah blah blah\n" \
387
+ "blah blah\n"
388
+
389
+ # Create a file
390
+ File.open('test.html', 'w') { |io| io.write(content) }
391
+
392
+ # Create data source
393
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
394
+
395
+ # Parse it
396
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
397
+ assert_equal({}, result[0])
398
+ assert_equal(content, result[1])
399
+ end
400
+
401
+ def test_parse_embedded_diff
402
+ content = \
403
+ "--- a/foo\n" \
404
+ "+++ b/foo\n" \
405
+ "blah blah\n"
406
+
407
+ # Create a file
408
+ File.open('test.html', 'w') { |io| io.write(content) }
409
+
410
+ # Create data source
411
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
412
+
413
+ # Parse it
414
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
415
+ assert_equal({}, result[0])
416
+ assert_equal(content, result[1])
417
+ end
418
+
419
+ def test_parse_external
420
+ # Create a file
421
+ File.open('test.html', 'w') { |io| io.write("blah blah") }
422
+ File.open('test.yaml', 'w') { |io| io.write("foo: bar") }
423
+
424
+ # Create data source
425
+ data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
426
+
427
+ # Parse it
428
+ result = data_source.instance_eval { parse('test.html', 'test.yaml', 'foobar') }
429
+ assert_equal({ "foo" => "bar"}, result[0])
430
+ assert_equal("blah blah", result[1])
431
+ end
432
+
433
+ end