nanoc 3.8.0 → 4.0.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +322 -0
  4. data/NEWS.md +6 -0
  5. data/bin/nanoc +0 -18
  6. data/lib/nanoc.rb +5 -3
  7. data/lib/nanoc/base.rb +24 -6
  8. data/lib/nanoc/base/checksummer.rb +6 -4
  9. data/lib/nanoc/base/compilation/checksum_store.rb +4 -4
  10. data/lib/nanoc/base/compilation/compiled_content_cache.rb +5 -5
  11. data/lib/nanoc/base/compilation/compiler.rb +60 -65
  12. data/lib/nanoc/base/compilation/compiler_dsl.rb +11 -9
  13. data/lib/nanoc/base/compilation/dependency_tracker.rb +24 -38
  14. data/lib/nanoc/base/compilation/filter.rb +22 -7
  15. data/lib/nanoc/base/compilation/item_rep_proxy.rb +14 -12
  16. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +8 -8
  17. data/lib/nanoc/base/compilation/outdatedness_checker.rb +32 -32
  18. data/lib/nanoc/base/compilation/outdatedness_reasons.rb +3 -1
  19. data/lib/nanoc/base/compilation/rule.rb +9 -7
  20. data/lib/nanoc/base/compilation/rule_context.rb +15 -15
  21. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +3 -3
  22. data/lib/nanoc/base/compilation/rule_memory_store.rb +7 -7
  23. data/lib/nanoc/base/compilation/rules_collection.rb +28 -30
  24. data/lib/nanoc/base/context.rb +2 -2
  25. data/lib/nanoc/base/core_ext/array.rb +17 -25
  26. data/lib/nanoc/base/core_ext/hash.rb +17 -25
  27. data/lib/nanoc/base/core_ext/pathname.rb +4 -2
  28. data/lib/nanoc/base/core_ext/string.rb +5 -3
  29. data/lib/nanoc/base/directed_graph.rb +4 -9
  30. data/lib/nanoc/base/error.rb +7 -0
  31. data/lib/nanoc/base/errors.rb +16 -23
  32. data/lib/nanoc/base/memoization.rb +4 -2
  33. data/lib/nanoc/base/notification_center.rb +3 -1
  34. data/lib/nanoc/base/plugin_registry.rb +14 -21
  35. data/lib/nanoc/base/result_data/item_rep.rb +43 -88
  36. data/lib/nanoc/base/source_data/code_snippet.rb +6 -4
  37. data/lib/nanoc/base/source_data/configuration.rb +3 -1
  38. data/lib/nanoc/base/source_data/data_source.rb +12 -94
  39. data/lib/nanoc/base/source_data/identifier.rb +50 -0
  40. data/lib/nanoc/base/source_data/item.rb +24 -67
  41. data/lib/nanoc/base/source_data/item_array.rb +6 -4
  42. data/lib/nanoc/base/source_data/layout.rb +17 -28
  43. data/lib/nanoc/base/source_data/site.rb +33 -44
  44. data/lib/nanoc/base/store.rb +3 -5
  45. data/lib/nanoc/base/temp_filename_factory.rb +3 -2
  46. data/lib/nanoc/base/views/config.rb +19 -0
  47. data/lib/nanoc/base/views/item.rb +77 -0
  48. data/lib/nanoc/base/views/item_collection.rb +43 -0
  49. data/lib/nanoc/base/views/item_rep.rb +125 -0
  50. data/lib/nanoc/base/views/layout.rb +42 -0
  51. data/lib/nanoc/base/views/layout_collection.rb +26 -0
  52. data/lib/nanoc/base/views/mutable_config.rb +9 -0
  53. data/lib/nanoc/base/views/mutable_item.rb +9 -0
  54. data/lib/nanoc/base/views/mutable_item_collection.rb +18 -0
  55. data/lib/nanoc/base/views/mutable_layout.rb +9 -0
  56. data/lib/nanoc/base/views/mutable_layout_collection.rb +18 -0
  57. data/lib/nanoc/base/views/site.rb +35 -0
  58. data/lib/nanoc/cli.rb +3 -6
  59. data/lib/nanoc/cli/ansi_string_colorizer.rb +2 -0
  60. data/lib/nanoc/cli/cleaning_stream.rb +2 -0
  61. data/lib/nanoc/cli/command_runner.rb +8 -42
  62. data/lib/nanoc/cli/commands/check.rb +2 -2
  63. data/lib/nanoc/cli/commands/compile.rb +19 -34
  64. data/lib/nanoc/cli/commands/create-site.rb +46 -83
  65. data/lib/nanoc/cli/commands/deploy.rb +4 -4
  66. data/lib/nanoc/cli/commands/shell.rb +1 -1
  67. data/lib/nanoc/cli/commands/show-plugins.rb +4 -6
  68. data/lib/nanoc/cli/error_handler.rb +4 -14
  69. data/lib/nanoc/cli/logger.rb +2 -0
  70. data/lib/nanoc/cli/stream_cleaners.rb +1 -0
  71. data/lib/nanoc/cli/stream_cleaners/abstract.rb +2 -0
  72. data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +2 -0
  73. data/lib/nanoc/cli/stream_cleaners/utf8.rb +2 -0
  74. data/lib/nanoc/data_sources.rb +1 -17
  75. data/lib/nanoc/data_sources/filesystem.rb +6 -37
  76. data/lib/nanoc/data_sources/filesystem_unified.rb +5 -3
  77. data/lib/nanoc/data_sources/filesystem_verbose.rb +5 -3
  78. data/lib/nanoc/data_sources/static.rb +4 -2
  79. data/lib/nanoc/extra.rb +1 -13
  80. data/lib/nanoc/extra/checking.rb +1 -0
  81. data/lib/nanoc/extra/checking/check.rb +4 -2
  82. data/lib/nanoc/extra/checking/checks.rb +1 -0
  83. data/lib/nanoc/extra/checking/checks/css.rb +1 -0
  84. data/lib/nanoc/extra/checking/checks/external_links.rb +2 -0
  85. data/lib/nanoc/extra/checking/checks/html.rb +1 -0
  86. data/lib/nanoc/extra/checking/checks/internal_links.rb +2 -0
  87. data/lib/nanoc/extra/checking/checks/mixed_content.rb +2 -0
  88. data/lib/nanoc/extra/checking/checks/stale.rb +1 -0
  89. data/lib/nanoc/extra/checking/dsl.rb +1 -0
  90. data/lib/nanoc/extra/checking/issue.rb +1 -0
  91. data/lib/nanoc/extra/checking/runner.rb +3 -3
  92. data/lib/nanoc/extra/core_ext/pathname.rb +5 -3
  93. data/lib/nanoc/extra/core_ext/time.rb +4 -2
  94. data/lib/nanoc/extra/deployer.rb +3 -1
  95. data/lib/nanoc/extra/deployers.rb +1 -0
  96. data/lib/nanoc/extra/deployers/fog.rb +2 -0
  97. data/lib/nanoc/extra/deployers/rsync.rb +2 -0
  98. data/lib/nanoc/extra/filesystem_tools.rb +3 -7
  99. data/lib/nanoc/extra/jruby_nokogiri_warner.rb +1 -0
  100. data/lib/nanoc/extra/link_collector.rb +1 -0
  101. data/lib/nanoc/extra/piper.rb +2 -1
  102. data/lib/nanoc/extra/pruner.rb +5 -3
  103. data/lib/nanoc/filters.rb +1 -2
  104. data/lib/nanoc/filters/asciidoc.rb +2 -0
  105. data/lib/nanoc/filters/bluecloth.rb +1 -0
  106. data/lib/nanoc/filters/coffeescript.rb +2 -0
  107. data/lib/nanoc/filters/colorize_syntax.rb +1 -12
  108. data/lib/nanoc/filters/erb.rb +2 -1
  109. data/lib/nanoc/filters/erubis.rb +2 -1
  110. data/lib/nanoc/filters/haml.rb +2 -1
  111. data/lib/nanoc/filters/handlebars.rb +2 -0
  112. data/lib/nanoc/filters/kramdown.rb +1 -0
  113. data/lib/nanoc/filters/less.rb +1 -0
  114. data/lib/nanoc/filters/markaby.rb +1 -0
  115. data/lib/nanoc/filters/maruku.rb +1 -0
  116. data/lib/nanoc/filters/mustache.rb +2 -0
  117. data/lib/nanoc/filters/pandoc.rb +1 -0
  118. data/lib/nanoc/filters/rainpress.rb +1 -0
  119. data/lib/nanoc/filters/rdiscount.rb +1 -0
  120. data/lib/nanoc/filters/rdoc.rb +1 -0
  121. data/lib/nanoc/filters/redcarpet.rb +2 -0
  122. data/lib/nanoc/filters/redcloth.rb +1 -0
  123. data/lib/nanoc/filters/relativize_paths.rb +1 -0
  124. data/lib/nanoc/filters/rubypants.rb +1 -0
  125. data/lib/nanoc/filters/sass.rb +1 -0
  126. data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +2 -0
  127. data/lib/nanoc/filters/slim.rb +3 -1
  128. data/lib/nanoc/filters/typogruby.rb +2 -0
  129. data/lib/nanoc/filters/uglify_js.rb +1 -0
  130. data/lib/nanoc/filters/xsl.rb +2 -0
  131. data/lib/nanoc/filters/yui_compressor.rb +2 -0
  132. data/lib/nanoc/helpers/blogging.rb +30 -30
  133. data/lib/nanoc/helpers/breadcrumbs.rb +2 -2
  134. data/lib/nanoc/helpers/capturing.rb +6 -17
  135. data/lib/nanoc/helpers/filtering.rb +3 -3
  136. data/lib/nanoc/helpers/link_to.rb +3 -3
  137. data/lib/nanoc/helpers/rendering.rb +11 -11
  138. data/lib/nanoc/helpers/xml_sitemap.rb +3 -3
  139. data/lib/nanoc/tasks.rb +1 -0
  140. data/lib/nanoc/tasks/clean.rake +1 -1
  141. data/lib/nanoc/version.rb +1 -1
  142. data/tasks/doc.rake +2 -1
  143. data/tasks/test.rake +7 -1
  144. data/test/base/checksummer_spec.rb +15 -15
  145. data/test/base/core_ext/array_spec.rb +10 -10
  146. data/test/base/core_ext/hash_spec.rb +16 -16
  147. data/test/base/core_ext/pathname_spec.rb +2 -2
  148. data/test/base/core_ext/string_spec.rb +9 -9
  149. data/test/base/temp_filename_factory_spec.rb +3 -7
  150. data/test/base/test_checksum_store.rb +5 -5
  151. data/test/base/test_code_snippet.rb +3 -3
  152. data/test/base/test_compiler.rb +29 -29
  153. data/test/base/test_compiler_dsl.rb +23 -23
  154. data/test/base/test_context.rb +4 -4
  155. data/test/base/test_data_source.rb +17 -7
  156. data/test/base/test_dependency_tracker.rb +29 -29
  157. data/test/base/test_directed_graph.rb +27 -27
  158. data/test/base/test_item.rb +23 -21
  159. data/test/base/test_item_array.rb +18 -18
  160. data/test/base/test_item_rep.rb +76 -76
  161. data/test/base/test_item_rep_recorder_proxy.rb +4 -4
  162. data/test/base/test_layout.rb +8 -16
  163. data/test/base/test_memoization.rb +4 -4
  164. data/test/base/test_notification_center.rb +6 -6
  165. data/test/base/test_outdatedness_checker.rb +18 -18
  166. data/test/base/test_plugin.rb +1 -1
  167. data/test/base/test_rule.rb +2 -2
  168. data/test/base/test_rule_context.rb +5 -5
  169. data/test/base/test_site.rb +62 -38
  170. data/test/base/test_store.rb +2 -2
  171. data/test/cli/commands/test_check.rb +1 -1
  172. data/test/cli/commands/test_compile.rb +24 -18
  173. data/test/cli/commands/test_create_site.rb +5 -7
  174. data/test/cli/commands/test_deploy.rb +1 -1
  175. data/test/data_sources/test_filesystem.rb +22 -67
  176. data/test/data_sources/test_filesystem_unified.rb +10 -23
  177. data/test/data_sources/test_filesystem_verbose.rb +8 -53
  178. data/test/data_sources/test_static.rb +9 -9
  179. data/test/extra/checking/checks/test_stale.rb +1 -1
  180. data/test/extra/core_ext/test_pathname.rb +3 -3
  181. data/test/extra/core_ext/test_time.rb +4 -4
  182. data/test/extra/test_filesystem_tools.rb +1 -1
  183. data/test/filters/test_handlebars.rb +3 -3
  184. data/test/filters/test_less.rb +6 -6
  185. data/test/filters/test_mustache.rb +2 -2
  186. data/test/filters/test_relativize_paths.rb +81 -81
  187. data/test/filters/test_sass.rb +7 -7
  188. data/test/filters/test_xsl.rb +6 -6
  189. data/test/helper.rb +1 -1
  190. data/test/helpers/test_blogging.rb +78 -99
  191. data/test/helpers/test_breadcrumbs.rb +12 -12
  192. data/test/helpers/test_capturing.rb +10 -11
  193. data/test/helpers/test_filtering.rb +6 -6
  194. data/test/helpers/test_rendering.rb +3 -3
  195. data/test/helpers/test_tagging.rb +7 -7
  196. data/test/helpers/test_xml_sitemap.rb +34 -33
  197. metadata +19 -43
  198. data/lib/nanoc/cli/commands/autocompile.rb +0 -69
  199. data/lib/nanoc/cli/commands/create-item.rb +0 -55
  200. data/lib/nanoc/cli/commands/create-layout.rb +0 -68
  201. data/lib/nanoc/cli/commands/sync.rb +0 -32
  202. data/lib/nanoc/cli/commands/update.rb +0 -63
  203. data/lib/nanoc/cli/commands/validate-css.rb +0 -20
  204. data/lib/nanoc/cli/commands/validate-html.rb +0 -20
  205. data/lib/nanoc/cli/commands/validate-links.rb +0 -27
  206. data/lib/nanoc/cli/commands/watch.rb +0 -176
  207. data/lib/nanoc/data_sources/deprecated/delicious.rb +0 -38
  208. data/lib/nanoc/data_sources/deprecated/last_fm.rb +0 -85
  209. data/lib/nanoc/data_sources/deprecated/twitter.rb +0 -34
  210. data/lib/nanoc/extra/auto_compiler.rb +0 -99
  211. data/lib/nanoc/extra/chick.rb +0 -117
  212. data/lib/nanoc/extra/file_proxy.rb +0 -36
  213. data/lib/nanoc/extra/validators.rb +0 -8
  214. data/lib/nanoc/extra/validators/links.rb +0 -18
  215. data/lib/nanoc/extra/validators/w3c.rb +0 -23
  216. data/lib/nanoc/extra/vcs.rb +0 -62
  217. data/lib/nanoc/extra/vcses.rb +0 -15
  218. data/lib/nanoc/extra/vcses/bazaar.rb +0 -21
  219. data/lib/nanoc/extra/vcses/dummy.rb +0 -20
  220. data/lib/nanoc/extra/vcses/git.rb +0 -21
  221. data/lib/nanoc/extra/vcses/mercurial.rb +0 -21
  222. data/lib/nanoc/extra/vcses/subversion.rb +0 -21
  223. data/lib/nanoc/filters/coderay.rb +0 -19
  224. data/lib/nanoc3.rb +0 -3
  225. data/lib/nanoc3/cli.rb +0 -3
  226. data/lib/nanoc3/tasks.rb +0 -3
  227. data/test/cli/commands/test_create_item.rb +0 -10
  228. data/test/cli/commands/test_create_layout.rb +0 -24
  229. data/test/cli/commands/test_sync.rb +0 -27
  230. data/test/cli/commands/test_update.rb +0 -6
  231. data/test/cli/commands/test_watch.rb +0 -74
  232. data/test/extra/test_auto_compiler.rb +0 -437
  233. data/test/extra/test_vcs.rb +0 -18
  234. data/test/extra/validators/test_links.rb +0 -4
  235. data/test/extra/validators/test_w3c.rb +0 -37
  236. data/test/filters/test_coderay.rb +0 -40
@@ -1,62 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra
4
- # A very simple representation of a version control system (VCS) that
5
- # abstracts the add, remove and move operations. It does not commit. This
6
- # class is primarily used by data sources that store data as flat files on
7
- # the disk.
8
- #
9
- # @abstract Subclass and override {#add}, {#remove} and {#move} to implement
10
- # a custom VCS.
11
- class VCS
12
- extend Nanoc::PluginRegistry::PluginMethods
13
-
14
- # Adds the file with the given filename to the working copy.
15
- #
16
- # @param [String] filename The name of the file to add
17
- #
18
- # @return [void]
19
- #
20
- # @abstract
21
- def add(filename) # rubocop:disable Lint/UnusedMethodArgument
22
- not_implemented('add')
23
- end
24
-
25
- # Removes the file with the given filename from the working copy. When
26
- # this method is executed, the file should no longer be present on the
27
- # disk.
28
- #
29
- # @param [String] filename The name of the file to remove
30
- #
31
- # @return [void]
32
- #
33
- # @abstract
34
- def remove(filename) # rubocop:disable Lint/UnusedMethodArgument
35
- not_implemented('remove')
36
- end
37
-
38
- # Moves the file with the given filename to a new location. When this
39
- # method is executed, the original file should no longer be present on the
40
- # disk.
41
- #
42
- # @param [String] src The old filename
43
- #
44
- # @param [String] dst The new filename
45
- #
46
- # @return [void]
47
- #
48
- # @abstract
49
- def move(src, dst) # rubocop:disable Lint/UnusedMethodArgument
50
- not_implemented('move')
51
- end
52
-
53
- private
54
-
55
- def not_implemented(name)
56
- raise NotImplementedError.new(
57
- "#{self.class} does not override ##{name}, which is required for " \
58
- 'this data source to be used.'
59
- )
60
- end
61
- end
62
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- autoload 'Bazaar', 'nanoc/extra/vcses/bazaar'
5
- autoload 'Dummy', 'nanoc/extra/vcses/dummy'
6
- autoload 'Git', 'nanoc/extra/vcses/git'
7
- autoload 'Mercurial', 'nanoc/extra/vcses/mercurial'
8
- autoload 'Subversion', 'nanoc/extra/vcses/subversion'
9
-
10
- Nanoc::Extra::VCS.register '::Nanoc::Extra::VCSes::Bazaar', :bazaar, :bzr
11
- Nanoc::Extra::VCS.register '::Nanoc::Extra::VCSes::Dummy', :dummy
12
- Nanoc::Extra::VCS.register '::Nanoc::Extra::VCSes::Git', :git
13
- Nanoc::Extra::VCS.register '::Nanoc::Extra::VCSes::Mercurial', :mercurial, :hg
14
- Nanoc::Extra::VCS.register '::Nanoc::Extra::VCSes::Subversion', :subversion, :svn
15
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- # @see Nanoc::Extra::VCS
5
- class Bazaar < Nanoc::Extra::VCS
6
- # @see Nanoc::Extra::VCS#add
7
- def add(filename)
8
- system('bzr', 'add', filename)
9
- end
10
-
11
- # @see Nanoc::Extra::VCS#remove
12
- def remove(filename)
13
- system('bzr', 'rm', filename)
14
- end
15
-
16
- # @see Nanoc::Extra::VCS#move
17
- def move(src, dst)
18
- system('bzr', 'mv', src, dst)
19
- end
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- # @see Nanoc::Extra::VCS
5
- class Dummy < Nanoc::Extra::VCS
6
- # @see Nanoc::Extra::VCS#add
7
- def add(_filename)
8
- end
9
-
10
- # @see Nanoc::Extra::VCS#remove
11
- def remove(filename)
12
- FileUtils.rm_rf(filename)
13
- end
14
-
15
- # @see Nanoc::Extra::VCS#move
16
- def move(src, dst)
17
- FileUtils.move(src, dst)
18
- end
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- # @see Nanoc::Extra::VCS
5
- class Git < Nanoc::Extra::VCS
6
- # @see Nanoc::Extra::VCS#add
7
- def add(filename)
8
- system('git', 'add', filename)
9
- end
10
-
11
- # @see Nanoc::Extra::VCS#remove
12
- def remove(filename)
13
- system('git', 'rm', filename)
14
- end
15
-
16
- # @see Nanoc::Extra::VCS#move
17
- def move(src, dst)
18
- system('git', 'mv', src, dst)
19
- end
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- # @see Nanoc::Extra::VCS
5
- class Mercurial < Nanoc::Extra::VCS
6
- # @see Nanoc::Extra::VCS#add
7
- def add(filename)
8
- system('hg', 'add', filename)
9
- end
10
-
11
- # @see Nanoc::Extra::VCS#remove
12
- def remove(filename)
13
- system('hg', 'rm', filename)
14
- end
15
-
16
- # @see Nanoc::Extra::VCS#move
17
- def move(src, dst)
18
- system('hg', 'mv', src, dst)
19
- end
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Extra::VCSes
4
- # @see Nanoc::Extra::VCS
5
- class Subversion < Nanoc::Extra::VCS
6
- # @see Nanoc::Extra::VCS#add
7
- def add(filename)
8
- system('svn', 'add', filename)
9
- end
10
-
11
- # @see Nanoc::Extra::VCS#remove
12
- def remove(filename)
13
- system('svn', 'rm', filename)
14
- end
15
-
16
- # @see Nanoc::Extra::VCS#move
17
- def move(src, dst)
18
- system('svn', 'mv', src, dst)
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Filters
4
- class CodeRay < Nanoc::Filter
5
- requires 'coderay'
6
-
7
- # @deprecated Use the `:colorize_syntax` filter instead.
8
- def run(content, params = {})
9
- # Warn
10
- warn 'The :coderay filter is deprecated; consider using the :colorize_syntax filter instead.'
11
-
12
- # Check params
13
- raise ArgumentError, 'CodeRay filter requires a :language argument which is missing' if params[:language].nil?
14
-
15
- # Get result
16
- ::CodeRay.scan(content, params[:language]).html
17
- end
18
- end
19
- end
@@ -1,3 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'nanoc'
@@ -1,3 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'nanoc/cli'
@@ -1,3 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'nanoc/tasks'
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc::CLI::Commands::CreateItemTest < Nanoc::TestCase
4
- def test_run
5
- with_site do |_site|
6
- Nanoc::CLI.run %w( create_item /blah/ )
7
- assert File.file?('content/blah.html')
8
- end
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc::CLI::Commands::CreateLayoutTest < Nanoc::TestCase
4
- def test_can_compile_new_layout
5
- require 'nanoc/cli'
6
-
7
- Nanoc::CLI.run %w( create_site foo )
8
-
9
- FileUtils.cd('foo') do
10
- # Create new layout
11
- Nanoc::CLI.run %w( create_layout moo )
12
-
13
- # Makes rules use new layout
14
- rules_raw = File.read('Rules')
15
- File.open('Rules', 'w') do |io|
16
- io.write rules_raw.sub("layout 'default'", "layout 'moo'")
17
- end
18
-
19
- site = Nanoc::Site.new('.')
20
- site.load_data
21
- site.compile
22
- end
23
- end
24
- end
@@ -1,27 +0,0 @@
1
- class Nanoc::CLI::Commands::SyncTest < Nanoc::TestCase
2
- def test_run
3
- with_site do
4
- File.open('lib/foo_data_source.rb', 'w') do |io|
5
- io.write "class FooDataSource < Nanoc::DataSource\n"
6
- io.write " identifier :sync_test_foo\n"
7
- io.write " def sync\n"
8
- io.write " File.open('foo_source_data.yaml', 'w') do |io|\n"
9
- io.write " io.write 'sync: true'\n"
10
- io.write " end\n"
11
- io.write " end\n"
12
- io.write "end\n"
13
- end
14
-
15
- File.open('nanoc.yaml', 'w') do |io|
16
- io.write "data_sources:\n"
17
- io.write " - type: sync_test_foo\n"
18
- io.write ' items_root: /'
19
- end
20
-
21
- Nanoc::CLI.run %w( sync )
22
-
23
- assert File.file?('foo_source_data.yaml')
24
- assert_equal File.read('foo_source_data.yaml'), 'sync: true'
25
- end
26
- end
27
- end
@@ -1,6 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc::CLI::Commands::UpdateTest < Nanoc::TestCase
4
- def test_stub
5
- end
6
- end
@@ -1,74 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc::CLI::Commands::WatchTest < Nanoc::TestCase
4
- def test_run
5
- with_site do |_s|
6
- watch_thread = Thread.new do
7
- Nanoc::CLI.run %w( watch )
8
- end
9
-
10
- File.open('content/index.html', 'w') { |io| io.write('Hello there!') }
11
- wait_until_content_equals('content/index.html', 'Hello there!')
12
-
13
- File.open('content/index.html', 'w') { |io| io.write('Hello there again!') }
14
- wait_until_content_equals('content/index.html', 'Hello there again!')
15
-
16
- watch_thread.kill
17
- end
18
- end
19
-
20
- def test_notify
21
- with_site do |_s|
22
- watch_thread = Thread.new do
23
- Nanoc::CLI.run %w( watch )
24
- end
25
-
26
- File.open('content/index.html', 'w') { |io| io.write('Hello there!') }
27
- wait_until_exists('output/index.html')
28
- assert_equal 'Hello there!', File.read('output/index.html')
29
-
30
- watch_thread.kill
31
- end
32
- end
33
-
34
- def test_growlnotify_cmd
35
- Nanoc::CLI.setup
36
- notifier = Nanoc::CLI::Commands::Watch::Notifier.new
37
- assert_equal ['growlnotify', '-m', 'foo'], notifier.send(:growlnotify_cmd_for, 'foo')
38
- end
39
-
40
- def test_growlnotify_windows_cmd
41
- Nanoc::CLI.setup
42
- notifier = Nanoc::CLI::Commands::Watch::Notifier.new
43
- assert_equal ['growlnotify', '/t:nanoc', 'foo'], notifier.send(:growlnotify_windows_cmd_for, 'foo')
44
- end
45
-
46
- def wait_until_exists(filename)
47
- 20.times do
48
- break if File.file?(filename)
49
- sleep 0.5
50
- end
51
- unless File.file?(filename)
52
- raise "Expected #{filename} to appear but it didn't :("
53
- end
54
- end
55
-
56
- def wait_until_content_equals(filename, expected_content)
57
- wait_until_exists(filename)
58
-
59
- 20.times do
60
- break if File.read(filename) == expected_content
61
- sleep 0.5
62
- end
63
-
64
- actual_content = File.read(filename)
65
- if actual_content != expected_content
66
- raise "Expected #{filename} to have " \
67
- "content #{expected_content.inspect} but it had " \
68
- "content #{actual_content.inspect} instead :("
69
- end
70
-
71
- # Ugly, but seems to be necessary or changes are not picked up. :(
72
- sleep 0.5
73
- end
74
- end
@@ -1,437 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Nanoc::Extra::AutoCompilerTest < Nanoc::TestCase
4
- def test_handle_request_with_item_rep_with_index_filename
5
- if_have 'mime/types', 'rack' do
6
- # Create site
7
- Nanoc::CLI.run %w( create_site bar)
8
-
9
- FileUtils.cd('bar') do
10
- # Create item
11
- FileUtils.mkdir_p('content/foo')
12
- File.open('content/foo/index.html', 'w') do |io|
13
- io.write 'Moo!'
14
- end
15
-
16
- # Create output file
17
- FileUtils.mkdir_p('output/foo')
18
- File.open('output/foo/index.html', 'w') do |io|
19
- io.write 'Compiled moo!'
20
- end
21
-
22
- # Create site
23
- site = Nanoc::Site.new('.')
24
- site.expects(:compile)
25
-
26
- # Create autocompiler
27
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
28
- autocompiler.stubs(:build_site)
29
- autocompiler.stubs(:site).returns(site)
30
-
31
- # Serve
32
- status, headers, body = autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/foo/index.html') }
33
-
34
- # Check response
35
- assert_equal(200, status)
36
- assert_equal('text/html', headers['Content-Type'])
37
- body.each do |b|
38
- assert_equal 'Compiled moo!', b
39
- end
40
- end
41
- end
42
- end
43
-
44
- def test_handle_request_with_broken_url
45
- if_have 'mime/types', 'rack' do
46
- # Create site
47
- Nanoc::CLI.run %w( create_site bar)
48
-
49
- FileUtils.cd('bar') do
50
- # Create site
51
- site = Nanoc::Site.new('.')
52
-
53
- # Create autocompiler
54
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
55
- autocompiler.stubs(:build_site)
56
- autocompiler.stubs(:site).returns(site)
57
-
58
- # Serve
59
- status, _, _ = autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/afjwiagoawf.html') }
60
-
61
- # Check response
62
- assert_equal(404, status)
63
- end
64
- end
65
- end
66
-
67
- def test_handle_request_with_file
68
- if_have 'mime/types', 'rack' do
69
- # Create file
70
- FileUtils.mkdir_p('out')
71
- File.open('out/somefile.txt', 'w') { |io| io.write('hello') }
72
-
73
- # Create file server
74
- file_server = mock
75
- def file_server.call(env)
76
- @expected_path_info = 'somefile.txt'
77
- @actual_path_info = env['PATH_INFO']
78
- end
79
- def file_server.expected_path_info
80
- @expected_path_info
81
- end
82
- def file_server.actual_path_info
83
- @actual_path_info
84
- end
85
-
86
- # Create site
87
- site = mock
88
- site.expects(:items).returns([])
89
- site.expects(:config).returns({ output_dir: 'out', index_filenames: ['index.html'] })
90
-
91
- # Create autocompiler
92
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
93
- autocompiler.stubs(:build_site)
94
- autocompiler.stubs(:site).returns(site)
95
- autocompiler.expects(:file_server).returns(file_server)
96
-
97
- # Run
98
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => 'somefile.txt') }
99
-
100
- # Check
101
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
102
- end
103
- end
104
-
105
- def test_handle_request_with_dir_with_slash_with_index_file
106
- if_have 'mime/types', 'rack' do
107
- # Create file
108
- FileUtils.mkdir_p('out/foo/bar')
109
- File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
110
-
111
- # Create file server
112
- file_server = mock
113
- def file_server.call(env)
114
- @expected_path_info = '/foo/bar/index.html'
115
- @actual_path_info = env['PATH_INFO']
116
- end
117
- def file_server.expected_path_info
118
- @expected_path_info
119
- end
120
- def file_server.actual_path_info
121
- @actual_path_info
122
- end
123
-
124
- # Create site
125
- site = mock
126
- site.expects(:items).returns([])
127
- site.expects(:config).at_least_once.returns({ output_dir: 'out', index_filenames: ['index.html'] })
128
-
129
- # Create autocompiler
130
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
131
- autocompiler.stubs(:build_site)
132
- autocompiler.stubs(:site).returns(site)
133
- autocompiler.expects(:file_server).returns(file_server)
134
-
135
- # Run
136
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/foo/bar/') }
137
-
138
- # Check
139
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
140
- end
141
- end
142
-
143
- def test_handle_request_with_dir_with_slash_without_index_file
144
- if_have 'mime/types', 'rack' do
145
- # Create file
146
- FileUtils.mkdir_p('out/foo/bar')
147
- File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
148
-
149
- # Create file server
150
- file_server = mock
151
- def file_server.call(env)
152
- @expected_path_info = 'foo/bar/'
153
- @actual_path_info = env['PATH_INFO']
154
- end
155
- def file_server.expected_path_info
156
- @expected_path_info
157
- end
158
- def file_server.actual_path_info
159
- @actual_path_info
160
- end
161
-
162
- # Create site
163
- site = mock
164
- site.expects(:items).returns([])
165
- site.expects(:config).at_least_once.returns({ output_dir: 'out', index_filenames: ['index.html'] })
166
-
167
- # Create autocompiler
168
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
169
- autocompiler.stubs(:build_site)
170
- autocompiler.stubs(:site).returns(site)
171
- autocompiler.expects(:file_server).returns(file_server)
172
-
173
- # Run
174
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => 'foo/bar/') }
175
-
176
- # Check
177
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
178
- end
179
- end
180
-
181
- def test_handle_request_with_dir_without_slash_with_index_file
182
- if_have 'mime/types', 'rack' do
183
- # Create file
184
- FileUtils.mkdir_p('out/foo/bar')
185
- File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
186
-
187
- # Create file server
188
- file_server = mock
189
- def file_server.call(env)
190
- @expected_path_info = 'foo/bar'
191
- @actual_path_info = env['PATH_INFO']
192
- end
193
- def file_server.expected_path_info
194
- @expected_path_info
195
- end
196
- def file_server.actual_path_info
197
- @actual_path_info
198
- end
199
-
200
- # Create site
201
- site = mock
202
- site.expects(:items).returns([])
203
- site.expects(:config).at_least_once.returns({ output_dir: 'out', index_filenames: ['index.html'] })
204
-
205
- # Create autocompiler
206
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
207
- autocompiler.stubs(:build_site)
208
- autocompiler.stubs(:site).returns(site)
209
- autocompiler.expects(:file_server).returns(file_server)
210
-
211
- # Run
212
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => 'foo/bar') }
213
-
214
- # Check
215
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
216
- end
217
- end
218
-
219
- def test_handle_request_with_dir_without_slash_without_index_file
220
- if_have 'mime/types', 'rack' do
221
- # Create file
222
- FileUtils.mkdir_p('out/foo/bar')
223
- File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
224
-
225
- # Create file server
226
- file_server = mock
227
- def file_server.call(env)
228
- @expected_path_info = 'foo/bar'
229
- @actual_path_info = env['PATH_INFO']
230
- end
231
- def file_server.expected_path_info
232
- @expected_path_info
233
- end
234
- def file_server.actual_path_info
235
- @actual_path_info
236
- end
237
-
238
- # Create site
239
- site = mock
240
- site.expects(:items).returns([])
241
- site.expects(:config).at_least_once.returns({ output_dir: 'out', index_filenames: ['index.html'] })
242
-
243
- # Create autocompiler
244
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
245
- autocompiler.stubs(:build_site)
246
- autocompiler.stubs(:site).returns(site)
247
- autocompiler.expects(:file_server).returns(file_server)
248
-
249
- # Run
250
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => 'foo/bar') }
251
-
252
- # Check
253
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
254
- end
255
- end
256
-
257
- def test_handle_request_with_404
258
- if_have 'mime/types', 'rack' do
259
- # Create file server
260
- file_server = mock
261
- def file_server.call(env)
262
- @expected_path_info = 'four-oh-four.txt'
263
- @actual_path_info = env['PATH_INFO']
264
- end
265
- def file_server.expected_path_info
266
- @expected_path_info
267
- end
268
- def file_server.actual_path_info
269
- @actual_path_info
270
- end
271
-
272
- # Create site
273
- site = mock
274
- site.expects(:items).returns([])
275
- site.expects(:config).at_least_once.returns({ output_dir: 'out', index_filenames: ['index.html'] })
276
-
277
- # Create autocompiler
278
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
279
- autocompiler.stubs(:build_site)
280
- autocompiler.stubs(:site).returns(site)
281
- autocompiler.expects(:file_server).returns(file_server)
282
-
283
- # Run
284
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => 'four-oh-four.txt') }
285
-
286
- # Check
287
- assert_equal(file_server.expected_path_info, file_server.actual_path_info)
288
- end
289
- end
290
-
291
- def test_mime_type_of
292
- if_have 'mime/types', 'rack' do
293
- # Create autocompiler
294
- autocompiler = Nanoc::Extra::AutoCompiler.new(nil)
295
-
296
- # Create known test file
297
- File.open('foo.html', 'w') { |io| io.write('hello') }
298
- assert_equal(
299
- 'text/html',
300
- autocompiler.instance_eval { mime_type_of('foo.html', 'huh') }
301
- )
302
-
303
- # Create unknown test file
304
- File.open('foo', 'w') { |io| io.write('hello') }
305
- assert_equal(
306
- 'huh',
307
- autocompiler.instance_eval { mime_type_of('foo', 'huh') }
308
- )
309
- end
310
- end
311
-
312
- def test_serve_with_working_item
313
- if_have 'mime/types', 'rack' do
314
- # Create site
315
- Nanoc::CLI.run %w( create_site bar)
316
-
317
- FileUtils.cd('bar') do
318
- # Create item
319
- File.open('content/index.html', 'w') do |io|
320
- io.write 'Moo!'
321
- end
322
-
323
- # Create output file
324
- File.open('output/index.html', 'w') do |io|
325
- io.write 'Compiled moo!'
326
- end
327
-
328
- # Create site
329
- site = Nanoc::Site.new('.')
330
- site.expects(:compile)
331
-
332
- # Create autocompiler
333
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
334
- autocompiler.stubs(:build_site)
335
- autocompiler.stubs(:site).returns(site)
336
-
337
- # Serve
338
- status, headers, body = autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/') }
339
-
340
- # Check response
341
- assert_equal(200, status)
342
- assert_equal('text/html', headers['Content-Type'])
343
- body.each do |b|
344
- assert_equal 'Compiled moo!', b
345
- end
346
- end
347
- end
348
- end
349
-
350
- def test_serve_with_broken_item
351
- if_have 'mime/types', 'rack' do
352
- # Create site
353
- Nanoc::CLI.run %w( create_site bar)
354
-
355
- FileUtils.cd('bar') do
356
- # Create item
357
- File.open('content/whatever.html', 'w') do |io|
358
- io.write 'Whatever!'
359
- end
360
-
361
- # Create site
362
- site = Nanoc::Site.new('.')
363
- site.expects(:compile).raises(RuntimeError, 'aah! fail!')
364
-
365
- # Create autocompiler
366
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
367
- autocompiler.stubs(:build_site)
368
- autocompiler.stubs(:site).returns(site)
369
-
370
- # Serve
371
- assert_raises(RuntimeError) do
372
- autocompiler.instance_eval { call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/whatever/') }
373
- end
374
- end
375
- end
376
- end
377
-
378
- def test_reload_config_file_before_each_request
379
- if_have 'mime/types', 'rack' do
380
- # Create site
381
- Nanoc::CLI.run %w( create_site foo )
382
-
383
- FileUtils.cd('foo') do
384
- # Create item that outputs config elements
385
- File.open('content/index.html', 'w') do |io|
386
- io.write 'The Grand Value of Configuration is <%= @config[:value] %>!'
387
- end
388
-
389
- # Create autocompiler
390
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
391
-
392
- # Set config to 1st value
393
- File.open('nanoc.yaml', 'w') do |io|
394
- io.write 'value: Foo'
395
- end
396
- File.utime(Time.now + 5, Time.now + 5, 'nanoc.yaml')
397
-
398
- # Check
399
- _status, _headers, body = autocompiler.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/')
400
- body.each do |b|
401
- assert_match(/The Grand Value of Configuration is Foo!/, b)
402
- end
403
-
404
- # Set config to 2nd value
405
- File.open('nanoc.yaml', 'w') do |io|
406
- io.write 'value: Bar'
407
- end
408
- File.utime(Time.now + 5, Time.now + 5, 'nanoc.yaml')
409
-
410
- # Check
411
- _status, _headers, body = autocompiler.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/')
412
- body.each do |b|
413
- assert_match(/The Grand Value of Configuration is Bar!/, b)
414
- end
415
- end
416
- end
417
- end
418
-
419
- def test_call_with_uri_encoded_path
420
- if_have 'rack' do
421
- # Create autocompiler
422
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
423
-
424
- # Mock dependencies
425
- site = mock
426
- site.stubs(:config).returns({ output_dir: 'output/' })
427
- site.stubs(:items).returns([])
428
- autocompiler.stubs(:build_site)
429
- autocompiler.stubs(:site).returns(site)
430
-
431
- # Test
432
- result = autocompiler.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/%73oftware')
433
- assert_equal 404, result[0]
434
- assert_match("File not found: /software\n", result[2][0])
435
- end
436
- end
437
- end