nanoc 4.8.10 → 4.8.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/NEWS.md +7 -0
  4. data/lib/nanoc.rb +11 -6
  5. data/lib/nanoc/base.rb +1 -0
  6. data/lib/nanoc/base/changes_stream.rb +53 -0
  7. data/lib/nanoc/base/contracts_support.rb +0 -2
  8. data/lib/nanoc/base/feature.rb +3 -0
  9. data/lib/nanoc/base/memoization.rb +0 -2
  10. data/lib/nanoc/base/repos/aggregate_data_source.rb +8 -0
  11. data/lib/nanoc/base/repos/data_source.rb +12 -0
  12. data/lib/nanoc/base/repos/in_mem_data_source.rb +10 -1
  13. data/lib/nanoc/base/repos/prefixed_data_source.rb +8 -0
  14. data/lib/nanoc/base/repos/site_loader.rb +11 -7
  15. data/lib/nanoc/base/services/compiler.rb +2 -3
  16. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +2 -3
  17. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +1 -1
  18. data/lib/nanoc/base/services/pruner.rb +0 -2
  19. data/lib/nanoc/base/services/temp_filename_factory.rb +0 -2
  20. data/lib/nanoc/checking/checks/external_links.rb +0 -5
  21. data/lib/nanoc/checking/checks/internal_links.rb +0 -2
  22. data/lib/nanoc/checking/checks/stale.rb +0 -2
  23. data/lib/nanoc/cli.rb +7 -1
  24. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +0 -3
  25. data/lib/nanoc/cli/commands/live.rb +30 -0
  26. data/lib/nanoc/cli/commands/view.rb +4 -5
  27. data/lib/nanoc/cli/error_handler.rb +52 -36
  28. data/lib/nanoc/cli/logger.rb +0 -2
  29. data/lib/nanoc/cli/stack_trace_writer.rb +50 -0
  30. data/lib/nanoc/data_sources/filesystem.rb +25 -0
  31. data/lib/nanoc/extra.rb +1 -0
  32. data/lib/nanoc/extra/jruby_nokogiri_warner.rb +0 -2
  33. data/lib/nanoc/extra/link_collector.rb +0 -2
  34. data/lib/nanoc/extra/live_recompiler.rb +131 -0
  35. data/lib/nanoc/extra/parallel_collection.rb +0 -2
  36. data/lib/nanoc/extra/piper.rb +0 -2
  37. data/lib/nanoc/filters/relativize_paths.rb +8 -7
  38. data/lib/nanoc/helpers/link_to.rb +0 -2
  39. data/lib/nanoc/rule_dsl/action_provider.rb +2 -2
  40. data/lib/nanoc/version.rb +1 -1
  41. data/nanoc.gemspec +15 -4
  42. data/nanoc.manifest +545 -0
  43. data/spec/manifest_spec.rb +22 -0
  44. data/spec/nanoc/base/changes_stream_spec.rb +45 -0
  45. data/spec/nanoc/base/checksummer_spec.rb +0 -2
  46. data/spec/nanoc/base/directed_graph_spec.rb +66 -0
  47. data/spec/nanoc/base/entities/code_snippet_spec.rb +9 -0
  48. data/spec/nanoc/base/entities/context_spec.rb +26 -0
  49. data/spec/nanoc/base/entities/identifiable_collection_spec.rb +53 -0
  50. data/spec/nanoc/base/repos/aggregate_data_source_spec.rb +87 -0
  51. data/spec/nanoc/base/repos/data_source_spec.rb +95 -0
  52. data/spec/nanoc/base/repos/in_mem_data_source_spec.rb +39 -0
  53. data/spec/nanoc/base/repos/prefixed_data_source_spec.rb +39 -0
  54. data/spec/nanoc/cli/error_handler_spec.rb +43 -0
  55. data/spec/nanoc/cli/stack_trace_writer_spec.rb +156 -0
  56. data/spec/nanoc/data_sources/filesystem_spec.rb +46 -0
  57. data/spec/nanoc/extra/live_recompiler_spec.rb +129 -0
  58. data/spec/nanoc/helpers/blogging_spec.rb +1 -1
  59. data/spec/spec_helper.rb +60 -0
  60. data/test/base/test_compiler.rb +11 -11
  61. data/test/cli/test_cli.rb +0 -1
  62. data/test/cli/test_error_handler.rb +4 -5
  63. data/test/filters/test_relativize_paths.rb +30 -0
  64. data/test/filters/test_sass.rb +3 -3
  65. data/test/rule_dsl/test_compiler_dsl.rb +2 -2
  66. metadata +39 -43
  67. data/.github/CONTRIBUTING.md +0 -17
  68. data/.github/ISSUE_TEMPLATE.md +0 -23
  69. data/.github/PULL_REQUEST_TEMPLATE.md +0 -18
  70. data/.gitignore +0 -10
  71. data/.travis.yml +0 -27
  72. data/Gemfile +0 -73
  73. data/Guardfile +0 -5
  74. data/scripts/release +0 -95
  75. data/test/base/test_code_snippet.rb +0 -17
  76. data/test/base/test_context.rb +0 -35
  77. data/test/base/test_data_source.rb +0 -60
  78. data/test/base/test_directed_graph.rb +0 -56
  79. data/test/base/test_item_array.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 651f15c4ee22daacf31bab68c3ec1a00a02238f0
4
- data.tar.gz: 6a8a41fd4ecc345ebb70814cd9f7f89d0cd6decc
3
+ metadata.gz: 686e6a239ceae1d59678f267f4aa4c5dfc46b45e
4
+ data.tar.gz: e80de3bfc0c9475292ad4f9f4fa886f87bd272a8
5
5
  SHA512:
6
- metadata.gz: 0f9576114f97906cf843f19dcff2e84a45d4612165162e267ef10ab441e910b82fbaac55d1cc71f68d7add44214269c003eca73c31118119b7f9d238f08e3391
7
- data.tar.gz: 66be4b141524b69d045e636ecc01b33c69c9e7f4267eb8ff7a5a6978c2b7fbb9c1960bf6cd482458484a4477dfc1aeb1821a03d4ec3e358c2de3c2009b727792
6
+ metadata.gz: b476ce18ea4cdd880de849b64bc5c8bbe1287a1b3cbd67a7a54a0fa079812107d9448f839785b391ae192147f331facb47e89d828a65c896aae5dad8b40a5c08
7
+ data.tar.gz: 8ffcb7d57ea237b0fef6490828d960247fd618c814990e14f0f707a55831f8288b2666cc21693792452f3d9d1e475aa9c33cbebc6807405d7749cda3022fedc9
data/.rubocop.yml CHANGED
@@ -45,6 +45,7 @@ Lint/NestedMethodDefinition:
45
45
  Style/GlobalVars:
46
46
  Exclude:
47
47
  - 'test/**/*.rb'
48
+ - 'spec/**/*.rb'
48
49
 
49
50
 
50
51
 
@@ -165,3 +166,8 @@ Style/GuardClause:
165
166
  # Used for “undo work, whatever error happens”
166
167
  Lint/RescueWithoutErrorClass:
167
168
  Enabled: false
169
+
170
+ # For the sake of consistency, it makes the most sense to retain $stderr.puts
171
+ # when used in situations where $stderr.flush, $stderr.print, … are also used.
172
+ Style/StderrPuts:
173
+ Enabled: false
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.8.11 (2017-10-28)
4
+
5
+ Enhancements:
6
+
7
+ * Added `:save_with` parameter to `relativize_paths` filter (#1237) [Gregory Pakosz]
8
+ * Made error messages more compact and easier to read
9
+
3
10
  ## 4.8.10 (2017-10-08)
4
11
 
5
12
  Fixes:
data/lib/nanoc.rb CHANGED
@@ -19,28 +19,33 @@ module Nanoc
19
19
  end
20
20
 
21
21
  # Load external dependencies
22
+ require 'addressable'
23
+ require 'ddplugin'
22
24
  require 'hamster'
23
25
  require 'ref'
24
- require 'ddplugin'
25
- require 'addressable'
26
+ require 'slow_enumerator_tools'
26
27
 
27
28
  # Load general requirements
28
29
  require 'cgi'
29
30
  require 'digest'
30
- require 'enumerator'
31
+ require 'English'
31
32
  require 'fiber'
32
33
  require 'fileutils'
34
+ require 'find'
33
35
  require 'forwardable'
36
+ require 'net/http'
37
+ require 'net/https'
38
+ require 'open3'
34
39
  require 'pathname'
35
40
  require 'pstore'
36
41
  require 'set'
37
42
  require 'singleton'
38
43
  require 'tempfile'
39
- require 'thread'
40
44
  require 'time'
41
- require 'yaml'
45
+ require 'timeout'
46
+ require 'tmpdir'
42
47
  require 'uri'
43
- require 'English'
48
+ require 'yaml'
44
49
 
45
50
  # Load Nanoc
46
51
  require 'nanoc/version'
data/lib/nanoc/base.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'base/contracts_support'
9
9
  require_relative 'base/memoization'
10
10
  require_relative 'base/error'
11
11
  require_relative 'base/errors'
12
+ require_relative 'base/changes_stream'
12
13
 
13
14
  require_relative 'base/entities'
14
15
  require_relative 'base/feature'
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ class ChangesStream
5
+ class ChangesListener
6
+ def initialize(y)
7
+ @y = y
8
+ end
9
+
10
+ def unknown
11
+ @y << :unknown
12
+ end
13
+
14
+ def lib
15
+ @y << :lib
16
+ end
17
+
18
+ def to_stop(&block)
19
+ if block_given?
20
+ @to_stop = block
21
+ else
22
+ @to_stop
23
+ end
24
+ end
25
+ end
26
+
27
+ def initialize(enum: nil)
28
+ @enum = enum
29
+ @enum ||=
30
+ Enumerator.new do |y|
31
+ @listener = ChangesListener.new(y)
32
+ yield(@listener)
33
+ end.lazy
34
+ end
35
+
36
+ def stop
37
+ @listener&.to_stop&.call
38
+ end
39
+
40
+ def map
41
+ self.class.new(enum: @enum.map { |e| yield(e) })
42
+ end
43
+
44
+ def to_enum
45
+ @enum
46
+ end
47
+
48
+ def each
49
+ @enum.each { |e| yield(e) }
50
+ nil
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'singleton'
4
-
5
3
  module Nanoc::Int
6
4
  # @api private
7
5
  module ContractsSupport
@@ -90,3 +90,6 @@ module Nanoc
90
90
  end
91
91
  end
92
92
  end
93
+
94
+ Nanoc::Feature.define('live_cmd', version: '4.8')
95
+ Nanoc::Feature.define('sensible_stack_traces', version: '4.8')
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'weakref'
4
-
5
3
  module Nanoc::Int
6
4
  # Adds support for memoizing functions.
7
5
  #
@@ -22,5 +22,13 @@ module Nanoc::Int
22
22
  Nanoc::Int::LayoutCollection.new(@config, objs)
23
23
  end
24
24
  end
25
+
26
+ def item_changes
27
+ SlowEnumeratorTools.merge(@data_sources.map(&:item_changes))
28
+ end
29
+
30
+ def layout_changes
31
+ SlowEnumeratorTools.merge(@data_sources.map(&:layout_changes))
32
+ end
25
33
  end
26
34
  end
@@ -98,6 +98,18 @@ module Nanoc
98
98
  []
99
99
  end
100
100
 
101
+ # @api private
102
+ def item_changes
103
+ warn "Caution: Data source #{self.class.identifier.inspect} does not implement #item_changes; live compilation will not pick up changes in this data source."
104
+ Enumerator.new { |_y| sleep }
105
+ end
106
+
107
+ # @api private
108
+ def layout_changes
109
+ warn "Caution: Data source #{self.class.identifier.inspect} does not implement #layout_changes; live compilation will not pick up changes in this data source."
110
+ Enumerator.new { |_y| sleep }
111
+ end
112
+
101
113
  # Returns the collection of layouts (represented by {Nanoc::Int::Layout}) in
102
114
  # this site. The default implementation simply returns an empty array.
103
115
  #
@@ -5,11 +5,20 @@ module Nanoc::Int
5
5
  attr_reader :items
6
6
  attr_reader :layouts
7
7
 
8
- def initialize(items, layouts)
8
+ def initialize(items, layouts, orig_data_source = nil)
9
9
  super({}, '/', '/', {})
10
10
 
11
11
  @items = items
12
12
  @layouts = layouts
13
+ @orig_data_source = orig_data_source
14
+ end
15
+
16
+ def item_changes
17
+ @orig_data_source ? @orig_data_source.item_changes : super
18
+ end
19
+
20
+ def layout_changes
21
+ @orig_data_source ? @orig_data_source.layout_changes : super
13
22
  end
14
23
  end
15
24
  end
@@ -17,5 +17,13 @@ module Nanoc::Int
17
17
  def layouts
18
18
  @data_source.layouts.map { |d| d.with_identifier_prefix(@layouts_prefix) }
19
19
  end
20
+
21
+ def item_changes
22
+ @data_source.item_changes
23
+ end
24
+
25
+ def layout_changes
26
+ @data_source.layout_changes
27
+ end
20
28
  end
21
29
  end
@@ -19,12 +19,7 @@ module Nanoc::Int
19
19
  Nanoc::Int::ConfigLoader.cwd_is_nanoc_site?
20
20
  end
21
21
 
22
- private
23
-
24
- def site_from_config(config)
25
- code_snippets = code_snippets_from_config(config)
26
- code_snippets.each(&:load)
27
-
22
+ def gen_data_source_for_config(config)
28
23
  data_sources_to_aggregate =
29
24
  with_data_sources(config) do |data_sources|
30
25
  data_sources.map do |ds|
@@ -32,7 +27,16 @@ module Nanoc::Int
32
27
  end
33
28
  end
34
29
 
35
- data_source = Nanoc::Int::AggregateDataSource.new(data_sources_to_aggregate, config)
30
+ Nanoc::Int::AggregateDataSource.new(data_sources_to_aggregate, config)
31
+ end
32
+
33
+ private
34
+
35
+ def site_from_config(config)
36
+ code_snippets = code_snippets_from_config(config)
37
+ code_snippets.each(&:load)
38
+
39
+ data_source = gen_data_source_for_config(config)
36
40
 
37
41
  Nanoc::Int::Site.new(
38
42
  config: config,
@@ -78,7 +78,7 @@ module Nanoc::Int
78
78
  run_stage(prune_stage(reps))
79
79
  run_stage(compile_reps_stage(action_sequences, reps))
80
80
  run_stage(store_post_compilation_state_stage)
81
- run_stage(postprocess_stage(reps), self)
81
+ run_stage(postprocess_stage, self)
82
82
  ensure
83
83
  run_stage(cleanup_stage)
84
84
  end
@@ -191,11 +191,10 @@ module Nanoc::Int
191
191
  )
192
192
  end
193
193
 
194
- def postprocess_stage(reps)
194
+ def postprocess_stage
195
195
  @_postprocess_stage ||= Stages::Postprocess.new(
196
196
  action_provider: @action_provider,
197
197
  site: @site,
198
- reps: reps,
199
198
  )
200
199
  end
201
200
 
@@ -4,15 +4,14 @@ module Nanoc::Int::Compiler::Stages
4
4
  class Postprocess
5
5
  include Nanoc::Int::ContractsSupport
6
6
 
7
- def initialize(action_provider:, site:, reps:)
7
+ def initialize(action_provider:, site:)
8
8
  @action_provider = action_provider
9
9
  @site = site
10
- @reps = reps
11
10
  end
12
11
 
13
12
  contract Nanoc::Int::Compiler => C::Any
14
13
  def run(compiler)
15
- @action_provider.postprocess(@site, compiler, @reps)
14
+ @action_provider.postprocess(@site, compiler)
16
15
  end
17
16
  end
18
17
  end
@@ -13,7 +13,7 @@ module Nanoc::Int::Compiler::Stages
13
13
  return if @site.preprocessed?
14
14
 
15
15
  if @action_provider.need_preprocessing?
16
- @site.data_source = Nanoc::Int::InMemDataSource.new(@site.items, @site.layouts)
16
+ @site.data_source = Nanoc::Int::InMemDataSource.new(@site.items, @site.layouts, @site.data_source)
17
17
  @action_provider.preprocess(@site)
18
18
 
19
19
  @dependency_store.items = @site.items
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'find'
4
-
5
3
  module Nanoc
6
4
  # Responsible for finding and deleting files in the site’s output directory
7
5
  # that are not managed by Nanoc.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tmpdir'
4
-
5
3
  module Nanoc::Int
6
4
  # @api private
7
5
  class TempFilenameFactory
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
- require 'net/https'
5
- require 'timeout'
6
- require 'uri'
7
-
8
3
  module ::Nanoc::Checking::Checks
9
4
  # A validator that verifies that all external links point to a location that exists.
10
5
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
4
-
5
3
  module Nanoc::Checking::Checks
6
4
  # A check that verifies that all internal links point to a location that exists.
7
5
  #
@@ -6,8 +6,6 @@ module Nanoc::Checking::Checks
6
6
  identifier :stale
7
7
 
8
8
  def run
9
- require 'set'
10
-
11
9
  output_filenames.each do |f|
12
10
  next if pruner.filename_excluded?(f)
13
11
  next if item_rep_paths.include?(f)
data/lib/nanoc/cli.rb CHANGED
@@ -20,6 +20,7 @@ require_relative 'cli/command_runner'
20
20
  require_relative 'cli/cleaning_stream'
21
21
  require_relative 'cli/stream_cleaners'
22
22
  require_relative 'cli/error_handler'
23
+ require_relative 'cli/stack_trace_writer'
23
24
 
24
25
  require_relative 'cli/commands/compile_listeners/abstract'
25
26
  require_relative 'cli/commands/compile_listeners/debug_printer'
@@ -113,7 +114,12 @@ module Nanoc::CLI
113
114
  # Add other commands
114
115
  cmd_filenames = Dir[__dir__ + '/cli/commands/*.rb']
115
116
  cmd_filenames.each do |cmd_filename|
116
- next if File.basename(cmd_filename, '.rb') == 'nanoc'
117
+ basename = File.basename(cmd_filename, '.rb')
118
+
119
+ next if basename == 'nanoc'
120
+
121
+ next if basename == 'live' && !Nanoc::Feature.enabled?(Nanoc::Feature::LIVE_CMD)
122
+
117
123
  cmd = load_command_at(cmd_filename)
118
124
  add_command(cmd)
119
125
  end
@@ -9,7 +9,6 @@ module Nanoc::CLI::Commands::CompileListeners
9
9
 
10
10
  # @see Listener#start
11
11
  def start
12
- require 'tempfile'
13
12
  setup_diffs
14
13
  old_contents = {}
15
14
  Nanoc::Int::NotificationCenter.on(:will_write_rep, self) do |rep, path|
@@ -65,8 +64,6 @@ module Nanoc::CLI::Commands::CompileListeners
65
64
  end
66
65
 
67
66
  def diff_strings(a, b)
68
- require 'open3'
69
-
70
67
  # Create files
71
68
  Tempfile.open('old') do |old_file|
72
69
  Tempfile.open('new') do |new_file|
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ usage 'live'
4
+ summary 'auto-recompile and serve'
5
+ description <<~EOS
6
+ Starts the live recompiler along with the static web server. Unless specified,
7
+ the web server will run on port 3000 and listen on all IP addresses. Running
8
+ this static web server requires `adsf` (not `asdf`!).
9
+ EOS
10
+
11
+ required :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
12
+ required :o, :host, 'specify the host to listen on (default: 127.0.0.1)'
13
+ required :p, :port, 'specify the port to listen on (default: 3000)'
14
+
15
+ module Nanoc::CLI::Commands
16
+ class Live < ::Nanoc::CLI::CommandRunner
17
+ def run
18
+ self.class.enter_site_dir
19
+
20
+ Thread.new do
21
+ Thread.current.abort_on_exception = true
22
+ Nanoc::CLI::Commands::View.new(options, [], self).run
23
+ end
24
+
25
+ Nanoc::Extra::LiveRecompiler.new(command_runner: self).run
26
+ end
27
+ end
28
+ end
29
+
30
+ runner Nanoc::CLI::Commands::Live