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,69 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'autocompile [options]'
4
- summary 'start the autocompiler'
5
- be_hidden
6
- aliases :aco
7
- description <<-EOS
8
- Start the autocompiler web server. Unless overridden with command-line options
9
- or configuration entries, the web server will run on port 3000 and listen on all
10
- IP addresses. Running the autocompiler requires the `mime/types` and `rack` gems.
11
-
12
- To specify the host, port, and/or handler options in config.yaml, you can add
13
- any of the following:
14
-
15
- autocompile:
16
- host: '10.0.2.0' # override the default host
17
- port: 4000 # override the default port
18
- handler: thin # override the default handler
19
-
20
- EOS
21
-
22
- required :H, :handler, 'specify the handler to use (webrick/mongrel/…)'
23
- required :o, :host, 'specify the host to listen on (default: 0.0.0.0)'
24
- required :p, :port, 'specify the port to listen on (default: 3000)'
25
-
26
- module Nanoc::CLI::Commands
27
- class AutoCompile < ::Nanoc::CLI::CommandRunner
28
- def run
29
- warn 'WARNING: The `autocompile` command is deprecated. Please consider using `guard-nanoc` instead (see https://github.com/nanoc/guard-nanoc).'
30
-
31
- require 'rack'
32
-
33
- # Make sure we are in a nanoc site directory
34
- require_site
35
- autocompile_config = site.config[:autocompile] || {}
36
-
37
- # Set options
38
- options_for_rack = {
39
- Port: (options[:port] || autocompile_config[:port] || 3000).to_i,
40
- Host: (options[:host] || autocompile_config[:host] || '0.0.0.0')
41
- }
42
-
43
- # Guess which handler we should use
44
- handler_option = options[:handler] || autocompile_config[:handler]
45
- handler = Rack::Handler.get(handler_option)
46
- unless handler
47
- begin
48
- handler = Rack::Handler::Mongrel
49
- rescue LoadError
50
- handler = Rack::Handler::WEBrick
51
- end
52
- end
53
-
54
- # Build app
55
- autocompiler = Nanoc::Extra::AutoCompiler.new('.')
56
- app = Rack::Builder.new do
57
- use Rack::CommonLogger, $stderr
58
- use Rack::ShowExceptions
59
- run autocompiler
60
- end.to_app
61
-
62
- # Run autocompiler
63
- puts "Running on http://#{options_for_rack[:Host]}:#{options_for_rack[:Port]}/"
64
- handler.run(app, options_for_rack)
65
- end
66
- end
67
- end
68
-
69
- runner Nanoc::CLI::Commands::AutoCompile
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'create-item [options] identifier'
4
- aliases :create_item, :ci
5
- summary 'create an item'
6
- description <<-EOS
7
- Create a new item in the current site. The first data source in the site
8
- configuration will be used.
9
- EOS
10
-
11
- required :c, :vcs, 'specify the VCS to use'
12
-
13
- module Nanoc::CLI::Commands
14
- class CreateItem < ::Nanoc::CLI::CommandRunner
15
- def run
16
- # Check arguments
17
- if arguments.length != 1
18
- raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}"
19
- end
20
-
21
- # Extract arguments and options
22
- identifier = arguments[0].cleaned_identifier
23
-
24
- # Make sure we are in a nanoc site directory
25
- require_site
26
-
27
- # Set VCS if possible
28
- set_vcs(options[:vcs])
29
-
30
- # Check whether item is unique
31
- unless site.items.find { |i| i.identifier == identifier }.nil?
32
- raise Nanoc::Errors::GenericTrivial,
33
- "An item already exists at #{identifier}. Please " \
34
- 'pick a unique name for the item you are creating.'
35
- end
36
-
37
- # Setup notifications
38
- Nanoc::NotificationCenter.on(:file_created) do |file_path|
39
- Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
40
- end
41
-
42
- # Create item
43
- data_source = site.data_sources[0]
44
- data_source.create_item(
45
- "Hi, I'm a new item!\n",
46
- { title: 'A New Item' },
47
- identifier
48
- )
49
-
50
- puts "An item has been created at #{identifier}."
51
- end
52
- end
53
- end
54
-
55
- runner Nanoc::CLI::Commands::CreateItem
@@ -1,68 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'create-layout [options] identifier'
4
- aliases :create_layout, :cl
5
- summary 'create a layout'
6
- description <<-EOS
7
- Create a new layout in the current site. The first data source in the site
8
- configuration will be used.
9
- EOS
10
-
11
- module Nanoc::CLI::Commands
12
- class CreateLayout < ::Nanoc::CLI::CommandRunner
13
- def run
14
- # Check arguments
15
- if arguments.length != 1
16
- raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}"
17
- end
18
-
19
- # Extract arguments
20
- identifier = arguments[0].cleaned_identifier
21
-
22
- # Make sure we are in a nanoc site directory
23
- require_site
24
-
25
- # Set VCS if possible
26
- set_vcs(options[:vcs])
27
-
28
- # Check whether layout is unique
29
- unless site.layouts.find { |l| l.identifier == identifier }.nil?
30
- raise Nanoc::Errors::GenericTrivial,
31
- "A layout already exists at #{identifier}. Please " \
32
- 'pick a unique name for the layout you are creating.'
33
- end
34
-
35
- # Check whether layout is not at /
36
- if identifier == '/'
37
- raise Nanoc::Errors::GenericTrivial,
38
- "There cannot be a layout with the identifier '/'; " \
39
- 'please pick a different identifier for this layout.'
40
- end
41
-
42
- # Setup notifications
43
- Nanoc::NotificationCenter.on(:file_created) do |file_path|
44
- Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
45
- end
46
-
47
- # Create layout
48
- data_source = site.data_sources[0]
49
- data_source.create_layout(
50
- "<html>\n" \
51
- " <head>\n" \
52
- " <title><%= @item[:title] %></title>\n" \
53
- " </head>\n" \
54
- " <body>\n" \
55
- " <p>Hi, I'm a new layout. Please customize me!</p>\n" \
56
- "<%= yield %>\n" \
57
- " </body>\n" \
58
- "</html>\n",
59
- {},
60
- identifier
61
- )
62
-
63
- puts "A layout has been created at #{identifier}."
64
- end
65
- end
66
- end
67
-
68
- runner Nanoc::CLI::Commands::CreateLayout
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'sync'
4
- summary 'sync data sources'
5
- description <<-EOS
6
- Sync data source data. This command is useful for updating local item caches
7
- for data sources which rely on slow external APIs.
8
- EOS
9
-
10
- module Nanoc::CLI::Commands
11
- class Sync < ::Nanoc::CLI::CommandRunner
12
- def run
13
- # Check arguments
14
- if arguments.size != 0
15
- raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}"
16
- end
17
-
18
- # Make sure we are in a nanoc site directory
19
- require_site
20
-
21
- # Update all syncable data sources
22
- site.data_sources.each do |data_source|
23
- unless data_source.method(:sync).owner == Nanoc::DataSource
24
- puts "Syncing #{data_source.config[:type]} data source: #{data_source.items_root}"
25
- data_source.sync
26
- end
27
- end
28
- end
29
- end
30
- end
31
-
32
- runner Nanoc::CLI::Commands::Sync
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'update [options]'
4
- summary 'update the data stored by the data source to a newer version'
5
- description <<-EOS
6
- Update the data stored by the data source to a newer format. The format in
7
- which data is stored can change between releases, and even though backward
8
- compatibility is usually preserved, it is often a good idea to store the site
9
- data in a newer format so newer features can be taken advantage of.
10
-
11
- This command will change data, and it is therefore recommended to make a
12
- backup in case something goes wrong.
13
- EOS
14
-
15
- required :c, :vcs, 'select the VCS to use'
16
- flag :y, :yes, 'update the data without warning'
17
-
18
- module Nanoc::CLI::Commands
19
- class Update < ::Nanoc::CLI::CommandRunner
20
- def run
21
- # Check arguments
22
- if arguments.size != 0
23
- raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}"
24
- end
25
-
26
- # Make sure we are in a nanoc site directory
27
- require_site
28
-
29
- # Set VCS if possible
30
- set_vcs(options[:vcs])
31
-
32
- # Check for -y switch
33
- unless options.key?(:yes)
34
- $stderr.puts '*************'
35
- $stderr.puts '** WARNING **'
36
- $stderr.puts '*************'
37
- $stderr.puts
38
- $stderr.puts 'Are you absolutely sure you want to update the ' \
39
- 'content for this site? Updating the site content ' \
40
- 'will change the structure of existing data. This ' \
41
- 'operation is destructive and cannot be reverted. ' \
42
- 'Please do not interrupt this operation; doing so can ' \
43
- 'result in data loss. As always, consider making a ' \
44
- 'backup copy.'
45
- $stderr.puts
46
- $stderr.puts 'If this nanoc site is versioned using a VCS ' \
47
- 'supported by nanoc, consider using the --vcs option ' \
48
- 'to have nanoc perform add/delete/move operations ' \
49
- 'using the specified VCS. To get a list of VCSes ' \
50
- 'supported by nanoc, issue the "info" command.'
51
- $stderr.puts
52
- $stderr.puts 'To continue, use the -y/--yes option, like "nanoc ' \
53
- 'update -y".'
54
- exit 1
55
- end
56
-
57
- # Update
58
- site.data_sources.each(&:update)
59
- end
60
- end
61
- end
62
-
63
- runner Nanoc::CLI::Commands::Update
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'validate-css [options]'
4
- aliases :validate_css, :vcss
5
- summary 'validate the site’s CSS'
6
- be_hidden
7
- description "
8
- Validates the site’s CSS files.
9
- "
10
-
11
- module Nanoc::CLI::Commands
12
- class ValidateCSS < ::Nanoc::CLI::CommandRunner
13
- def run
14
- warn 'The `validate-css` command is deprecated. Please use the new `check` command instead.'
15
- Nanoc::CLI.run %w( check css )
16
- end
17
- end
18
- end
19
-
20
- runner Nanoc::CLI::Commands::ValidateCSS
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'validate-html [options]'
4
- aliases :validate_html, :vhtml
5
- summary 'validate the site’s HTML'
6
- be_hidden
7
- description "
8
- Validates the site’s HTML files.
9
- "
10
-
11
- module Nanoc::CLI::Commands
12
- class ValidateHTML < ::Nanoc::CLI::CommandRunner
13
- def run
14
- warn 'The `validate-html` command is deprecated. Please use the new `check` command instead.'
15
- Nanoc::CLI.run %w( check html )
16
- end
17
- end
18
- end
19
-
20
- runner Nanoc::CLI::Commands::ValidateHTML
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'validate-links [options]'
4
- aliases :validate_links, :vlink
5
- summary 'validate links in site'
6
- be_hidden
7
- description "
8
- Validates the site’s links. By default, both internal and external links will be checked.
9
- "
10
-
11
- flag :i, :internal, 'validate internal links only'
12
- flag :e, :external, 'validate external links only'
13
-
14
- module Nanoc::CLI::Commands
15
- class ValidateLinks < ::Nanoc::CLI::CommandRunner
16
- def run
17
- warn 'The `validate-links` command is deprecated. Please use the new `check` command instead.'
18
-
19
- checks = []
20
- checks << 'ilinks' if options[:internal]
21
- checks << 'elinks' if options[:external]
22
- Nanoc::CLI.run ['check', checks].flatten
23
- end
24
- end
25
- end
26
-
27
- runner Nanoc::CLI::Commands::ValidateLinks
@@ -1,176 +0,0 @@
1
- # encoding: utf-8
2
-
3
- usage 'watch [options]'
4
- summary 'start the watcher'
5
- be_hidden
6
- description <<-EOS
7
- Start the watcher. When a change is detected, the site will be recompiled.
8
- EOS
9
-
10
- module Nanoc::CLI::Commands
11
- class Watch < ::Nanoc::CLI::CommandRunner
12
- def run
13
- warn 'WARNING: The `watch` command is deprecated. Please consider using `guard-nanoc` instead (see https://github.com/nanoc/guard-nanoc).'
14
-
15
- require 'listen'
16
- require 'pathname'
17
-
18
- require_site
19
- watcher_config = site.config[:watcher] || {}
20
-
21
- @notifier = Notifier.new
22
-
23
- # Define rebuilder
24
- rebuilder = lambda do |file_path|
25
- # Determine filename
26
- if file_path.nil?
27
- filename = nil
28
- else
29
- filename = ::Pathname.new(file_path).relative_path_from(::Pathname.new(Dir.getwd)).to_s
30
- end
31
-
32
- # Notify
33
- if filename
34
- print "Change detected to #{filename}; recompiling… "
35
- else
36
- print 'Watcher started; compiling the entire site… '
37
- end
38
-
39
- # Recompile
40
- start = Time.now
41
- site = Nanoc::Site.new('.')
42
- begin
43
- site.compile
44
-
45
- # TODO: include icon (--image misc/success-icon.png)
46
- notify_on_compilation_success = watcher_config.fetch(:notify_on_compilation_success) { true }
47
- if notify_on_compilation_success
48
- @notifier.notify('Compilation complete')
49
- end
50
-
51
- time_spent = ((Time.now - start) * 1000.0).round
52
- puts "done in #{format '%is %ims', *(time_spent.divmod(1000))}"
53
- rescue Exception => e
54
- # TODO: include icon (--image misc/error-icon.png)
55
- notify_on_compilation_failure = watcher_config.fetch(:notify_on_compilation_failure) { true }
56
- if notify_on_compilation_failure
57
- @notifier.notify('Compilation failed')
58
- end
59
-
60
- puts
61
- Nanoc::CLI::ErrorHandler.print_error(e)
62
- puts
63
- end
64
- end
65
-
66
- # Rebuild once
67
- rebuilder.call(nil)
68
-
69
- # Get directories to watch
70
- dirs_to_watch = watcher_config.fetch(:dirs_to_watch, %w( content layouts lib ))
71
- files_to_watch = watcher_config.fetch(:files_to_watch, %w( nanoc.yaml config.yaml Rules rules Rules.rb rules.rb ))
72
- files_to_watch = Regexp.new(files_to_watch.map { |name| Regexp.quote(name) + '$' }.join('|'))
73
- ignore_dir = Regexp.new(Dir.glob('*').map { |dir| dir if File.directory?(dir) }.compact.join('|'))
74
-
75
- # Watch
76
- puts 'Watching for changes…'
77
-
78
- callback = proc do |modified, added, removed|
79
- rebuilder.call(modified[0]) if modified[0]
80
- rebuilder.call(added[0]) if added[0]
81
- rebuilder.call(removed[0]) if removed[0]
82
- end
83
-
84
- listener = Listen::Listener.new(*dirs_to_watch).change(&callback)
85
- listener_root = Listen::Listener.new('.', filter: files_to_watch, ignore: ignore_dir).change(&callback)
86
-
87
- begin
88
- listener_root.start
89
- listener.start!
90
- rescue Interrupt
91
- listener.stop
92
- listener_root.stop
93
- end
94
- end
95
-
96
- # Allows sending user notifications in a cross-platform way.
97
- class Notifier
98
- # A list of command-line tool names that can be used to send notifications
99
- TOOLS = %w( growlnotify notify-send ) unless defined? TOOLS
100
-
101
- # Send a notification. If no notifier is found, no notification will be
102
- # created.
103
- #
104
- # @param [String] message The message to include in the notification
105
- def notify(message)
106
- return if tool.nil?
107
- if tool == 'growlnotify' && self.on_windows?
108
- growlnotify_windows(message)
109
- else
110
- send(tool.tr('-', '_'), message)
111
- end
112
- end
113
-
114
- protected
115
-
116
- def nix_tool_present?(tool)
117
- !`which #{tool}`.empty?
118
- rescue Errno::ENOENT
119
- false
120
- end
121
-
122
- def windows_tool_present?(tool)
123
- !`where #{tool} 2> nul`.empty?
124
- rescue Errno::ENOENT
125
- false
126
- end
127
-
128
- def tool_present?(tool)
129
- if self.on_windows?
130
- self.windows_tool_present?(tool)
131
- else
132
- self.nix_tool_present?(tool)
133
- end
134
- end
135
-
136
- def tool
137
- @tool ||= begin
138
- require 'terminal-notifier'
139
- 'terminal-notify'
140
- rescue LoadError
141
- TOOLS.find { |t| tool_present?(t) }
142
- end
143
- end
144
-
145
- def terminal_notify(message)
146
- TerminalNotifier.notify(message, title: 'nanoc')
147
- end
148
-
149
- def growlnotify_cmd_for(message)
150
- ['growlnotify', '-m', message]
151
- end
152
-
153
- def growlnotify(message)
154
- system(*growlnotify_cmd_for(message))
155
- end
156
-
157
- def growlnotify_windows_cmd_for(message)
158
- ['growlnotify', '/t:nanoc', message]
159
- end
160
-
161
- def growlnotify_windows(message)
162
- system(*growlnotify_windows_cmd_for(message))
163
- end
164
-
165
- def notify_send(message)
166
- system('notify-send', message)
167
- end
168
-
169
- def on_windows?
170
- Nanoc.on_windows?
171
- end
172
- end
173
- end
174
- end
175
-
176
- runner Nanoc::CLI::Commands::Watch