nanoc 4.11.0 → 4.11.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ end
8
+ end
9
+ end
4
10
  end
5
11
 
6
12
  require_relative 'phases/abstract'
@@ -10,3 +16,4 @@ require_relative 'phases/cache'
10
16
  require_relative 'phases/resume'
11
17
  require_relative 'phases/write'
12
18
  require_relative 'phases/mark_done'
19
+ require_relative 'phases/notify'
@@ -1,44 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- class Abstract
5
- include Nanoc::Int::ContractsSupport
6
-
7
- def initialize(wrapped:)
8
- @wrapped = wrapped
9
- end
10
-
11
- def start
12
- @wrapped&.start
13
- end
14
-
15
- def stop
16
- @wrapped&.stop
17
- end
18
-
19
- def call(rep, is_outdated:)
20
- notify(:phase_started, rep)
21
- run(rep, is_outdated: is_outdated) do
22
- notify(:phase_yielded, rep)
23
- @wrapped.call(rep, is_outdated: is_outdated)
24
- notify(:phase_resumed, rep)
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ class Abstract
8
+ include Nanoc::Core::ContractsSupport
9
+
10
+ def initialize(wrapped:)
11
+ @wrapped = wrapped
12
+ end
13
+
14
+ def start
15
+ @wrapped&.start
16
+ end
17
+
18
+ def stop
19
+ @wrapped&.stop
20
+ end
21
+
22
+ def call(rep, is_outdated:)
23
+ notify(:phase_started, rep)
24
+ run(rep, is_outdated: is_outdated) do
25
+ notify(:phase_yielded, rep)
26
+ @wrapped.call(rep, is_outdated: is_outdated)
27
+ notify(:phase_resumed, rep)
28
+ end
29
+ notify(:phase_ended, rep)
30
+ rescue
31
+ notify(:phase_aborted, rep)
32
+ raise
33
+ end
34
+
35
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
36
+ def run(_rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
37
+ raise NotImplementedError
38
+ end
39
+
40
+ private
41
+
42
+ def notify(sym, rep)
43
+ name = self.class.to_s.sub(/^.*::/, '')
44
+ Nanoc::Core::NotificationCenter.post(sym, name, rep)
45
+ end
46
+ end
25
47
  end
26
- notify(:phase_ended, rep)
27
- rescue
28
- notify(:phase_aborted, rep)
29
- raise
30
- end
31
-
32
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
33
- def run(_rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
34
- raise NotImplementedError
35
- end
36
-
37
- private
38
-
39
- def notify(sym, rep)
40
- name = self.class.to_s.sub(/^.*::/, '')
41
- Nanoc::Int::NotificationCenter.post(sym, name, rep)
42
48
  end
43
49
  end
44
50
  end
@@ -1,39 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- # Provides functionality for (re)calculating the content of an item rep, with caching or
5
- # outdatedness checking. Delegates to s::Recalculate if outdated or no cache available.
6
- class Cache < Abstract
7
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ # Provides functionality for (re)calculating the content of an item rep, with caching or
8
+ # outdatedness checking. Delegates to s::Recalculate if outdated or no cache available.
9
+ class Cache < Abstract
10
+ include Nanoc::Core::ContractsSupport
8
11
 
9
- def initialize(wrapped:, compiled_content_cache:, snapshot_repo:)
10
- super(wrapped: wrapped)
12
+ def initialize(wrapped:, compiled_content_cache:, compiled_content_store:)
13
+ super(wrapped: wrapped)
11
14
 
12
- @compiled_content_cache = compiled_content_cache
13
- @snapshot_repo = snapshot_repo
14
- end
15
+ @compiled_content_cache = compiled_content_cache
16
+ @compiled_content_store = compiled_content_store
17
+ end
15
18
 
16
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
17
- def run(rep, is_outdated:)
18
- if can_reuse_content_for_rep?(rep, is_outdated: is_outdated)
19
- Nanoc::Int::NotificationCenter.post(:cached_content_used, rep)
19
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
20
+ def run(rep, is_outdated:)
21
+ if can_reuse_content_for_rep?(rep, is_outdated: is_outdated)
22
+ Nanoc::Core::NotificationCenter.post(:cached_content_used, rep)
20
23
 
21
- @snapshot_repo.set_all(rep, @compiled_content_cache[rep])
22
- else
23
- yield
24
- end
24
+ @compiled_content_store.set_all(rep, @compiled_content_cache[rep])
25
+ else
26
+ yield
27
+ end
25
28
 
26
- rep.compiled = true
27
- @compiled_content_cache[rep] = @snapshot_repo.get_all(rep)
28
- end
29
+ rep.compiled = true
30
+ @compiled_content_cache[rep] = @compiled_content_store.get_all(rep)
31
+ end
29
32
 
30
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool] => C::Bool
31
- def can_reuse_content_for_rep?(rep, is_outdated:)
32
- if is_outdated
33
- false
34
- else
35
- cache = @compiled_content_cache[rep]
36
- cache ? cache.none? { |_snapshot_name, content| content.binary? } : false
33
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool] => C::Bool
34
+ def can_reuse_content_for_rep?(rep, is_outdated:)
35
+ if is_outdated
36
+ false
37
+ else
38
+ cache = @compiled_content_cache[rep]
39
+ cache ? cache.none? { |_snapshot_name, content| content.binary? } : false
40
+ end
41
+ end
42
+ end
37
43
  end
38
44
  end
39
45
  end
@@ -1,19 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- class MarkDone < Abstract
5
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ class MarkDone < Abstract
8
+ include Nanoc::Core::ContractsSupport
6
9
 
7
- def initialize(wrapped:, outdatedness_store:)
8
- super(wrapped: wrapped)
10
+ def initialize(wrapped:, outdatedness_store:)
11
+ super(wrapped: wrapped)
9
12
 
10
- @outdatedness_store = outdatedness_store
11
- end
13
+ @outdatedness_store = outdatedness_store
14
+ end
12
15
 
13
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
14
- def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
15
- yield
16
- @outdatedness_store.remove(rep)
16
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
17
+ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
18
+ yield
19
+ @outdatedness_store.remove(rep)
20
+ end
21
+ end
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ # Provides functionality for notifying start and end of compilation.
8
+ class Notify < Abstract
9
+ include Nanoc::Core::ContractsSupport
10
+
11
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
12
+ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
13
+ Nanoc::Core::NotificationCenter.post(:compilation_started, rep)
14
+ yield
15
+ Nanoc::Core::NotificationCenter.post(:compilation_ended, rep)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,45 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- # Provides functionality for (re)calculating the content of an item rep, without caching or
5
- # outdatedness checking.
6
- class Recalculate < Abstract
7
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ # Provides functionality for (re)calculating the content of an item rep, without caching or
8
+ # outdatedness checking.
9
+ class Recalculate < Abstract
10
+ include Nanoc::Core::ContractsSupport
8
11
 
9
- def initialize(action_sequences:, dependency_store:, compilation_context:)
10
- super(wrapped: nil)
12
+ def initialize(action_sequences:, dependency_store:, compilation_context:)
13
+ super(wrapped: nil)
11
14
 
12
- @action_sequences = action_sequences
13
- @dependency_store = dependency_store
14
- @compilation_context = compilation_context
15
- end
15
+ @action_sequences = action_sequences
16
+ @dependency_store = dependency_store
17
+ @compilation_context = compilation_context
18
+ end
16
19
 
17
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
18
- def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
19
- dependency_tracker = Nanoc::Int::DependencyTracker.new(@dependency_store)
20
- dependency_tracker.enter(rep.item)
20
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
21
+ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
22
+ dependency_tracker = Nanoc::Int::DependencyTracker.new(@dependency_store)
23
+ dependency_tracker.enter(rep.item)
21
24
 
22
- executor = Nanoc::Int::Executor.new(rep, @compilation_context, dependency_tracker)
25
+ executor = Nanoc::Int::Executor.new(rep, @compilation_context, dependency_tracker)
23
26
 
24
- @compilation_context.snapshot_repo.set(rep, :last, rep.item.content)
27
+ @compilation_context.compiled_content_store.set_current(rep, rep.item.content)
25
28
 
26
- actions = @action_sequences[rep]
27
- actions.each do |action|
28
- case action
29
- when Nanoc::Int::ProcessingActions::Filter
30
- executor.filter(action.filter_name, action.params)
31
- when Nanoc::Int::ProcessingActions::Layout
32
- executor.layout(action.layout_identifier, action.params)
33
- when Nanoc::Int::ProcessingActions::Snapshot
34
- action.snapshot_names.each do |snapshot_name|
35
- executor.snapshot(snapshot_name)
29
+ actions = @action_sequences[rep]
30
+ actions.each do |action|
31
+ case action
32
+ when Nanoc::Core::ProcessingActions::Filter
33
+ executor.filter(action.filter_name, action.params)
34
+ when Nanoc::Core::ProcessingActions::Layout
35
+ executor.layout(action.layout_identifier, action.params)
36
+ when Nanoc::Core::ProcessingActions::Snapshot
37
+ action.snapshot_names.each do |snapshot_name|
38
+ executor.snapshot(snapshot_name)
39
+ end
40
+ else
41
+ raise Nanoc::Int::Errors::InternalInconsistency, "unknown action #{action.inspect}"
42
+ end
43
+ end
44
+ ensure
45
+ dependency_tracker.exit
36
46
  end
37
- else
38
- raise Nanoc::Int::Errors::InternalInconsistency, "unknown action #{action.inspect}"
39
47
  end
40
48
  end
41
- ensure
42
- dependency_tracker.exit
43
49
  end
44
50
  end
45
51
  end
@@ -1,55 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- # Provides functionality for suspending and resuming item rep compilation (using fibers).
5
- class Resume < Abstract
6
- include Nanoc::Int::ContractsSupport
7
-
8
- DONE = Object.new
9
-
10
- def initialize(wrapped:)
11
- super(wrapped: wrapped)
12
- end
13
-
14
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
15
- def run(rep, is_outdated:)
16
- fiber = fiber_for(rep, is_outdated: is_outdated) { yield }
17
- while fiber.alive?
18
- Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
19
- res = fiber.resume
20
-
21
- case res
22
- when Nanoc::Int::Errors::UnmetDependency
23
- Nanoc::Int::NotificationCenter.post(:compilation_suspended, rep, res)
24
- raise(res)
25
- when Proc
26
- fiber.resume(res.call)
27
- when DONE # rubocop:disable Lint/EmptyWhen
28
- # ignore
29
- else
30
- raise Nanoc::Int::Errors::InternalInconsistency.new(
31
- "Fiber yielded object of unexpected type #{res.class}",
32
- )
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ # Provides functionality for suspending and resuming item rep compilation (using fibers).
8
+ class Resume < Abstract
9
+ include Nanoc::Core::ContractsSupport
10
+
11
+ DONE = Object.new
12
+
13
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
14
+ def run(rep, is_outdated:)
15
+ fiber = fiber_for(rep, is_outdated: is_outdated) { yield }
16
+ while fiber.alive?
17
+ res = fiber.resume
18
+
19
+ case res
20
+ when Nanoc::Int::Errors::UnmetDependency
21
+ Nanoc::Core::NotificationCenter.post(:compilation_suspended, rep, res.rep, res.snapshot_name)
22
+ raise(res)
23
+ when Proc
24
+ fiber.resume(res.call)
25
+ when DONE # rubocop:disable Lint/EmptyWhen
26
+ # ignore
27
+ else
28
+ raise Nanoc::Int::Errors::InternalInconsistency.new(
29
+ "Fiber yielded object of unexpected type #{res.class}",
30
+ )
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => Fiber
38
+ def fiber_for(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
39
+ @fibers ||= {}
40
+
41
+ @fibers[rep] ||=
42
+ Fiber.new do
43
+ yield
44
+ @fibers.delete(rep)
45
+ DONE
46
+ end
47
+
48
+ @fibers[rep]
49
+ end
33
50
  end
34
51
  end
35
-
36
- Nanoc::Int::NotificationCenter.post(:compilation_ended, rep)
37
- end
38
-
39
- private
40
-
41
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => Fiber
42
- def fiber_for(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
43
- @fibers ||= {}
44
-
45
- @fibers[rep] ||=
46
- Fiber.new do
47
- yield
48
- @fibers.delete(rep)
49
- DONE
50
- end
51
-
52
- @fibers[rep]
53
52
  end
54
53
  end
55
54
  end
@@ -1,77 +1,83 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int::Compiler::Phases
4
- class Write < Abstract
5
- include Nanoc::Int::ContractsSupport
6
-
7
- class Worker
8
- def initialize(queue:, snapshot_repo:)
9
- @queue = queue
10
- @snapshot_repo = snapshot_repo
11
- end
12
-
13
- def start
14
- @thread = Thread.new do
15
- Thread.current.abort_on_exception = true
16
- Thread.current.priority = -1 # schedule I/O work ASAP
17
-
18
- writer = Nanoc::Int::ItemRepWriter.new
19
-
20
- while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
21
- writer.write_all(rep, @snapshot_repo)
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ module Phases
7
+ class Write < Abstract
8
+ include Nanoc::Core::ContractsSupport
9
+
10
+ class Worker
11
+ def initialize(queue:, compiled_content_store:)
12
+ @queue = queue
13
+ @compiled_content_store = compiled_content_store
14
+ end
15
+
16
+ def start
17
+ @thread = Thread.new do
18
+ Thread.current.abort_on_exception = true
19
+ Thread.current.priority = -1 # schedule I/O work ASAP
20
+
21
+ writer = Nanoc::Int::ItemRepWriter.new
22
+
23
+ while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
24
+ writer.write_all(rep, @compiled_content_store)
25
+ end
26
+ end
27
+ end
28
+
29
+ def join
30
+ @thread.join
31
+ end
22
32
  end
23
- end
24
- end
25
33
 
26
- def join
27
- @thread.join
28
- end
29
- end
30
-
31
- class WorkerPool
32
- def initialize(queue:, size:, snapshot_repo:)
33
- @workers = Array.new(size) { Worker.new(queue: queue, snapshot_repo: snapshot_repo) }
34
- end
34
+ class WorkerPool
35
+ def initialize(queue:, size:, compiled_content_store:)
36
+ @workers = Array.new(size) { Worker.new(queue: queue, compiled_content_store: compiled_content_store) }
37
+ end
35
38
 
36
- def start
37
- @workers.each(&:start)
38
- end
39
+ def start
40
+ @workers.each(&:start)
41
+ end
39
42
 
40
- def join
41
- @workers.each(&:join)
42
- end
43
- end
43
+ def join
44
+ @workers.each(&:join)
45
+ end
46
+ end
44
47
 
45
- QUEUE_SIZE = 40
46
- WORKER_POOL_SIZE = 5
48
+ QUEUE_SIZE = 40
49
+ WORKER_POOL_SIZE = 5
47
50
 
48
- def initialize(snapshot_repo:, wrapped:)
49
- super(wrapped: wrapped)
51
+ def initialize(compiled_content_store:, wrapped:)
52
+ super(wrapped: wrapped)
50
53
 
51
- @snapshot_repo = snapshot_repo
54
+ @compiled_content_store = compiled_content_store
52
55
 
53
- @queue = SizedQueue.new(QUEUE_SIZE)
54
- @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, snapshot_repo: @snapshot_repo)
55
- end
56
+ @queue = SizedQueue.new(QUEUE_SIZE)
57
+ @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, compiled_content_store: @compiled_content_store)
58
+ end
56
59
 
57
- def start
58
- super
59
- @worker_pool.start
60
- end
60
+ def start
61
+ super
62
+ @worker_pool.start
63
+ end
61
64
 
62
- def stop
63
- super
64
- @queue.close
65
- @worker_pool.join
66
- end
65
+ def stop
66
+ super
67
+ @queue.close
68
+ @worker_pool.join
69
+ end
67
70
 
68
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
69
- def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
70
- yield
71
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
72
+ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
73
+ yield
71
74
 
72
- @queue << rep
75
+ @queue << rep
73
76
 
74
- Nanoc::Int::NotificationCenter.post(:rep_write_enqueued, rep)
77
+ Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)
78
+ end
79
+ end
80
+ end
75
81
  end
76
82
  end
77
83
  end