nanoc 4.11.0 → 4.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +6 -0
  3. data/lib/nanoc.rb +4 -7
  4. data/lib/nanoc/base.rb +3 -3
  5. data/lib/nanoc/base/assertions.rb +1 -1
  6. data/lib/nanoc/base/entities.rb +2 -20
  7. data/lib/nanoc/base/entities/action_sequence.rb +60 -64
  8. data/lib/nanoc/base/entities/checksum_collection.rb +23 -21
  9. data/lib/nanoc/base/entities/dependency.rb +24 -22
  10. data/lib/nanoc/base/entities/outdatedness_reasons.rb +74 -72
  11. data/lib/nanoc/base/entities/outdatedness_status.rb +19 -17
  12. data/lib/nanoc/base/entities/props.rb +119 -117
  13. data/lib/nanoc/base/entities/site.rb +46 -50
  14. data/lib/nanoc/base/errors.rb +183 -198
  15. data/lib/nanoc/base/repos.rb +4 -2
  16. data/lib/nanoc/base/repos/action_sequence_store.rb +44 -42
  17. data/lib/nanoc/base/repos/aggregate_data_source.rb +24 -22
  18. data/lib/nanoc/base/repos/checksum_store.rb +51 -49
  19. data/lib/nanoc/base/repos/compiled_content_cache.rb +47 -45
  20. data/lib/nanoc/base/repos/compiled_content_store.rb +76 -0
  21. data/lib/nanoc/base/repos/config_loader.rb +74 -72
  22. data/lib/nanoc/base/repos/dependency_store.rb +174 -172
  23. data/lib/nanoc/base/repos/in_mem_data_source.rb +17 -15
  24. data/lib/nanoc/base/repos/item_rep_repo.rb +26 -24
  25. data/lib/nanoc/base/repos/outdatedness_store.rb +50 -48
  26. data/lib/nanoc/base/repos/prefixed_data_source.rb +21 -19
  27. data/lib/nanoc/base/repos/site_loader.rb +75 -73
  28. data/lib/nanoc/base/repos/store.rb +93 -91
  29. data/lib/nanoc/base/services.rb +7 -3
  30. data/lib/nanoc/base/services/action_provider.rb +23 -21
  31. data/lib/nanoc/base/services/action_sequence_builder.rb +42 -34
  32. data/lib/nanoc/base/services/compilation_context.rb +49 -47
  33. data/lib/nanoc/base/services/compiler.rb +177 -170
  34. data/lib/nanoc/base/services/compiler/phases.rb +8 -1
  35. data/lib/nanoc/base/services/compiler/phases/abstract.rb +44 -38
  36. data/lib/nanoc/base/services/compiler/phases/cache.rb +34 -28
  37. data/lib/nanoc/base/services/compiler/phases/mark_done.rb +17 -11
  38. data/lib/nanoc/base/services/compiler/phases/notify.rb +21 -0
  39. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +37 -31
  40. data/lib/nanoc/base/services/compiler/phases/resume.rb +47 -48
  41. data/lib/nanoc/base/services/compiler/phases/write.rb +65 -59
  42. data/lib/nanoc/base/services/compiler/stage.rb +27 -8
  43. data/lib/nanoc/base/services/compiler/stages.rb +7 -1
  44. data/lib/nanoc/base/services/compiler/stages/build_reps.rb +25 -19
  45. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +34 -28
  46. data/lib/nanoc/base/services/compiler/stages/cleanup.rb +33 -27
  47. data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +79 -69
  48. data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +46 -40
  49. data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +15 -9
  50. data/lib/nanoc/base/services/compiler/stages/load_stores.rb +28 -22
  51. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +16 -10
  52. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +25 -19
  53. data/lib/nanoc/base/services/compiler/stages/prune.rb +23 -17
  54. data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +15 -9
  55. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +26 -20
  56. data/lib/nanoc/base/services/compiler_loader.rb +26 -24
  57. data/lib/nanoc/base/services/dependency_tracker.rb +47 -45
  58. data/lib/nanoc/base/services/executor.rb +16 -15
  59. data/lib/nanoc/base/services/filter.rb +37 -5
  60. data/lib/nanoc/base/services/instrumentor.rb +12 -10
  61. data/lib/nanoc/base/services/item_rep_builder.rb +21 -19
  62. data/lib/nanoc/base/services/item_rep_router.rb +72 -70
  63. data/lib/nanoc/base/services/item_rep_selector.rb +48 -46
  64. data/lib/nanoc/base/services/item_rep_writer.rb +58 -53
  65. data/lib/nanoc/base/services/outdatedness_checker.rb +181 -179
  66. data/lib/nanoc/base/services/outdatedness_rule.rb +23 -21
  67. data/lib/nanoc/base/services/outdatedness_rules.rb +5 -3
  68. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +28 -24
  69. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +20 -16
  70. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +13 -9
  71. data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +12 -8
  72. data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +12 -8
  73. data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +10 -6
  74. data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +39 -35
  75. data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +19 -15
  76. data/lib/nanoc/base/services/pruner.rb +2 -2
  77. data/lib/nanoc/base/views.rb +7 -0
  78. data/lib/nanoc/base/views/basic_item_view.rb +1 -1
  79. data/lib/nanoc/base/views/compilation_item_rep_view.rb +2 -2
  80. data/lib/nanoc/base/views/identifiable_collection_view.rb +2 -2
  81. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +1 -1
  82. data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +5 -5
  83. data/lib/nanoc/base/views/mutable_item_collection_view.rb +3 -3
  84. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +2 -2
  85. data/lib/nanoc/base/views/view_context_for_compilation.rb +6 -6
  86. data/lib/nanoc/base/views/view_context_for_pre_compilation.rb +2 -2
  87. data/lib/nanoc/base/views/view_context_for_shell.rb +2 -2
  88. data/lib/nanoc/checking/check.rb +1 -1
  89. data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +24 -7
  90. data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +79 -15
  91. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +4 -7
  92. data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +15 -24
  93. data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +22 -18
  94. data/lib/nanoc/cli/commands/create-site.rb +2 -7
  95. data/lib/nanoc/cli/commands/shell.rb +1 -1
  96. data/lib/nanoc/cli/commands/show-data.rb +9 -9
  97. data/lib/nanoc/cli/logger.rb +1 -1
  98. data/lib/nanoc/data_sources/filesystem.rb +8 -8
  99. data/lib/nanoc/filters/erb.rb +1 -1
  100. data/lib/nanoc/filters/erubi.rb +1 -1
  101. data/lib/nanoc/filters/erubis.rb +1 -1
  102. data/lib/nanoc/filters/haml.rb +1 -1
  103. data/lib/nanoc/filters/sass.rb +1 -1
  104. data/lib/nanoc/filters/slim.rb +1 -1
  105. data/lib/nanoc/helpers/breadcrumbs.rb +2 -2
  106. data/lib/nanoc/helpers/capturing.rb +9 -8
  107. data/lib/nanoc/helpers/filtering.rb +2 -2
  108. data/lib/nanoc/helpers/rendering.rb +1 -1
  109. data/lib/nanoc/rule_dsl.rb +10 -0
  110. data/lib/nanoc/rule_dsl/action_provider.rb +3 -3
  111. data/lib/nanoc/rule_dsl/action_recorder.rb +3 -3
  112. data/lib/nanoc/rule_dsl/action_sequence_calculator.rb +7 -7
  113. data/lib/nanoc/rule_dsl/compilation_rule.rb +2 -2
  114. data/lib/nanoc/rule_dsl/compilation_rule_context.rb +9 -9
  115. data/lib/nanoc/rule_dsl/compiler_dsl.rb +4 -4
  116. data/lib/nanoc/rule_dsl/routing_rule.rb +3 -3
  117. data/lib/nanoc/rule_dsl/rule.rb +5 -5
  118. data/lib/nanoc/rule_dsl/rule_context.rb +3 -3
  119. data/lib/nanoc/rule_dsl/rules_collection.rb +4 -4
  120. data/lib/nanoc/spec.rb +15 -15
  121. data/lib/nanoc/version.rb +1 -1
  122. metadata +10 -111
  123. data/lib/nanoc/base/contracts_support.rb +0 -130
  124. data/lib/nanoc/base/core_ext.rb +0 -5
  125. data/lib/nanoc/base/core_ext/array.rb +0 -50
  126. data/lib/nanoc/base/core_ext/hash.rb +0 -54
  127. data/lib/nanoc/base/core_ext/string.rb +0 -16
  128. data/lib/nanoc/base/entities/code_snippet.rb +0 -53
  129. data/lib/nanoc/base/entities/configuration-schema.json +0 -122
  130. data/lib/nanoc/base/entities/configuration.rb +0 -206
  131. data/lib/nanoc/base/entities/content.rb +0 -112
  132. data/lib/nanoc/base/entities/context.rb +0 -70
  133. data/lib/nanoc/base/entities/directed_graph.rb +0 -195
  134. data/lib/nanoc/base/entities/document.rb +0 -125
  135. data/lib/nanoc/base/entities/identifiable_collection.rb +0 -141
  136. data/lib/nanoc/base/entities/identifier.rb +0 -222
  137. data/lib/nanoc/base/entities/item.rb +0 -10
  138. data/lib/nanoc/base/entities/item_collection.rb +0 -14
  139. data/lib/nanoc/base/entities/item_rep.rb +0 -91
  140. data/lib/nanoc/base/entities/layout.rb +0 -10
  141. data/lib/nanoc/base/entities/layout_collection.rb +0 -14
  142. data/lib/nanoc/base/entities/lazy_value.rb +0 -43
  143. data/lib/nanoc/base/entities/pattern.rb +0 -85
  144. data/lib/nanoc/base/entities/processing_action.rb +0 -21
  145. data/lib/nanoc/base/entities/processing_actions.rb +0 -5
  146. data/lib/nanoc/base/entities/processing_actions/filter.rb +0 -36
  147. data/lib/nanoc/base/entities/processing_actions/layout.rb +0 -36
  148. data/lib/nanoc/base/entities/processing_actions/snapshot.rb +0 -46
  149. data/lib/nanoc/base/entities/snapshot_def.rb +0 -22
  150. data/lib/nanoc/base/repos/data_source.rb +0 -168
  151. data/lib/nanoc/base/repos/snapshot_repo.rb +0 -67
  152. data/lib/nanoc/base/services/checksummer.rb +0 -274
  153. data/lib/nanoc/base/services/notification_center.rb +0 -87
  154. data/lib/nanoc/base/services/temp_filename_factory.rb +0 -52
@@ -20,7 +20,7 @@ module Nanoc
20
20
  res = @item_rep.raw_path(snapshot: snapshot)
21
21
 
22
22
  unless @item_rep.compiled?
23
- Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(@item_rep))
23
+ Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(@item_rep, snapshot))
24
24
  end
25
25
 
26
26
  # Wait for file to exist
@@ -43,7 +43,7 @@ module Nanoc
43
43
  # @return [String] The content at the given snapshot.
44
44
  def compiled_content(snapshot: nil)
45
45
  @context.dependency_tracker.bounce(_unwrap.item, compiled_content: true)
46
- @context.snapshot_repo.compiled_content(rep: _unwrap, snapshot: snapshot)
46
+ @context.compiled_content_store.compiled_content(rep: _unwrap, snapshot: snapshot)
47
47
  end
48
48
  end
49
49
  end
@@ -56,7 +56,7 @@ module Nanoc
56
56
 
57
57
  prop_attribute =
58
58
  case arg
59
- when String, Nanoc::Identifier
59
+ when String, Nanoc::Core::Identifier
60
60
  [arg.to_s]
61
61
  when Regexp
62
62
  [arg]
@@ -93,7 +93,7 @@ module Nanoc
93
93
  def [](arg)
94
94
  prop_attribute =
95
95
  case arg
96
- when String, Nanoc::Identifier
96
+ when String, Nanoc::Core::Identifier
97
97
  [arg.to_s]
98
98
  when Regexp
99
99
  [arg]
@@ -31,7 +31,7 @@ module Nanoc
31
31
  self.class.hash ^ identifier.hash
32
32
  end
33
33
 
34
- # @return [Nanoc::Identifier]
34
+ # @return [Nanoc::Core::Identifier]
35
35
  def identifier
36
36
  _unwrap.identifier
37
37
  end
@@ -16,7 +16,7 @@ module Nanoc
16
16
  end
17
17
 
18
18
  def raw_content=(arg)
19
- _unwrap.content = Nanoc::Int::Content.create(arg)
19
+ _unwrap.content = Nanoc::Core::Content.create(arg)
20
20
  end
21
21
 
22
22
  # Sets the value for the given attribute.
@@ -26,8 +26,8 @@ module Nanoc
26
26
  # @see Hash#[]=
27
27
  def []=(key, value)
28
28
  disallowed_value_classes = Set.new([
29
- Nanoc::Int::Item,
30
- Nanoc::Int::Layout,
29
+ Nanoc::Core::Item,
30
+ Nanoc::Core::Layout,
31
31
  Nanoc::CompilationItemView,
32
32
  Nanoc::LayoutView,
33
33
  ])
@@ -40,9 +40,9 @@ module Nanoc
40
40
 
41
41
  # Sets the identifier to the given argument.
42
42
  #
43
- # @param [String, Nanoc::Identifier] arg
43
+ # @param [String, Nanoc::Core::Identifier] arg
44
44
  def identifier=(arg)
45
- _unwrap.identifier = Nanoc::Identifier.from(arg)
45
+ _unwrap.identifier = Nanoc::Core::Identifier.from(arg)
46
46
  end
47
47
 
48
48
  # Updates the attributes based on the given hash.
@@ -15,7 +15,7 @@ module Nanoc
15
15
  #
16
16
  # @param [Hash] attributes A hash containing this item's attributes.
17
17
  #
18
- # @param [Nanoc::Identifier, String] identifier This item's identifier.
18
+ # @param [Nanoc::Core::Identifier, String] identifier This item's identifier.
19
19
  #
20
20
  # @param [Boolean] binary Whether or not this item is binary
21
21
  #
@@ -24,8 +24,8 @@ module Nanoc
24
24
  #
25
25
  # @return [self]
26
26
  def create(content, attributes, identifier, binary: false, filename: nil)
27
- content = Nanoc::Int::Content.create(content, binary: binary, filename: filename)
28
- @objects = @objects.add(Nanoc::Int::Item.new(content, attributes, identifier))
27
+ content = Nanoc::Core::Content.create(content, binary: binary, filename: filename)
28
+ @objects = @objects.add(Nanoc::Core::Item.new(content, attributes, identifier))
29
29
  self
30
30
  end
31
31
  end
@@ -13,11 +13,11 @@ module Nanoc
13
13
  #
14
14
  # @param [Hash] attributes A hash containing this layout's attributes.
15
15
  #
16
- # @param [Nanoc::Identifier, String] identifier This layout's identifier.
16
+ # @param [Nanoc::Core::Identifier, String] identifier This layout's identifier.
17
17
  #
18
18
  # @return [self]
19
19
  def create(content, attributes, identifier)
20
- @objects = @objects.add(Nanoc::Int::Layout.new(content, attributes, identifier))
20
+ @objects = @objects.add(Nanoc::Core::Layout.new(content, attributes, identifier))
21
21
  self
22
22
  end
23
23
  end
@@ -3,27 +3,27 @@
3
3
  module Nanoc
4
4
  # @api private
5
5
  class ViewContextForCompilation
6
- include Nanoc::Int::ContractsSupport
6
+ include Nanoc::Core::ContractsSupport
7
7
 
8
8
  attr_reader :reps
9
9
  attr_reader :items
10
10
  attr_reader :dependency_tracker
11
11
  attr_reader :compilation_context
12
- attr_reader :snapshot_repo
12
+ attr_reader :compiled_content_store
13
13
 
14
14
  contract C::KeywordArgs[
15
15
  reps: Nanoc::Int::ItemRepRepo,
16
- items: Nanoc::Int::IdentifiableCollection,
16
+ items: Nanoc::Core::IdentifiableCollection,
17
17
  dependency_tracker: C::Any,
18
18
  compilation_context: C::Any,
19
- snapshot_repo: C::Any,
19
+ compiled_content_store: C::Any,
20
20
  ] => C::Any
21
- def initialize(reps:, items:, dependency_tracker:, compilation_context:, snapshot_repo:)
21
+ def initialize(reps:, items:, dependency_tracker:, compilation_context:, compiled_content_store:)
22
22
  @reps = reps
23
23
  @items = items
24
24
  @dependency_tracker = dependency_tracker
25
25
  @compilation_context = compilation_context
26
- @snapshot_repo = snapshot_repo
26
+ @compiled_content_store = compiled_content_store
27
27
  end
28
28
  end
29
29
  end
@@ -3,12 +3,12 @@
3
3
  module Nanoc
4
4
  # @api private
5
5
  class ViewContextForPreCompilation
6
- include Nanoc::Int::ContractsSupport
6
+ include Nanoc::Core::ContractsSupport
7
7
 
8
8
  attr_reader :items
9
9
  attr_reader :dependency_tracker
10
10
 
11
- contract C::KeywordArgs[items: Nanoc::Int::IdentifiableCollection] => C::Any
11
+ contract C::KeywordArgs[items: Nanoc::Core::IdentifiableCollection] => C::Any
12
12
  def initialize(items:)
13
13
  @items = items
14
14
 
@@ -3,14 +3,14 @@
3
3
  module Nanoc
4
4
  # @api private
5
5
  class ViewContextForShell
6
- include Nanoc::Int::ContractsSupport
6
+ include Nanoc::Core::ContractsSupport
7
7
 
8
8
  attr_reader :items
9
9
  attr_reader :reps
10
10
  attr_reader :dependency_tracker
11
11
 
12
12
  contract C::KeywordArgs[
13
- items: Nanoc::Int::IdentifiableCollection,
13
+ items: Nanoc::Core::IdentifiableCollection,
14
14
  reps: Nanoc::Int::ItemRepRepo,
15
15
  ] => C::Any
16
16
  def initialize(items:, reps:)
@@ -9,7 +9,7 @@ module Nanoc::Checking
9
9
  end
10
10
 
11
11
  # @api private
12
- class Check < Nanoc::Int::Context
12
+ class Check < Nanoc::Core::Context
13
13
  extend DDPlugin::Plugin
14
14
 
15
15
  attr_reader :issues
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Nanoc::CLI::Commands::CompileListeners
4
4
  class Abstract
5
- def initialize(*); end
5
+ def initialize(*)
6
+ super()
7
+ end
6
8
 
7
9
  def self.enable_for?(command_runner, site) # rubocop:disable Lint/UnusedMethodArgument
8
10
  true
@@ -16,26 +18,41 @@ module Nanoc::CLI::Commands::CompileListeners
16
18
  # @abstract
17
19
  def stop; end
18
20
 
19
- def run_while
21
+ def wrapped_start
22
+ @_notification_names = []
20
23
  start
24
+ end
25
+
26
+ def wrapped_stop
27
+ stop
28
+
29
+ Nanoc::Core::NotificationCenter.sync
30
+
31
+ @_notification_names.each do |name|
32
+ Nanoc::Core::NotificationCenter.remove(name, self)
33
+ end
34
+ end
35
+
36
+ def run_while
37
+ wrapped_start
21
38
  yield
22
39
  ensure
23
- stop
40
+ wrapped_stop
24
41
  end
25
42
 
26
43
  def start_safely
27
- start
44
+ wrapped_start
28
45
  @_started = true
29
46
  end
30
47
 
31
48
  def stop_safely
32
- stop if @_started
49
+ wrapped_stop if @_started
33
50
  @_started = false
34
51
  end
35
52
 
36
53
  def on(sym)
37
- # TODO: clean up on stop
38
- Nanoc::Int::NotificationCenter.on(sym, self) { |*args| yield(*args) }
54
+ @_notification_names << sym
55
+ Nanoc::Core::NotificationCenter.on(sym, self) { |*args| yield(*args) }
39
56
  end
40
57
  end
41
58
  end
@@ -7,30 +7,94 @@ module Nanoc::CLI::Commands::CompileListeners
7
7
  command_runner.debug?
8
8
  end
9
9
 
10
+ COLOR_MAP = {
11
+ 'compilation' => "\e[31m",
12
+ 'content' => "\e[32m",
13
+ 'filtering' => "\e[33m",
14
+ 'dependency_tracking' => "\e[34m",
15
+ 'phase' => "\e[35m",
16
+ 'stage' => "\e[36m",
17
+ }.freeze
18
+
10
19
  # @see Listener#start
11
20
  def start
12
- Nanoc::Int::NotificationCenter.on(:compilation_started) do |rep|
13
- puts "*** Started compilation of #{rep.inspect}"
21
+ on(:compilation_started) do |rep|
22
+ log('compilation', "Started compilation of #{rep}")
23
+ end
24
+
25
+ on(:compilation_ended) do |rep|
26
+ log('compilation', "Ended compilation of #{rep}")
27
+ log('compilation', '')
14
28
  end
15
- Nanoc::Int::NotificationCenter.on(:compilation_ended) do |rep|
16
- puts "*** Ended compilation of #{rep.inspect}"
17
- puts
29
+
30
+ on(:compilation_suspended) do |rep, target_rep, snapshot_name|
31
+ log('compilation', "Suspended compilation of #{rep}: depends on #{target_rep}, snapshot #{snapshot_name}")
18
32
  end
19
- Nanoc::Int::NotificationCenter.on(:compilation_suspended) do |rep, e|
20
- puts "*** Suspended compilation of #{rep.inspect}: #{e.message}"
33
+
34
+ on(:cached_content_used) do |rep|
35
+ log('content', "Used cached compiled content for #{rep} instead of recompiling")
21
36
  end
22
- Nanoc::Int::NotificationCenter.on(:cached_content_used) do |rep|
23
- puts "*** Used cached compiled content for #{rep.inspect} instead of recompiling"
37
+
38
+ on(:snapshot_created) do |rep, snapshot_name|
39
+ log('content', "Snapshot #{snapshot_name} created for #{rep}")
24
40
  end
25
- Nanoc::Int::NotificationCenter.on(:filtering_started) do |rep, filter_name|
26
- puts "*** Started filtering #{rep.inspect} with #{filter_name}"
41
+
42
+ on(:filtering_started) do |rep, filter_name|
43
+ log('filtering', "Started filtering #{rep} with #{filter_name}")
27
44
  end
28
- Nanoc::Int::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
29
- puts "*** Ended filtering #{rep.inspect} with #{filter_name}"
45
+
46
+ on(:filtering_ended) do |rep, filter_name|
47
+ log('filtering', "Ended filtering #{rep} with #{filter_name}")
30
48
  end
31
- Nanoc::Int::NotificationCenter.on(:dependency_created) do |src, dst|
32
- puts "*** Dependency created from #{src.inspect} onto #{dst.inspect}"
49
+
50
+ on(:dependency_created) do |src, dst|
51
+ log('dependency_tracking', "Dependency created from #{src.inspect} onto #{dst.inspect}")
52
+ end
53
+
54
+ on(:phase_started) do |phase_name, rep|
55
+ log('phase', "Phase started: #{phase_name} (rep: #{rep})")
56
+ end
57
+
58
+ on(:phase_yielded) do |phase_name, rep|
59
+ log('phase', "Phase yielded: #{phase_name} (rep: #{rep})")
60
+ end
61
+
62
+ on(:phase_resumed) do |phase_name, rep|
63
+ log('phase', "Phase resumed: #{phase_name} (rep: #{rep})")
33
64
  end
65
+
66
+ on(:phase_ended) do |phase_name, rep|
67
+ log('phase', "Phase ended: #{phase_name} (rep: #{rep})")
68
+ end
69
+
70
+ on(:phase_aborted) do |phase_name, rep|
71
+ log('phase', "Phase aborted: #{phase_name} (rep: #{rep})")
72
+ end
73
+
74
+ on(:stage_started) do |stage_name|
75
+ log('stage', "Stage started: #{stage_name}")
76
+ end
77
+
78
+ on(:stage_ended) do |stage_name|
79
+ log('stage', "Stage ended: #{stage_name}")
80
+ end
81
+
82
+ on(:stage_aborted) do |stage_name|
83
+ log('stage', "Stage aborted: #{stage_name}")
84
+ end
85
+ end
86
+
87
+ def log(progname, msg)
88
+ logger.info(progname) { msg }
89
+ end
90
+
91
+ def logger
92
+ @_logger ||=
93
+ Logger.new($stdout).tap do |l|
94
+ l.formatter = proc do |_severity, _datetime, progname, msg|
95
+ "*** #{COLOR_MAP[progname]}#{msg}\e[0m\n"
96
+ end
97
+ end
34
98
  end
35
99
  end
36
100
  end
@@ -11,10 +11,12 @@ module Nanoc::CLI::Commands::CompileListeners
11
11
  def start
12
12
  setup_diffs
13
13
  old_contents = {}
14
- Nanoc::Int::NotificationCenter.on(:rep_write_started, self) do |rep, path|
14
+
15
+ on(:rep_write_started) do |rep, path|
15
16
  old_contents[rep] = File.file?(path) ? File.read(path) : nil
16
17
  end
17
- Nanoc::Int::NotificationCenter.on(:rep_write_ended, self) do |rep, binary, path, _is_created, _is_modified|
18
+
19
+ on(:rep_write_ended) do |rep, binary, path, _is_created, _is_modified|
18
20
  unless binary
19
21
  new_contents = File.file?(path) ? File.read(path) : nil
20
22
  if old_contents[rep] && new_contents
@@ -27,11 +29,6 @@ module Nanoc::CLI::Commands::CompileListeners
27
29
 
28
30
  # @see Listener#stop
29
31
  def stop
30
- super
31
-
32
- Nanoc::Int::NotificationCenter.remove(:rep_write_started, self)
33
- Nanoc::Int::NotificationCenter.remove(:rep_write_ended, self)
34
-
35
32
  teardown_diffs
36
33
  end
37
34
 
@@ -3,39 +3,38 @@
3
3
  module Nanoc::CLI::Commands::CompileListeners
4
4
  class FileActionPrinter < Abstract
5
5
  def initialize(reps:)
6
- @start_times = {}
7
- @acc_durations = {}
8
-
9
6
  @reps = reps
7
+
8
+ @stopwatches = {}
10
9
  end
11
10
 
12
11
  # @see Listener#start
13
12
  def start
14
- Nanoc::Int::NotificationCenter.on(:compilation_started, self) do |rep|
15
- @start_times[rep] = Time.now
16
- @acc_durations[rep] ||= 0.0
13
+ on(:compilation_started) do |rep|
14
+ @stopwatches[rep] ||= DDMetrics::Stopwatch.new
15
+ @stopwatches[rep].start
17
16
  end
18
17
 
19
- Nanoc::Int::NotificationCenter.on(:compilation_suspended, self) do |rep|
20
- @acc_durations[rep] += Time.now - @start_times[rep]
18
+ on(:compilation_suspended) do |rep|
19
+ @stopwatches[rep].stop
21
20
  end
22
21
 
23
22
  cached_reps = Set.new
24
- Nanoc::Int::NotificationCenter.on(:cached_content_used, self) do |rep|
23
+ on(:cached_content_used) do |rep|
25
24
  cached_reps << rep
26
25
  end
27
26
 
28
- Nanoc::Int::NotificationCenter.on(:rep_write_enqueued, self) do |rep|
29
- @acc_durations[rep] += Time.now - @start_times[rep]
27
+ on(:rep_write_enqueued) do |rep|
28
+ @stopwatches[rep].stop
30
29
  end
31
30
 
32
- Nanoc::Int::NotificationCenter.on(:rep_write_started, self) do |rep, _raw_path|
33
- @start_times[rep] = Time.now
31
+ on(:rep_write_started) do |rep, _raw_path|
32
+ @stopwatches[rep].start
34
33
  end
35
34
 
36
- Nanoc::Int::NotificationCenter.on(:rep_write_ended, self) do |rep, _binary, path, is_created, is_modified|
37
- @acc_durations[rep] += Time.now - @start_times[rep]
38
- duration = @acc_durations[rep]
35
+ on(:rep_write_ended) do |rep, _binary, path, is_created, is_modified|
36
+ @stopwatches[rep].stop
37
+ duration = @stopwatches[rep].duration
39
38
 
40
39
  action =
41
40
  if is_created then :create
@@ -60,14 +59,6 @@ module Nanoc::CLI::Commands::CompileListeners
60
59
 
61
60
  # @see Listener#stop
62
61
  def stop
63
- super
64
-
65
- Nanoc::Int::NotificationCenter.remove(:compilation_started, self)
66
- Nanoc::Int::NotificationCenter.remove(:compilation_suspended, self)
67
- Nanoc::Int::NotificationCenter.remove(:rep_write_enqueued, self)
68
- Nanoc::Int::NotificationCenter.remove(:rep_write_started, self)
69
- Nanoc::Int::NotificationCenter.remove(:rep_write_ended, self)
70
-
71
62
  @reps.reject(&:compiled?).each do |rep|
72
63
  raw_paths = rep.raw_paths.values.flatten.uniq
73
64
  raw_paths.each do |raw_path|