nanoc 4.4.5 → 4.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -2
  3. data/Gemfile.lock +37 -18
  4. data/NEWS.md +6 -0
  5. data/Rakefile +8 -20
  6. data/lib/nanoc/base/entities/code_snippet.rb +0 -2
  7. data/lib/nanoc/base/entities/item_rep.rb +4 -22
  8. data/lib/nanoc/base/entities/processing_actions/snapshot.rb +9 -7
  9. data/lib/nanoc/base/entities/rule_memory.rb +15 -7
  10. data/lib/nanoc/base/entities/snapshot_def.rb +2 -8
  11. data/lib/nanoc/base/repos/store.rb +2 -28
  12. data/lib/nanoc/base/services/checksummer.rb +9 -10
  13. data/lib/nanoc/base/services/compiler.rb +14 -16
  14. data/lib/nanoc/base/services/executor.rb +2 -13
  15. data/lib/nanoc/base/views/mixins/with_reps_view_mixin.rb +1 -1
  16. data/lib/nanoc/checking/checks/external_links.rb +2 -1
  17. data/lib/nanoc/cli/commands/compile.rb +8 -14
  18. data/lib/nanoc/extra/parallel_collection.rb +57 -0
  19. data/lib/nanoc/extra.rb +1 -0
  20. data/lib/nanoc/filters/mustache.rb +1 -1
  21. data/lib/nanoc/rule_dsl/recording_executor.rb +6 -34
  22. data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +42 -12
  23. data/lib/nanoc/spec.rb +1 -1
  24. data/lib/nanoc/version.rb +1 -1
  25. data/nanoc.gemspec +1 -2
  26. data/spec/contributors_spec.rb +18 -0
  27. data/spec/nanoc/base/checksummer_spec.rb +381 -0
  28. data/spec/nanoc/base/compiler_spec.rb +181 -0
  29. data/spec/nanoc/base/entities/configuration_spec.rb +49 -0
  30. data/spec/nanoc/base/entities/content_spec.rb +193 -0
  31. data/spec/nanoc/base/entities/document_spec.rb +206 -0
  32. data/spec/nanoc/base/entities/identifier_spec.rb +460 -0
  33. data/spec/nanoc/base/entities/item_rep_spec.rb +226 -0
  34. data/spec/nanoc/base/entities/item_spec.rb +3 -0
  35. data/spec/nanoc/base/entities/layout_spec.rb +3 -0
  36. data/spec/nanoc/base/entities/lazy_value_spec.rb +106 -0
  37. data/spec/nanoc/base/entities/outdatedness_status_spec.rb +113 -0
  38. data/spec/nanoc/base/entities/pattern_spec.rb +125 -0
  39. data/spec/nanoc/base/entities/processing_action_spec.rb +9 -0
  40. data/spec/nanoc/base/entities/processing_actions/filter_spec.rb +18 -0
  41. data/spec/nanoc/base/entities/processing_actions/layout_spec.rb +18 -0
  42. data/spec/nanoc/base/entities/processing_actions/snapshot_spec.rb +32 -0
  43. data/spec/nanoc/base/entities/props_spec.rb +195 -0
  44. data/spec/nanoc/base/entities/rule_memory_spec.rb +131 -0
  45. data/spec/nanoc/base/entities/site_spec.rb +73 -0
  46. data/spec/nanoc/base/feature_spec.rb +107 -0
  47. data/spec/nanoc/base/filter_spec.rb +99 -0
  48. data/spec/nanoc/base/item_rep_writer_spec.rb +131 -0
  49. data/spec/nanoc/base/plugin_registry_spec.rb +29 -0
  50. data/spec/nanoc/base/repos/checksum_store_spec.rb +133 -0
  51. data/spec/nanoc/base/repos/compiled_content_cache_spec.rb +55 -0
  52. data/spec/nanoc/base/repos/config_loader_spec.rb +243 -0
  53. data/spec/nanoc/base/repos/dependency_store_spec.rb +195 -0
  54. data/spec/nanoc/base/repos/site_loader_spec.rb +214 -0
  55. data/spec/nanoc/base/services/dependency_tracker_spec.rb +238 -0
  56. data/spec/nanoc/base/services/executor_spec.rb +495 -0
  57. data/spec/nanoc/base/services/item_rep_router_spec.rb +134 -0
  58. data/spec/nanoc/base/services/item_rep_selector_spec.rb +169 -0
  59. data/spec/nanoc/base/services/outdatedness_checker_spec.rb +370 -0
  60. data/spec/nanoc/base/services/outdatedness_rules_spec.rb +432 -0
  61. data/spec/nanoc/base/services/pruner_spec.rb +105 -0
  62. data/spec/nanoc/base/services/temp_filename_factory_spec.rb +87 -0
  63. data/spec/nanoc/base/views/config_view_spec.rb +96 -0
  64. data/spec/nanoc/base/views/document_view_spec.rb +332 -0
  65. data/spec/nanoc/base/views/identifiable_collection_view_spec.rb +190 -0
  66. data/spec/nanoc/base/views/item_collection_with_reps_view_spec.rb +18 -0
  67. data/spec/nanoc/base/views/item_collection_without_reps_view_spec.rb +18 -0
  68. data/spec/nanoc/base/views/item_rep_collection_view_spec.rb +143 -0
  69. data/spec/nanoc/base/views/item_rep_view_spec.rb +265 -0
  70. data/spec/nanoc/base/views/item_view_spec.rb +341 -0
  71. data/spec/nanoc/base/views/layout_collection_view_spec.rb +18 -0
  72. data/spec/nanoc/base/views/layout_view_spec.rb +14 -0
  73. data/spec/nanoc/base/views/mutable_config_view_spec.rb +16 -0
  74. data/spec/nanoc/base/views/mutable_document_view_spec.rb +92 -0
  75. data/spec/nanoc/base/views/mutable_identifiable_collection_view_spec.rb +36 -0
  76. data/spec/nanoc/base/views/mutable_item_collection_view_spec.rb +49 -0
  77. data/spec/nanoc/base/views/mutable_item_view_spec.rb +22 -0
  78. data/spec/nanoc/base/views/mutable_layout_collection_view_spec.rb +49 -0
  79. data/spec/nanoc/base/views/mutable_layout_view_spec.rb +13 -0
  80. data/spec/nanoc/base/views/post_compile_item_rep_collection_view_spec.rb +4 -0
  81. data/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +137 -0
  82. data/spec/nanoc/base/views/post_compile_item_view_spec.rb +56 -0
  83. data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +76 -0
  84. data/spec/nanoc/cli/commands/compile/timing_recorder_spec.rb +66 -0
  85. data/spec/nanoc/cli/commands/compile_spec.rb +64 -0
  86. data/spec/nanoc/cli/commands/deploy_spec.rb +327 -0
  87. data/spec/nanoc/cli/commands/shell_spec.rb +54 -0
  88. data/spec/nanoc/cli/commands/show_data_spec.rb +126 -0
  89. data/spec/nanoc/cli/commands/show_rules_spec.rb +112 -0
  90. data/spec/nanoc/cli/commands/view_spec.rb +58 -0
  91. data/spec/nanoc/data_sources/filesystem_spec.rb +56 -0
  92. data/spec/nanoc/deploying/fog_spec.rb +193 -0
  93. data/spec/nanoc/extra/parallel_collection_spec.rb +108 -0
  94. data/spec/nanoc/filters/colorize_syntax/rouge_spec.rb +195 -0
  95. data/spec/nanoc/filters/less_spec.rb +120 -0
  96. data/spec/nanoc/helpers/blogging_spec.rb +216 -0
  97. data/spec/nanoc/helpers/breadcrumbs_spec.rb +133 -0
  98. data/spec/nanoc/helpers/capturing_spec.rb +181 -0
  99. data/spec/nanoc/helpers/child_parent_spec.rb +105 -0
  100. data/spec/nanoc/helpers/filtering_spec.rb +72 -0
  101. data/spec/nanoc/helpers/html_escape_spec.rb +35 -0
  102. data/spec/nanoc/helpers/link_to_spec.rb +275 -0
  103. data/spec/nanoc/helpers/rendering_spec.rb +141 -0
  104. data/spec/nanoc/helpers/tagging_spec.rb +104 -0
  105. data/spec/nanoc/helpers/text_spec.rb +58 -0
  106. data/spec/nanoc/integration/outdatedness_integration_spec.rb +208 -0
  107. data/spec/nanoc/regressions/gh_1015_spec.rb +17 -0
  108. data/spec/nanoc/regressions/gh_1031_spec.rb +54 -0
  109. data/spec/nanoc/regressions/gh_1035_spec.rb +33 -0
  110. data/spec/nanoc/regressions/gh_1040_spec.rb +22 -0
  111. data/spec/nanoc/regressions/gh_761_spec.rb +23 -0
  112. data/spec/nanoc/regressions/gh_767_spec.rb +19 -0
  113. data/spec/nanoc/regressions/gh_769_spec.rb +30 -0
  114. data/spec/nanoc/regressions/gh_776_spec.rb +43 -0
  115. data/spec/nanoc/regressions/gh_787_spec.rb +19 -0
  116. data/spec/nanoc/regressions/gh_795_spec.rb +19 -0
  117. data/spec/nanoc/regressions/gh_804_spec.rb +26 -0
  118. data/spec/nanoc/regressions/gh_807_spec.rb +17 -0
  119. data/spec/nanoc/regressions/gh_809_spec.rb +17 -0
  120. data/spec/nanoc/regressions/gh_813_spec.rb +22 -0
  121. data/spec/nanoc/regressions/gh_815_spec.rb +18 -0
  122. data/spec/nanoc/regressions/gh_828_spec.rb +23 -0
  123. data/spec/nanoc/regressions/gh_833_spec.rb +14 -0
  124. data/spec/nanoc/regressions/gh_841_spec.rb +15 -0
  125. data/spec/nanoc/regressions/gh_867_spec.rb +15 -0
  126. data/spec/nanoc/regressions/gh_882_spec.rb +29 -0
  127. data/spec/nanoc/regressions/gh_885_spec.rb +30 -0
  128. data/spec/nanoc/regressions/gh_891_spec.rb +26 -0
  129. data/spec/nanoc/regressions/gh_913_spec.rb +24 -0
  130. data/spec/nanoc/regressions/gh_928_spec.rb +5 -0
  131. data/spec/nanoc/regressions/gh_937_spec.rb +25 -0
  132. data/spec/nanoc/regressions/gh_942_spec.rb +21 -0
  133. data/spec/nanoc/regressions/gh_947_spec.rb +21 -0
  134. data/spec/nanoc/regressions/gh_948_spec.rb +16 -0
  135. data/spec/nanoc/regressions/gh_951_spec.rb +19 -0
  136. data/spec/nanoc/regressions/gh_954_spec.rb +33 -0
  137. data/spec/nanoc/regressions/gh_970a_spec.rb +17 -0
  138. data/spec/nanoc/regressions/gh_970b_spec.rb +50 -0
  139. data/spec/nanoc/regressions/gh_974_spec.rb +17 -0
  140. data/spec/nanoc/regressions/gh_981_spec.rb +21 -0
  141. data/spec/nanoc/rule_dsl/recording_executor_spec.rb +142 -0
  142. data/spec/nanoc/rule_dsl/rule_context_spec.rb +177 -0
  143. data/spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb +233 -0
  144. data/spec/nanoc/rule_dsl/rules_collection_spec.rb +299 -0
  145. data/spec/regression_filenames_spec.rb +16 -0
  146. data/spec/spec_helper.rb +173 -0
  147. data/test/base/core_ext/array_spec.rb +2 -0
  148. data/test/base/core_ext/hash_spec.rb +2 -0
  149. data/test/base/core_ext/string_spec.rb +2 -0
  150. data/test/base/test_code_snippet.rb +2 -0
  151. data/test/base/test_compiler.rb +2 -0
  152. data/test/base/test_context.rb +4 -2
  153. data/test/base/test_data_source.rb +2 -0
  154. data/test/base/test_dependency_tracker.rb +2 -0
  155. data/test/base/test_directed_graph.rb +2 -0
  156. data/test/base/test_filter.rb +7 -5
  157. data/test/base/test_item.rb +2 -0
  158. data/test/base/test_item_array.rb +3 -1
  159. data/test/base/test_layout.rb +2 -0
  160. data/test/base/test_memoization.rb +2 -0
  161. data/test/base/test_notification_center.rb +2 -0
  162. data/test/base/test_outdatedness_checker.rb +2 -0
  163. data/test/base/test_plugin.rb +2 -0
  164. data/test/base/test_site.rb +2 -0
  165. data/test/base/test_store.rb +2 -0
  166. data/test/checking/checks/test_css.rb +2 -0
  167. data/test/checking/checks/test_external_links.rb +4 -2
  168. data/test/checking/checks/test_html.rb +2 -0
  169. data/test/checking/checks/test_internal_links.rb +5 -3
  170. data/test/checking/checks/test_mixed_content.rb +2 -0
  171. data/test/checking/checks/test_stale.rb +2 -0
  172. data/test/checking/test_check.rb +2 -0
  173. data/test/checking/test_dsl.rb +2 -0
  174. data/test/checking/test_runner.rb +2 -0
  175. data/test/cli/commands/test_check.rb +2 -0
  176. data/test/cli/commands/test_compile.rb +2 -0
  177. data/test/cli/commands/test_create_site.rb +2 -0
  178. data/test/cli/commands/test_help.rb +2 -0
  179. data/test/cli/commands/test_info.rb +2 -0
  180. data/test/cli/commands/test_prune.rb +2 -0
  181. data/test/cli/test_cleaning_stream.rb +2 -0
  182. data/test/cli/test_cli.rb +11 -9
  183. data/test/cli/test_error_handler.rb +2 -0
  184. data/test/cli/test_logger.rb +2 -0
  185. data/test/data_sources/test_filesystem.rb +8 -6
  186. data/test/data_sources/test_filesystem_tools.rb +2 -0
  187. data/test/deploying/test_fog.rb +2 -0
  188. data/test/deploying/test_rsync.rb +4 -2
  189. data/test/extra/core_ext/test_pathname.rb +2 -0
  190. data/test/extra/core_ext/test_time.rb +2 -0
  191. data/test/extra/test_link_collector.rb +2 -0
  192. data/test/extra/test_piper.rb +2 -0
  193. data/test/filters/colorize_syntax/test_coderay.rb +2 -0
  194. data/test/filters/colorize_syntax/test_common.rb +2 -0
  195. data/test/filters/colorize_syntax/test_pygmentize.rb +2 -0
  196. data/test/filters/colorize_syntax/test_pygments.rb +2 -0
  197. data/test/filters/colorize_syntax/test_simon.rb +2 -0
  198. data/test/filters/test_asciidoc.rb +2 -0
  199. data/test/filters/test_bluecloth.rb +2 -0
  200. data/test/filters/test_coffeescript.rb +2 -0
  201. data/test/filters/test_erb.rb +7 -5
  202. data/test/filters/test_erubis.rb +6 -4
  203. data/test/filters/test_haml.rb +7 -5
  204. data/test/filters/test_handlebars.rb +2 -0
  205. data/test/filters/test_kramdown.rb +2 -0
  206. data/test/filters/test_markaby.rb +2 -0
  207. data/test/filters/test_maruku.rb +2 -0
  208. data/test/filters/test_mustache.rb +4 -2
  209. data/test/filters/test_pandoc.rb +2 -0
  210. data/test/filters/test_rainpress.rb +2 -0
  211. data/test/filters/test_rdiscount.rb +2 -0
  212. data/test/filters/test_rdoc.rb +2 -0
  213. data/test/filters/test_redcarpet.rb +2 -0
  214. data/test/filters/test_redcloth.rb +2 -0
  215. data/test/filters/test_relativize_paths.rb +2 -0
  216. data/test/filters/test_rubypants.rb +2 -0
  217. data/test/filters/test_sass.rb +4 -2
  218. data/test/filters/test_slim.rb +4 -2
  219. data/test/filters/test_typogruby.rb +2 -0
  220. data/test/filters/test_uglify_js.rb +2 -0
  221. data/test/filters/test_xsl.rb +2 -0
  222. data/test/filters/test_yui_compressor.rb +5 -3
  223. data/test/helpers/test_blogging.rb +2 -0
  224. data/test/helpers/test_capturing.rb +2 -0
  225. data/test/helpers/test_link_to.rb +2 -0
  226. data/test/helpers/test_xml_sitemap.rb +2 -0
  227. data/test/rule_dsl/test_action_provider.rb +2 -0
  228. data/test/rule_dsl/test_compiler_dsl.rb +6 -4
  229. data/test/rule_dsl/test_rule.rb +2 -0
  230. data/test/rule_dsl/test_rules_collection.rb +2 -0
  231. data/test/test_gem.rb +2 -0
  232. metadata +124 -17
  233. data/test/base/test_item_rep.rb +0 -156
@@ -0,0 +1,29 @@
1
+ describe 'GH-882', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'I am foo!')
4
+ File.write('content/bar.md', 'I am bar!')
5
+
6
+ File.write('Rules', <<EOS)
7
+ compile '/**/*' do
8
+ write item.identifier.without_ext + '.html'
9
+ end
10
+
11
+ postprocess do
12
+ modified_reps = items.flat_map(&:modified)
13
+ modified_reps.each do |rep|
14
+ puts "Modified: \#{rep.item.identifier} - \#{rep.name}"
15
+ end
16
+ end
17
+ EOS
18
+ end
19
+
20
+ example do
21
+ Nanoc::CLI.run(%w(compile))
22
+
23
+ File.write('content/bar.md', 'I am bar! Modified!')
24
+ expect { Nanoc::CLI.run(%w(compile)) }.to output(%r{^Modified: /bar.md - default$}).to_stdout
25
+
26
+ File.write('content/bar.md', 'I am bar! Modified again!')
27
+ expect { Nanoc::CLI.run(%w(compile)) }.not_to output(%r{^Modified: /foo.md - default$}).to_stdout
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ describe 'GH-885', site: true, stdio: true do
2
+ before do
3
+ File.write(
4
+ 'content/index.html',
5
+ "<%= @items['/hello.*'].compiled_content %> - <%= Time.now.to_f %>",
6
+ )
7
+
8
+ File.write('Rules', <<EOS)
9
+ preprocess do
10
+ items.create('hi!', {}, '/hello.html')
11
+ end
12
+
13
+ compile '/**/*' do
14
+ filter :erb
15
+ write item.identifier.without_ext + '.html'
16
+ end
17
+ EOS
18
+ end
19
+
20
+ example do
21
+ Nanoc::CLI.run(%w(compile))
22
+ before = File.read('output/index.html')
23
+
24
+ sleep(0.1)
25
+ Nanoc::CLI.run(%w(compile))
26
+ after = File.read('output/index.html')
27
+ expect(after).to eql(before)
28
+ expect(after).to match(/\Ahi! - \d+/)
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ describe 'GH-891', site: true, stdio: true do
2
+ before do
3
+ File.write('layouts/foo.erb', 'giraffes? <%= yield %>')
4
+ File.write('Rules', <<EOS)
5
+ preprocess do
6
+ items.create('yes!', {}, '/hello.html')
7
+ end
8
+
9
+ compile '/**/*' do
10
+ layout '/foo.*'
11
+ write item.identifier.without_ext + '.html'
12
+ end
13
+
14
+ layout '/foo.*', :erb
15
+ EOS
16
+ end
17
+
18
+ example do
19
+ Nanoc::CLI.run(%w(compile))
20
+ expect(File.read('output/hello.html')).to include('giraffes?')
21
+
22
+ File.write('layouts/foo.erb', 'donkeys? <%= yield %>')
23
+ Nanoc::CLI.run(%w(compile))
24
+ expect(File.read('output/hello.html')).to include('donkeys?')
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ describe 'GH-913', site: true, stdio: true do
2
+ before do
3
+ File.write('content/hello.html', 'hi!')
4
+
5
+ File.write('Rules', <<EOS)
6
+ postprocess do
7
+ items.map(&:compiled_content)
8
+ end
9
+
10
+ compile '/**/*' do
11
+ write item.identifier.without_ext + '.html'
12
+ end
13
+
14
+ layout '/foo.*', :erb
15
+ EOS
16
+ end
17
+
18
+ example do
19
+ 2.times do
20
+ Nanoc::CLI.run(%w(compile))
21
+ expect(File.read('output/hello.html')).to eq('hi!')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ describe 'GH-928', site: true, stdio: true do
2
+ example do
3
+ expect { Nanoc::CLI.run(%w(check --list)) }.to output(%r{^ css$}).to_stdout
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ describe 'GH-937', site: true, stdio: true do
2
+ before do
3
+ File.write('content/style.sass', ".test\n color: red")
4
+
5
+ File.write(
6
+ 'nanoc.yaml',
7
+ "sass_style: compact\nenvironments:\n staging:\n sass_style: expanded",
8
+ )
9
+
10
+ File.write('Rules', <<EOS)
11
+ compile '/*.sass' do
12
+ filter :sass, style: @config[:sass_style].to_sym
13
+ write item.identifier.without_ext + '.css'
14
+ end
15
+ EOS
16
+ end
17
+
18
+ it 'does not use cache when switching environments' do
19
+ Nanoc::CLI.run(%w(compile))
20
+ expect(File.read('output/style.css')).to eq(".test { color: red; }\n")
21
+
22
+ Nanoc::CLI.run(%w(compile --env=staging))
23
+ expect(File.read('output/style.css')).to eq(".test {\n color: red;\n}\n")
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ describe 'GH-942', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'Foo!')
4
+ File.write('Rules', <<EOS)
5
+ compile '/foo.*' do
6
+ write '/parent/foo'
7
+ end
8
+ EOS
9
+
10
+ File.open('nanoc.yaml', 'w') do |io|
11
+ io << 'prune:' << "\n"
12
+ io << ' auto_prune: true' << "\n"
13
+ end
14
+ end
15
+
16
+ example do
17
+ File.write('output/parent', 'Hahaaa! I am a file and not a directory!')
18
+ Nanoc::CLI.run(%w(compile))
19
+ expect(File.read('output/parent/foo')).to eq('Foo!')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ describe 'GH-947', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'Foo!')
4
+ File.write('Rules', <<EOS)
5
+ compile '/foo.*' do
6
+ write '/foo'
7
+ end
8
+ EOS
9
+
10
+ File.open('nanoc.yaml', 'w') do |io|
11
+ io << 'prune:' << "\n"
12
+ io << ' auto_prune: true' << "\n"
13
+ end
14
+ end
15
+
16
+ example do
17
+ File.write('output/foo', 'I am an older foo!')
18
+ expect { Nanoc::CLI.run(%w(compile)) }.to output(%r{\s+update.* output/foo$}).to_stdout
19
+ expect(File.read('output/foo')).to eq('Foo!')
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ describe 'GH-948', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'Foo!')
4
+
5
+ File.open('nanoc.yaml', 'w') do |io|
6
+ io << 'prune:' << "\n"
7
+ io << ' auto_prune: true' << "\n"
8
+ end
9
+
10
+ FileUtils.rm_rf('output')
11
+ end
12
+
13
+ it 'does not crash when output dir is not present' do
14
+ Nanoc::CLI.run(%w(compile))
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ describe 'GH-951', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'Foo!')
4
+
5
+ File.open('nanoc.yaml', 'w') do |io|
6
+ io << 'string_pattern_type: legacy' << "\n"
7
+ end
8
+
9
+ File.write('Rules', <<EOS)
10
+ passthrough '/foo.md'
11
+ EOS
12
+ end
13
+
14
+ it 'copies foo.md' do
15
+ Nanoc::CLI.run(%w(compile))
16
+
17
+ expect(File.file?('output/foo.md')).to eq(true)
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ describe 'GH-954', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'foo <a href="/">root</a>')
4
+ File.write('content/bar.md', 'bar <a href="/">root</a>')
5
+ File.write('content/bar-copy.md', '<%= @items["/bar.*"].compiled_content(snapshot: :last) %>')
6
+
7
+ File.write('Rules', <<EOS)
8
+ compile '/foo.*' do
9
+ filter :relativize_paths, type: :html unless rep.path.nil?
10
+ write item.identifier.without_ext + '.html'
11
+ end
12
+
13
+ compile '/bar.*' do
14
+ filter :relativize_paths, type: :html unless rep.path.nil?
15
+ end
16
+
17
+ compile '/bar-copy.*' do
18
+ filter :erb
19
+ write item.identifier.without_ext + '.html'
20
+ end
21
+ EOS
22
+ end
23
+
24
+ it 'properly filters foo.md' do
25
+ Nanoc::CLI.run(%w(compile))
26
+
27
+ # Path is relativized
28
+ expect(File.read('output/foo.html')).to eq('foo <a href="./">root</a>')
29
+
30
+ # Path is not relativized
31
+ expect(File.read('output/bar-copy.html')).to eq('bar <a href="/">root</a>')
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ describe 'GH-970 (show-rules)', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'foo')
4
+
5
+ File.write('Rules', <<EOS)
6
+ compile '/foo.*' do
7
+ write '/donkey.html'
8
+ end
9
+ EOS
10
+ end
11
+
12
+ it 'shows reps' do
13
+ expect { Nanoc::CLI.run(%w(show-rules --no-color)) }.to(
14
+ output(/^Item \/foo\.md:\n Rep default: \/foo\.\*$/).to_stdout,
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ describe 'GH-970 (show-data)', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'foo')
4
+ File.write('content/bar.md', '<%= @items["/foo.*"].compiled_content %>')
5
+
6
+ File.write('Rules', <<EOS)
7
+ compile '/foo.*' do
8
+ write '/foo.html'
9
+ end
10
+
11
+ compile '/bar.*' do
12
+ filter :erb
13
+ write '/bar.html'
14
+ end
15
+ EOS
16
+ end
17
+
18
+ before { Nanoc::CLI.run(%w(compile)) }
19
+
20
+ it 'shows default rep outdatedness' do
21
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
22
+ output(/^item \/foo\.md, rep default:\n is not outdated/).to_stdout,
23
+ )
24
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
25
+ output(/^item \/bar\.md, rep default:\n is not outdated/).to_stdout,
26
+ )
27
+ end
28
+
29
+ it 'shows file as outdated after modification' do
30
+ File.write('content/bar.md', 'JUST BAR!')
31
+
32
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
33
+ output(/^item \/foo\.md, rep default:\n is not outdated/).to_stdout,
34
+ )
35
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
36
+ output(/^item \/bar\.md, rep default:\n is outdated: /).to_stdout,
37
+ )
38
+ end
39
+
40
+ it 'shows file and dependencies as outdated after modification' do
41
+ File.write('content/foo.md', 'FOO!')
42
+
43
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
44
+ output(/^item \/foo\.md, rep default:\n is outdated: /).to_stdout,
45
+ )
46
+ expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
47
+ output(/^item \/bar\.md, rep default:\n is outdated: /).to_stdout,
48
+ )
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ describe 'GH-974', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'foo')
4
+
5
+ File.write('Rules', <<EOS)
6
+ compile '/foo.*' do
7
+ write item.identifier
8
+ end
9
+ EOS
10
+ end
11
+
12
+ it 'writes to path corresponding to identifier' do
13
+ Nanoc::CLI.run(%w(compile))
14
+
15
+ expect(File.file?('output/foo.md')).to eq(true)
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ describe 'GH-981', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.md', 'I am foo!')
4
+
5
+ File.write('Rules', <<EOS)
6
+ compile '/foo.*' do
7
+ filter :erb, stuff: self
8
+ write '/foo.html'
9
+ end
10
+ EOS
11
+ end
12
+
13
+ it 'creates at first' do
14
+ expect { Nanoc::CLI.run(%w(compile --verbose)) }.to output(%r{create.*output/foo\.html$}).to_stdout
15
+ end
16
+
17
+ it 'skips the item on second try' do
18
+ Nanoc::CLI.run(%w(compile))
19
+ expect { Nanoc::CLI.run(%w(compile --verbose)) }.to output(%r{skip.*output/foo\.html$}).to_stdout
20
+ end
21
+ end
@@ -0,0 +1,142 @@
1
+ describe Nanoc::RuleDSL::RecordingExecutor do
2
+ let(:executor) { described_class.new(rule_memory) }
3
+
4
+ let(:rule_memory) { Nanoc::Int::RuleMemory.new(rep) }
5
+ let(:rep) { double(:rep) }
6
+
7
+ describe '#filter' do
8
+ it 'records filter call without arguments' do
9
+ executor.filter(:erb)
10
+
11
+ expect(rule_memory.size).to eql(1)
12
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Filter)
13
+ expect(rule_memory[0].filter_name).to eql(:erb)
14
+ expect(rule_memory[0].params).to eql({})
15
+ end
16
+
17
+ it 'records filter call with arguments' do
18
+ executor.filter(:erb, x: 123)
19
+
20
+ expect(rule_memory.size).to eql(1)
21
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Filter)
22
+ expect(rule_memory[0].filter_name).to eql(:erb)
23
+ expect(rule_memory[0].params).to eql(x: 123)
24
+ end
25
+ end
26
+
27
+ describe '#layout' do
28
+ it 'records layout call without arguments' do
29
+ executor.layout('/default.*')
30
+
31
+ expect(rule_memory.size).to eql(2)
32
+
33
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
34
+ expect(rule_memory[0].snapshot_name).to eql(:pre)
35
+ expect(rule_memory[0].path).to be_nil
36
+
37
+ expect(rule_memory[1]).to be_a(Nanoc::Int::ProcessingActions::Layout)
38
+ expect(rule_memory[1].layout_identifier).to eql('/default.*')
39
+ expect(rule_memory[1].params).to eql({})
40
+ end
41
+
42
+ it 'records layout call with arguments' do
43
+ executor.layout('/default.*', donkey: 123)
44
+
45
+ expect(rule_memory.size).to eql(2)
46
+
47
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
48
+ expect(rule_memory[0].snapshot_name).to eql(:pre)
49
+ expect(rule_memory[0].path).to be_nil
50
+
51
+ expect(rule_memory[1]).to be_a(Nanoc::Int::ProcessingActions::Layout)
52
+ expect(rule_memory[1].layout_identifier).to eql('/default.*')
53
+ expect(rule_memory[1].params).to eql(donkey: 123)
54
+ end
55
+
56
+ it 'fails when passed a symbol' do
57
+ expect { executor.layout(:default, donkey: 123) }.to raise_error(ArgumentError)
58
+ end
59
+ end
60
+
61
+ describe '#snapshot' do
62
+ context 'snapshot already exists' do
63
+ before do
64
+ executor.snapshot(:foo)
65
+ end
66
+
67
+ it 'raises when creating same snapshot' do
68
+ expect { executor.snapshot(:foo) }
69
+ .to raise_error(Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName)
70
+ end
71
+ end
72
+
73
+ context 'no arguments' do
74
+ subject { executor.snapshot(:foo) }
75
+
76
+ it 'records' do
77
+ subject
78
+ expect(rule_memory.size).to eql(1)
79
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
80
+ expect(rule_memory[0].snapshot_name).to eql(:foo)
81
+ expect(rule_memory[0].path).to be_nil
82
+ end
83
+ end
84
+
85
+ context 'final argument' do
86
+ subject { executor.snapshot(:foo, path: path) }
87
+ let(:path) { nil }
88
+
89
+ context 'routing rule does not exist' do
90
+ context 'no explicit path given' do
91
+ it 'records' do
92
+ subject
93
+ expect(rule_memory.size).to eql(1)
94
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
95
+ expect(rule_memory[0].snapshot_name).to eql(:foo)
96
+ expect(rule_memory[0].path).to be_nil
97
+ end
98
+ end
99
+
100
+ context 'explicit path given as string' do
101
+ let(:path) { '/routed-foo.html' }
102
+
103
+ it 'records' do
104
+ subject
105
+ expect(rule_memory.size).to eql(1)
106
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
107
+ expect(rule_memory[0].snapshot_name).to eql(:foo)
108
+ expect(rule_memory[0].path).to eql('/routed-foo.html')
109
+ end
110
+ end
111
+
112
+ context 'explicit path given as identifier' do
113
+ let(:path) { Nanoc::Identifier.from('/routed-foo.html') }
114
+
115
+ it 'records' do
116
+ subject
117
+ expect(rule_memory.size).to eql(1)
118
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
119
+ expect(rule_memory[0].snapshot_name).to eql(:foo)
120
+ expect(rule_memory[0].path).to eql('/routed-foo.html')
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ it 'raises when given unknown arguments' do
127
+ expect { executor.snapshot(:foo, animal: 'giraffe') }
128
+ .to raise_error(ArgumentError)
129
+ end
130
+
131
+ it 'can create multiple snapshots with different names' do
132
+ executor.snapshot(:foo)
133
+ executor.snapshot(:bar)
134
+
135
+ expect(rule_memory.size).to eql(2)
136
+ expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
137
+ expect(rule_memory[0].snapshot_name).to eql(:foo)
138
+ expect(rule_memory[1]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
139
+ expect(rule_memory[1].snapshot_name).to eql(:bar)
140
+ end
141
+ end
142
+ end