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,59 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::LayoutTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_initialize
8
+ # Make sure attributes are cleaned
9
+ layout = Nanoc::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
10
+ assert_equal({ :foo => 'bar' }, layout.attributes)
11
+
12
+ # Make sure identifier is cleaned
13
+ layout = Nanoc::Layout.new("content", { 'foo' => 'bar' }, 'foo')
14
+ assert_equal('/foo/', layout.identifier)
15
+ end
16
+
17
+ def test_frozen_identifier
18
+ layout = Nanoc::Layout.new("foo", {}, '/foo')
19
+
20
+ raised = false
21
+ begin
22
+ layout.identifier.chop!
23
+ rescue => error
24
+ raised = true
25
+ assert_match /^can't modify frozen [Ss]tring$/, error.message
26
+ end
27
+ assert raised, 'Should have raised when trying to modify a frozen string'
28
+ end
29
+
30
+ def test_lookup_with_known_attribute
31
+ # Create layout
32
+ layout = Nanoc::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
33
+
34
+ # Check attributes
35
+ assert_equal('bar', layout[:foo])
36
+ end
37
+
38
+ def test_lookup_with_unknown_attribute
39
+ # Create layout
40
+ layout = Nanoc::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
41
+
42
+ # Check attributes
43
+ assert_equal(nil, layout[:filter])
44
+ end
45
+
46
+ def test_dump_and_load
47
+ layout = Nanoc::Layout.new(
48
+ "foobar",
49
+ { :a => { :b => 123 }},
50
+ '/foo/')
51
+
52
+ layout = Marshal.load(Marshal.dump(layout))
53
+
54
+ assert_equal '/foo/', layout.identifier
55
+ assert_equal 'foobar', layout.raw_content
56
+ assert_equal({ :a => { :b => 123 }}, layout.attributes)
57
+ end
58
+
59
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::MemoizationTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ class Sample1
8
+
9
+ extend Nanoc::Memoization
10
+
11
+ def initialize(value)
12
+ @value = value
13
+ end
14
+
15
+ def run(n)
16
+ @value*10 + n
17
+ end
18
+ memoize :run
19
+
20
+ end
21
+
22
+ class Sample2
23
+
24
+ extend Nanoc::Memoization
25
+
26
+ def initialize(value)
27
+ @value = value
28
+ end
29
+
30
+ def run(n)
31
+ @value*100 + n
32
+ end
33
+ memoize :run
34
+
35
+ end
36
+
37
+ class EqualSample
38
+
39
+ extend Nanoc::Memoization
40
+
41
+ def initialize(value)
42
+ @value = value
43
+ end
44
+
45
+ def hash
46
+ 4
47
+ end
48
+
49
+ def eql?(other)
50
+ true
51
+ end
52
+
53
+ def ==(other)
54
+ true
55
+ end
56
+
57
+ def run(n)
58
+ @value*10 + n
59
+ end
60
+ memoize :run
61
+
62
+ end
63
+
64
+ def test
65
+ sample1a = Sample1.new(10)
66
+ sample1b = Sample1.new(15)
67
+ sample2a = Sample2.new(20)
68
+ sample2b = Sample2.new(25)
69
+
70
+ 3.times do
71
+ assert_equal (10*10+5), sample1a.run(5)
72
+ assert_equal (10*15+7), sample1b.run(7)
73
+ assert_equal (100*20+5), sample2a.run(5)
74
+ assert_equal (100*25+7), sample2b.run(7)
75
+ end
76
+ end
77
+
78
+ def test_equal
79
+ sample1 = EqualSample.new(2)
80
+ sample2 = EqualSample.new(3)
81
+
82
+ 3.times do
83
+ assert_equal (2*10+5), sample1.run(5)
84
+ assert_equal (2*10+3), sample1.run(3)
85
+ assert_equal (3*10+5), sample2.run(5)
86
+ assert_equal (3*10+3), sample2.run(3)
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::NotificationCenterTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_post
8
+ # Set up notification
9
+ Nanoc::NotificationCenter.on :ping_received, :test do
10
+ @ping_received = true
11
+ end
12
+
13
+ # Post
14
+ @ping_received = false
15
+ Nanoc::NotificationCenter.post :ping_received
16
+ assert(@ping_received)
17
+ end
18
+
19
+ def test_remove
20
+ # Set up notification
21
+ Nanoc::NotificationCenter.on :ping_received, :test do
22
+ @ping_received = true
23
+ end
24
+
25
+ # Remove observer
26
+ Nanoc::NotificationCenter.remove :ping_received, :test
27
+
28
+ # Post
29
+ @ping_received = false
30
+ Nanoc::NotificationCenter.post :ping_received
31
+ assert(!@ping_received)
32
+ end
33
+
34
+ end
@@ -0,0 +1,394 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::OutdatednessCheckerTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_not_outdated
8
+ # Compile once
9
+ with_site(:name => 'foo') do |site|
10
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
11
+ File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
12
+
13
+ site.compile
14
+ end
15
+
16
+ # Check
17
+ with_site(:name => 'foo') do |site|
18
+ outdatedness_checker = site.compiler.send :outdatedness_checker
19
+ rep = site.items[0].reps[0]
20
+ assert_nil outdatedness_checker.outdatedness_reason_for(rep)
21
+ end
22
+ end
23
+
24
+ def test_outdated_if_item_checksum_nil
25
+ # Compile once
26
+ with_site(:name => 'foo') do |site|
27
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
28
+ File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
29
+
30
+ site.compile
31
+ end
32
+
33
+ # Delete checksums
34
+ with_site(:name => 'foo') do |site|
35
+ FileUtils.rm('tmp/checksums')
36
+ end
37
+
38
+ # Check
39
+ with_site(:name => 'foo') do |site|
40
+ outdatedness_checker = site.compiler.send :outdatedness_checker
41
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
42
+ assert_equal ::Nanoc::OutdatednessReasons::NotEnoughData,
43
+ outdatedness_checker.outdatedness_reason_for(rep)
44
+ end
45
+ end
46
+
47
+ def test_outdated_if_compiled_file_doesnt_exist
48
+ # Compile once
49
+ with_site(:name => 'foo') do |site|
50
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
51
+ File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
52
+
53
+ site.compile
54
+ end
55
+
56
+ # Delete old item
57
+ FileUtils.cd('foo') do
58
+ FileUtils.rm_rf('output/index.html')
59
+ end
60
+
61
+ # Check
62
+ with_site(:name => 'foo') do |site|
63
+ outdatedness_checker = site.compiler.send :outdatedness_checker
64
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
65
+ assert_equal ::Nanoc::OutdatednessReasons::NotWritten,
66
+ outdatedness_checker.outdatedness_reason_for(rep)
67
+ end
68
+ end
69
+
70
+ def test_outdated_if_item_checksum_is_different
71
+ # Compile once
72
+ with_site(:name => 'foo') do |site|
73
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
74
+ File.open('content/new.html', 'w') { |io| io.write('o hello too') }
75
+ File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
76
+
77
+ site.compile
78
+ end
79
+
80
+ # Create new item
81
+ FileUtils.cd('foo') do
82
+ File.open('content/new.html', 'w') { |io| io.write('o hello DIFFERENT!!!') }
83
+ end
84
+
85
+ # Check
86
+ with_site(:name => 'foo') do |site|
87
+ outdatedness_checker = site.compiler.send :outdatedness_checker
88
+ rep = site.items.find { |i| i.identifier == '/new/' }.reps[0]
89
+ assert_equal ::Nanoc::OutdatednessReasons::SourceModified,
90
+ outdatedness_checker.outdatedness_reason_for(rep)
91
+ end
92
+ end
93
+
94
+ def test_outdated_if_dependent_layout_outdated
95
+ # Compile once
96
+ with_site(:name => 'foo', :compilation_rule_content => 'layout "/default/"', :has_layout => true) do |site|
97
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
98
+ File.open('layouts/default.html', 'w') { |io| io.write('!!! <%= yield %> !!!') }
99
+
100
+ site.compile
101
+ end
102
+
103
+ # Change layout
104
+ FileUtils.cd('foo') do
105
+ File.open('layouts/default.html', 'w') { |io| io.write('!!! <%= yield %> !!! different') }
106
+ end
107
+
108
+ # Check
109
+ with_site(:name => 'foo') do |site|
110
+ # FIXME ugly fugly hack
111
+ site.compiler.load
112
+
113
+ outdatedness_checker = site.compiler.send :outdatedness_checker
114
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
115
+ assert_equal ::Nanoc::OutdatednessReasons::DependenciesOutdated,
116
+ outdatedness_checker.outdatedness_reason_for(rep)
117
+ end
118
+ end
119
+
120
+ def test_outdated_if_dependent_item_outdated
121
+ # Compile once
122
+ with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
123
+ File.open('content/a.html', 'w') do |io|
124
+ io.write('<%= @items.find { |i| i.identifier == "/b/" }.compiled_content %>')
125
+ end
126
+ File.open('content/b.html', 'w') do |io|
127
+ io.write('stuff')
128
+ end
129
+
130
+ site.compile
131
+ end
132
+
133
+ # Change item
134
+ FileUtils.cd('foo') do
135
+ File.open('content/b.html', 'w') do |io|
136
+ io.write('stuff different!!!')
137
+ end
138
+ end
139
+
140
+ # Check
141
+ with_site(:name => 'foo') do |site|
142
+ # FIXME ugly fugly hack
143
+ site.compiler.load
144
+
145
+ outdatedness_checker = site.compiler.send :outdatedness_checker
146
+ rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
147
+ assert_equal ::Nanoc::OutdatednessReasons::DependenciesOutdated,
148
+ outdatedness_checker.outdatedness_reason_for(rep)
149
+ end
150
+ end
151
+
152
+ def test_outdated_if_dependent_item_outdated_chained
153
+ # Compile once
154
+ with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
155
+ File.open('content/a.html', 'w') do |io|
156
+ io.write('<%= @items.find { |i| i.identifier == "/b/" }.compiled_content %> aaa')
157
+ end
158
+ File.open('content/b.html', 'w') do |io|
159
+ io.write('<%= @items.find { |i| i.identifier == "/c/" }.compiled_content %> bbb')
160
+ end
161
+ File.open('content/c.html', 'w') do |io|
162
+ io.write('stuff')
163
+ end
164
+
165
+ site.compile
166
+ end
167
+
168
+ # Change item
169
+ FileUtils.cd('foo') do
170
+ File.open('content/c.html', 'w') do |io|
171
+ io.write('stuff different!!!')
172
+ end
173
+ end
174
+
175
+ # Check
176
+ with_site(:name => 'foo') do |site|
177
+ # FIXME ugly fugly hack
178
+ site.compiler.load
179
+
180
+ outdatedness_checker = site.compiler.send :outdatedness_checker
181
+ rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
182
+ assert_equal ::Nanoc::OutdatednessReasons::DependenciesOutdated,
183
+ outdatedness_checker.outdatedness_reason_for(rep)
184
+ end
185
+ end
186
+
187
+ def test_outdated_if_dependent_item_removed
188
+ # Compile once
189
+ with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
190
+ File.open('content/a.html', 'w') do |io|
191
+ io.write('<% @items.select { |i| i.identifier != @item.identifier }.each do |i| %>')
192
+ io.write(' <%= i.compiled_content %>')
193
+ io.write('<% end %>')
194
+ end
195
+ File.open('content/b.html', 'w') do |io|
196
+ io.write('stuff')
197
+ end
198
+
199
+ site.compile
200
+ end
201
+
202
+ # Delete item
203
+ FileUtils.cd('foo') do
204
+ FileUtils.rm_rf('content/b.html')
205
+ end
206
+
207
+ # Check
208
+ with_site(:name => 'foo') do |site|
209
+ # FIXME ugly fugly hack
210
+ site.compiler.load
211
+
212
+ outdatedness_checker = site.compiler.send :outdatedness_checker
213
+ rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
214
+ assert_equal ::Nanoc::OutdatednessReasons::DependenciesOutdated,
215
+ outdatedness_checker.outdatedness_reason_for(rep)
216
+ end
217
+ end
218
+
219
+ def test_outdated_if_dependent_item_added
220
+ # Compile once
221
+ with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
222
+ File.open('content/a.html', 'w') do |io|
223
+ io.write('<% @items.select { |i| i.identifier != @item.identifier }.each do |i| %>')
224
+ io.write(' <%= i.compiled_content %>')
225
+ io.write('<% end %>')
226
+ end
227
+ File.open('content/b.html', 'w') do |io|
228
+ io.write('stuff')
229
+ end
230
+
231
+ site.compile
232
+ end
233
+
234
+ # Add item
235
+ FileUtils.cd('foo') do
236
+ File.open('content/z.html', 'w') do |io|
237
+ io.write('moar stuff')
238
+ end
239
+ end
240
+
241
+ # Check
242
+ with_site(:name => 'foo') do |site|
243
+ # FIXME ugly fugly hack
244
+ site.compiler.load
245
+
246
+ outdatedness_checker = site.compiler.send :outdatedness_checker
247
+ rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
248
+ assert_equal ::Nanoc::OutdatednessReasons::DependenciesOutdated,
249
+ outdatedness_checker.outdatedness_reason_for(rep)
250
+ end
251
+ end
252
+
253
+ # TODO make sure outdatedness of non-outdated items is correct
254
+
255
+ def test_outdated_if_code_snippets_outdated
256
+ # Compile once
257
+ with_site(:name => 'foo') do |site|
258
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
259
+
260
+ site.compile
261
+ end
262
+
263
+ # Change code
264
+ FileUtils.cd('foo') do
265
+ File.open('lib/moo.rb', 'w') { |io| io.write('def moo ; puts "moo" ; end') }
266
+ end
267
+
268
+ # Check
269
+ with_site(:name => 'foo') do |site|
270
+ outdatedness_checker = site.compiler.send :outdatedness_checker
271
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
272
+ assert_equal ::Nanoc::OutdatednessReasons::CodeSnippetsModified,
273
+ outdatedness_checker.outdatedness_reason_for(rep)
274
+ end
275
+ end
276
+
277
+ def test_outdated_if_config_outdated
278
+ # Compile once
279
+ with_site(:name => 'foo') do |site|
280
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
281
+
282
+ site.compile
283
+ end
284
+
285
+ # Change code
286
+ FileUtils.cd('foo') do
287
+ File.open('config.yaml', 'w') { |io| io.write('awesome: true') }
288
+ end
289
+
290
+ # Check
291
+ with_site(:name => 'foo') do |site|
292
+ outdatedness_checker = site.compiler.send :outdatedness_checker
293
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
294
+ assert_equal ::Nanoc::OutdatednessReasons::ConfigurationModified,
295
+ outdatedness_checker.outdatedness_reason_for(rep)
296
+ end
297
+ end
298
+
299
+ def test_not_outdated_if_irrelevant_rule_modified
300
+ # Compile once
301
+ with_site(:name => 'foo') do |site|
302
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
303
+
304
+ site.compile
305
+ end
306
+
307
+ # Change code
308
+ FileUtils.cd('foo') do
309
+ File.open('Rules', 'a') { |io| io.write('layout "/moo/", :haml') }
310
+ end
311
+
312
+ # Check
313
+ with_site(:name => 'foo') do |site|
314
+ outdatedness_checker = site.compiler.send :outdatedness_checker
315
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
316
+ assert_nil outdatedness_checker.outdatedness_reason_for(rep)
317
+ end
318
+ end
319
+
320
+ def test_outdated_if_relevant_rule_modified
321
+ # Create site
322
+ with_site(:name => 'foo') do |site|
323
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
324
+ File.open('Rules', 'w') do |io|
325
+ io.write("compile '/' do\n")
326
+ io.write(" filter :erb\n")
327
+ io.write("end\n")
328
+ io.write("\n")
329
+ io.write("route '/' do\n")
330
+ io.write(" '/index.html'\n")
331
+ io.write("end\n")
332
+ end
333
+ end
334
+
335
+ # Compile once
336
+ FileUtils.cd('foo') do
337
+ site = Nanoc::Site.new('.')
338
+ site.compile
339
+ end
340
+
341
+ # Modify rules
342
+ FileUtils.cd('foo') do
343
+ File.open('Rules', 'w') do |io|
344
+ io.write("compile '/' do\n")
345
+ io.write("end\n")
346
+ io.write("\n")
347
+ io.write("route '/' do\n")
348
+ io.write(" '/index.html'\n")
349
+ io.write("end\n")
350
+ end
351
+ end
352
+
353
+ # Check
354
+ FileUtils.cd('foo') do
355
+ site = Nanoc::Site.new('.')
356
+ outdatedness_checker = site.compiler.send :outdatedness_checker
357
+ rep = site.items.find { |i| i.identifier == '/' }.reps[0]
358
+ assert_equal ::Nanoc::OutdatednessReasons::RulesModified,
359
+ outdatedness_checker.outdatedness_reason_for(rep)
360
+ end
361
+ end
362
+
363
+ def test_items_in_rules_should_not_cause_outdatedness
364
+ # Create site
365
+ with_site(:name => 'foo') do |site|
366
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
367
+ File.open('Rules', 'w') do |io|
368
+ io.write("compile '/' do\n")
369
+ io.write(" filter :erb, :stuff => @items\n")
370
+ io.write("end\n")
371
+ io.write("\n")
372
+ io.write("route '/' do\n")
373
+ io.write(" '/index.html'\n")
374
+ io.write("end\n")
375
+ end
376
+ end
377
+
378
+ # Compile
379
+ FileUtils.cd('foo') do
380
+ site = Nanoc::Site.new('.')
381
+ site.compile
382
+ end
383
+
384
+ # Assert not outdated
385
+ FileUtils.cd('foo') do
386
+ site = Nanoc::Site.new('.')
387
+ outdatedness_checker = site.compiler.outdatedness_checker
388
+ site.items.each do |item|
389
+ refute outdatedness_checker.outdated?(item), "item should not be outdated"
390
+ end
391
+ end
392
+ end
393
+
394
+ end