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
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative 'services/action_provider'
4
4
  require_relative 'services/action_sequence_builder'
5
- require_relative 'services/checksummer'
6
5
  require_relative 'services/compilation_context'
7
6
  require_relative 'services/compiler'
8
7
  require_relative 'services/compiler_loader'
@@ -14,9 +13,7 @@ require_relative 'services/item_rep_builder'
14
13
  require_relative 'services/item_rep_router'
15
14
  require_relative 'services/item_rep_selector'
16
15
  require_relative 'services/item_rep_writer'
17
- require_relative 'services/notification_center'
18
16
  require_relative 'services/pruner'
19
- require_relative 'services/temp_filename_factory'
20
17
  require_relative 'services/outdatedness_rule'
21
18
  require_relative 'services/outdatedness_rules'
22
19
 
@@ -24,3 +21,10 @@ require_relative 'services/compiler/phases'
24
21
  require_relative 'services/compiler/stages'
25
22
 
26
23
  require_relative 'services/outdatedness_checker'
24
+
25
+ # TODO: Move this into the entity, once the load order is improved (i.e. the
26
+ # checksummer is loaded after CodeSnippet).
27
+ Nanoc::Core::Checksummer.define_behavior(
28
+ Nanoc::Core::CodeSnippet,
29
+ Nanoc::Core::Checksummer::DataUpdateBehavior,
30
+ )
@@ -1,32 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- # @private
5
- class ActionProvider
6
- extend DDPlugin::Plugin
3
+ module Nanoc
4
+ module Int
5
+ # @private
6
+ class ActionProvider
7
+ extend DDPlugin::Plugin
7
8
 
8
- def self.for(_site)
9
- raise NotImplementedError
10
- end
9
+ def self.for(_site)
10
+ raise NotImplementedError
11
+ end
11
12
 
12
- def rep_names_for(_item)
13
- raise NotImplementedError
14
- end
13
+ def rep_names_for(_item)
14
+ raise NotImplementedError
15
+ end
15
16
 
16
- def action_sequence_for(_obj)
17
- raise NotImplementedError
18
- end
17
+ def action_sequence_for(_obj)
18
+ raise NotImplementedError
19
+ end
19
20
 
20
- def need_preprocessing?
21
- raise NotImplementedError
22
- end
21
+ def need_preprocessing?
22
+ raise NotImplementedError
23
+ end
23
24
 
24
- def preprocess(_site)
25
- raise NotImplementedError
26
- end
25
+ def preprocess(_site)
26
+ raise NotImplementedError
27
+ end
27
28
 
28
- def postprocess(_site, _reps)
29
- raise NotImplementedError
29
+ def postprocess(_site, _reps)
30
+ raise NotImplementedError
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -1,46 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- class ActionSequenceBuilder
5
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ class ActionSequenceBuilder
6
+ include Nanoc::Core::ContractsSupport
7
+
8
+ def self.build(rep)
9
+ builder = new(rep)
10
+ yield(builder)
11
+ builder.action_sequence
12
+ end
6
13
 
7
- def initialize(item_rep)
8
- @item_rep = item_rep
9
- @actions = []
10
- end
14
+ def initialize(item_rep)
15
+ @item_rep = item_rep
16
+ @actions = []
17
+ end
11
18
 
12
- contract Symbol, Hash => self
13
- def add_filter(filter_name, params)
14
- @actions << Nanoc::Int::ProcessingActions::Filter.new(filter_name, params)
15
- self
16
- end
19
+ contract Symbol, Hash => self
20
+ def add_filter(filter_name, params)
21
+ @actions << Nanoc::Core::ProcessingActions::Filter.new(filter_name, params)
22
+ self
23
+ end
17
24
 
18
- contract String, C::Maybe[Hash] => self
19
- def add_layout(layout_identifier, params)
20
- @actions << Nanoc::Int::ProcessingActions::Layout.new(layout_identifier, params)
21
- self
22
- end
25
+ contract String, C::Maybe[Hash] => self
26
+ def add_layout(layout_identifier, params)
27
+ @actions << Nanoc::Core::ProcessingActions::Layout.new(layout_identifier, params)
28
+ self
29
+ end
23
30
 
24
- contract Symbol, C::Maybe[String] => self
25
- def add_snapshot(snapshot_name, path)
26
- will_add_snapshot(snapshot_name)
27
- @actions << Nanoc::Int::ProcessingActions::Snapshot.new([snapshot_name], path ? [path] : [])
28
- self
29
- end
31
+ contract Symbol, C::Maybe[String] => self
32
+ def add_snapshot(snapshot_name, path)
33
+ will_add_snapshot(snapshot_name)
34
+ @actions << Nanoc::Core::ProcessingActions::Snapshot.new([snapshot_name], path ? [path] : [])
35
+ self
36
+ end
30
37
 
31
- contract C::None => Nanoc::Int::ActionSequence
32
- def action_sequence
33
- Nanoc::Int::ActionSequence.new(@item_rep, actions: @actions)
34
- end
38
+ contract C::None => Nanoc::Int::ActionSequence
39
+ def action_sequence
40
+ Nanoc::Int::ActionSequence.new(@item_rep, actions: @actions)
41
+ end
35
42
 
36
- private
43
+ private
37
44
 
38
- def will_add_snapshot(name)
39
- @_snapshot_names ||= Set.new
40
- if @_snapshot_names.include?(name)
41
- raise Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName.new(@item_rep, name)
42
- else
43
- @_snapshot_names << name
45
+ def will_add_snapshot(name)
46
+ @_snapshot_names ||= Set.new
47
+ if @_snapshot_names.include?(name)
48
+ raise Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName.new(@item_rep, name)
49
+ else
50
+ @_snapshot_names << name
51
+ end
44
52
  end
45
53
  end
46
54
  end
@@ -1,57 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- class CompilationContext
5
- attr_reader :site
6
- attr_reader :compiled_content_cache
7
- attr_reader :snapshot_repo
8
-
9
- def initialize(action_provider:, reps:, site:, compiled_content_cache:, snapshot_repo:)
10
- @action_provider = action_provider
11
- @reps = reps
12
- @site = site
13
- @compiled_content_cache = compiled_content_cache
14
- @snapshot_repo = snapshot_repo
15
- end
16
-
17
- def filter_name_and_args_for_layout(layout)
18
- seq = @action_provider.action_sequence_for(layout)
19
- if seq.nil? || seq.size != 1 || !seq[0].is_a?(Nanoc::Int::ProcessingActions::Filter)
20
- raise Nanoc::Int::Errors::UndefinedFilterForLayout.new(layout)
3
+ module Nanoc
4
+ module Int
5
+ class CompilationContext
6
+ attr_reader :site
7
+ attr_reader :compiled_content_cache
8
+ attr_reader :compiled_content_store
9
+
10
+ def initialize(action_provider:, reps:, site:, compiled_content_cache:, compiled_content_store:)
11
+ @action_provider = action_provider
12
+ @reps = reps
13
+ @site = site
14
+ @compiled_content_cache = compiled_content_cache
15
+ @compiled_content_store = compiled_content_store
21
16
  end
22
17
 
23
- [seq[0].filter_name, seq[0].params]
24
- end
25
-
26
- def create_view_context(dependency_tracker)
27
- Nanoc::ViewContextForCompilation.new(
28
- reps: @reps,
29
- items: @site.items,
30
- dependency_tracker: dependency_tracker,
31
- compilation_context: self,
32
- snapshot_repo: @snapshot_repo,
33
- )
34
- end
35
-
36
- def assigns_for(rep, dependency_tracker)
37
- last_content = @snapshot_repo.get(rep, :last)
38
- content_or_filename_assigns =
39
- if last_content.binary?
40
- { filename: last_content.filename }
41
- else
42
- { content: last_content.string }
18
+ def filter_name_and_args_for_layout(layout)
19
+ seq = @action_provider.action_sequence_for(layout)
20
+ if seq.nil? || seq.size != 1 || !seq[0].is_a?(Nanoc::Core::ProcessingActions::Filter)
21
+ raise Nanoc::Int::Errors::UndefinedFilterForLayout.new(layout)
43
22
  end
44
23
 
45
- view_context = create_view_context(dependency_tracker)
24
+ [seq[0].filter_name, seq[0].params]
25
+ end
46
26
 
47
- content_or_filename_assigns.merge(
48
- item: Nanoc::CompilationItemView.new(rep.item, view_context),
49
- rep: Nanoc::CompilationItemRepView.new(rep, view_context),
50
- item_rep: Nanoc::CompilationItemRepView.new(rep, view_context),
51
- items: Nanoc::ItemCollectionWithRepsView.new(@site.items, view_context),
52
- layouts: Nanoc::LayoutCollectionView.new(@site.layouts, view_context),
53
- config: Nanoc::ConfigView.new(@site.config, view_context),
54
- )
27
+ def create_view_context(dependency_tracker)
28
+ Nanoc::ViewContextForCompilation.new(
29
+ reps: @reps,
30
+ items: @site.items,
31
+ dependency_tracker: dependency_tracker,
32
+ compilation_context: self,
33
+ compiled_content_store: @compiled_content_store,
34
+ )
35
+ end
36
+
37
+ def assigns_for(rep, dependency_tracker)
38
+ last_content = @compiled_content_store.get_current(rep)
39
+ content_or_filename_assigns =
40
+ if last_content.binary?
41
+ { filename: last_content.filename }
42
+ else
43
+ { content: last_content.string }
44
+ end
45
+
46
+ view_context = create_view_context(dependency_tracker)
47
+
48
+ content_or_filename_assigns.merge(
49
+ item: Nanoc::CompilationItemView.new(rep.item, view_context),
50
+ rep: Nanoc::CompilationItemRepView.new(rep, view_context),
51
+ item_rep: Nanoc::CompilationItemRepView.new(rep, view_context),
52
+ items: Nanoc::ItemCollectionWithRepsView.new(@site.items, view_context),
53
+ layouts: Nanoc::LayoutCollectionView.new(@site.layouts, view_context),
54
+ config: Nanoc::ConfigView.new(@site.config, view_context),
55
+ )
56
+ end
55
57
  end
56
58
  end
57
59
  end
@@ -1,207 +1,214 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- class Compiler
5
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ class Compiler
6
+ include Nanoc::Core::ContractsSupport
6
7
 
7
- def initialize(site, compiled_content_cache:, checksum_store:, action_sequence_store:, action_provider:, dependency_store:, outdatedness_store:)
8
- @site = site
8
+ def initialize(site, compiled_content_cache:, checksum_store:, action_sequence_store:, action_provider:, dependency_store:, outdatedness_store:)
9
+ @site = site
9
10
 
10
- # Needed because configuration is mutable :(
11
- @output_dirs = @site.config.output_dirs
11
+ # Needed because configuration is mutable :(
12
+ @output_dirs = @site.config.output_dirs
12
13
 
13
- @compiled_content_cache = compiled_content_cache
14
- @checksum_store = checksum_store
15
- @action_sequence_store = action_sequence_store
16
- @dependency_store = dependency_store
17
- @action_provider = action_provider
18
- @outdatedness_store = outdatedness_store
14
+ @compiled_content_cache = compiled_content_cache
15
+ @checksum_store = checksum_store
16
+ @action_sequence_store = action_sequence_store
17
+ @dependency_store = dependency_store
18
+ @action_provider = action_provider
19
+ @outdatedness_store = outdatedness_store
19
20
 
20
- @snapshot_repo = Nanoc::Int::SnapshotRepo.new
21
- end
21
+ @compiled_content_store = Nanoc::Int::CompiledContentStore.new
22
+ end
22
23
 
23
- contract Nanoc::Int::Site => Nanoc::Int::Compiler
24
- def self.new_for(site)
25
- Nanoc::Int::CompilerLoader.new.load(site)
26
- end
24
+ contract Nanoc::Int::Site => C::Any
25
+ def self.compile(site)
26
+ new_for(site).run_until_end
27
+ end
27
28
 
28
- def run_until_preprocessed
29
- @_res_preprocessed ||= begin
30
- preprocess_stage.call
31
- {}
29
+ contract Nanoc::Int::Site => Nanoc::Int::Compiler
30
+ def self.new_for(site)
31
+ Nanoc::Int::CompilerLoader.new.load(site)
32
32
  end
33
- end
34
33
 
35
- def run_until_reps_built
36
- @_res_reps_built ||= begin
37
- prev = run_until_preprocessed
34
+ def run_until_preprocessed
35
+ @_res_preprocessed ||= begin
36
+ preprocess_stage.call
37
+ {}
38
+ end
39
+ end
40
+
41
+ def run_until_reps_built
42
+ @_res_reps_built ||= begin
43
+ prev = run_until_preprocessed
44
+
45
+ res = build_reps_stage.call
46
+
47
+ prev.merge(
48
+ reps: res.fetch(:reps),
49
+ action_sequences: res.fetch(:action_sequences),
50
+ )
51
+ end
52
+ end
38
53
 
39
- res = build_reps_stage.call
54
+ def run_until_precompiled
55
+ @_res_precompiled ||= begin
56
+ prev = run_until_reps_built
57
+ action_sequences = prev.fetch(:action_sequences)
58
+ reps = prev.fetch(:reps)
59
+
60
+ load_stores_stage.call
61
+ checksums = calculate_checksums_stage.call
62
+ outdatedness_checker = create_outdatedness_checker(
63
+ checksums: checksums,
64
+ action_sequences: action_sequences,
65
+ reps: reps,
66
+ )
67
+ outdated_items = determine_outdatedness_stage(outdatedness_checker, reps).call
68
+
69
+ prev.merge(
70
+ checksums: checksums,
71
+ dependency_store: @dependency_store,
72
+ outdatedness_checker: outdatedness_checker,
73
+ outdated_items: outdated_items,
74
+ )
75
+ end
76
+ end
40
77
 
41
- prev.merge(
42
- reps: res.fetch(:reps),
43
- action_sequences: res.fetch(:action_sequences),
78
+ def run_until_end
79
+ res = run_until_precompiled
80
+ action_sequences = res.fetch(:action_sequences)
81
+ reps = res.fetch(:reps)
82
+ checksums = res.fetch(:checksums)
83
+ outdated_items = res.fetch(:outdated_items)
84
+
85
+ forget_outdated_dependencies_stage.call(outdated_items)
86
+ store_pre_compilation_state_stage(action_sequences, reps).call(checksums)
87
+ prune_stage(reps).call
88
+ compile_reps_stage(action_sequences, reps).call
89
+ store_post_compilation_state_stage.call
90
+ postprocess_stage.call(self)
91
+ ensure
92
+ cleanup_stage.call
93
+ end
94
+
95
+ def compilation_context(reps:)
96
+ Nanoc::Int::CompilationContext.new(
97
+ action_provider: @action_provider,
98
+ reps: reps,
99
+ site: @site,
100
+ compiled_content_cache: @compiled_content_cache,
101
+ compiled_content_store: @compiled_content_store,
44
102
  )
45
103
  end
46
- end
47
104
 
48
- def run_until_precompiled
49
- @_res_precompiled ||= begin
50
- prev = run_until_reps_built
51
- action_sequences = prev.fetch(:action_sequences)
52
- reps = prev.fetch(:reps)
105
+ private
53
106
 
54
- load_stores_stage.call
55
- checksums = calculate_checksums_stage.call
56
- outdatedness_checker = create_outdatedness_checker(
57
- checksums: checksums,
107
+ def create_outdatedness_checker(checksums:, action_sequences:, reps:)
108
+ Nanoc::Int::OutdatednessChecker.new(
109
+ site: @site,
110
+ checksum_store: @checksum_store,
111
+ dependency_store: @dependency_store,
112
+ action_sequence_store: @action_sequence_store,
58
113
  action_sequences: action_sequences,
114
+ checksums: checksums,
59
115
  reps: reps,
60
116
  )
61
- outdated_items = determine_outdatedness_stage(outdatedness_checker, reps).call
117
+ end
62
118
 
63
- prev.merge(
64
- checksums: checksums,
119
+ def preprocess_stage
120
+ @_preprocess_stage ||= Stages::Preprocess.new(
121
+ action_provider: @action_provider,
122
+ site: @site,
65
123
  dependency_store: @dependency_store,
66
- outdatedness_checker: outdatedness_checker,
67
- outdated_items: outdated_items,
124
+ checksum_store: @checksum_store,
68
125
  )
69
126
  end
70
- end
71
-
72
- def run_until_end
73
- res = run_until_precompiled
74
- action_sequences = res.fetch(:action_sequences)
75
- reps = res.fetch(:reps)
76
- checksums = res.fetch(:checksums)
77
- outdated_items = res.fetch(:outdated_items)
78
-
79
- forget_outdated_dependencies_stage.call(outdated_items)
80
- store_pre_compilation_state_stage(action_sequences, reps).call(checksums)
81
- prune_stage(reps).call
82
- compile_reps_stage(action_sequences, reps).call
83
- store_post_compilation_state_stage.call
84
- postprocess_stage.call(self)
85
- ensure
86
- cleanup_stage.call
87
- end
88
-
89
- def compilation_context(reps:)
90
- Nanoc::Int::CompilationContext.new(
91
- action_provider: @action_provider,
92
- reps: reps,
93
- site: @site,
94
- compiled_content_cache: @compiled_content_cache,
95
- snapshot_repo: @snapshot_repo,
96
- )
97
- end
98
-
99
- private
100
-
101
- def create_outdatedness_checker(checksums:, action_sequences:, reps:)
102
- Nanoc::Int::OutdatednessChecker.new(
103
- site: @site,
104
- checksum_store: @checksum_store,
105
- dependency_store: @dependency_store,
106
- action_sequence_store: @action_sequence_store,
107
- action_sequences: action_sequences,
108
- checksums: checksums,
109
- reps: reps,
110
- )
111
- end
112
-
113
- def preprocess_stage
114
- @_preprocess_stage ||= Stages::Preprocess.new(
115
- action_provider: @action_provider,
116
- site: @site,
117
- dependency_store: @dependency_store,
118
- checksum_store: @checksum_store,
119
- )
120
- end
121
127
 
122
- def build_reps_stage
123
- @_build_reps_stage ||= Stages::BuildReps.new(
124
- site: @site,
125
- action_provider: @action_provider,
126
- )
127
- end
128
+ def build_reps_stage
129
+ @_build_reps_stage ||= Stages::BuildReps.new(
130
+ site: @site,
131
+ action_provider: @action_provider,
132
+ )
133
+ end
128
134
 
129
- def prune_stage(reps)
130
- @_prune_stage ||= Stages::Prune.new(
131
- config: @site.config,
132
- reps: reps,
133
- )
134
- end
135
+ def prune_stage(reps)
136
+ @_prune_stage ||= Stages::Prune.new(
137
+ config: @site.config,
138
+ reps: reps,
139
+ )
140
+ end
135
141
 
136
- def load_stores_stage
137
- @_load_stores_stage ||= Stages::LoadStores.new(
138
- checksum_store: @checksum_store,
139
- compiled_content_cache: @compiled_content_cache,
140
- dependency_store: @dependency_store,
141
- action_sequence_store: @action_sequence_store,
142
- outdatedness_store: @outdatedness_store,
143
- )
144
- end
142
+ def load_stores_stage
143
+ @_load_stores_stage ||= Stages::LoadStores.new(
144
+ checksum_store: @checksum_store,
145
+ compiled_content_cache: @compiled_content_cache,
146
+ dependency_store: @dependency_store,
147
+ action_sequence_store: @action_sequence_store,
148
+ outdatedness_store: @outdatedness_store,
149
+ )
150
+ end
145
151
 
146
- def calculate_checksums_stage
147
- @_calculate_checksums_stage ||= Stages::CalculateChecksums.new(
148
- items: @site.items,
149
- layouts: @site.layouts,
150
- code_snippets: @site.code_snippets,
151
- config: @site.config,
152
- )
153
- end
152
+ def calculate_checksums_stage
153
+ @_calculate_checksums_stage ||= Stages::CalculateChecksums.new(
154
+ items: @site.items,
155
+ layouts: @site.layouts,
156
+ code_snippets: @site.code_snippets,
157
+ config: @site.config,
158
+ )
159
+ end
154
160
 
155
- def determine_outdatedness_stage(outdatedness_checker, reps)
156
- @_determine_outdatedness_stage ||= Stages::DetermineOutdatedness.new(
157
- reps: reps,
158
- outdatedness_checker: outdatedness_checker,
159
- outdatedness_store: @outdatedness_store,
160
- )
161
- end
161
+ def determine_outdatedness_stage(outdatedness_checker, reps)
162
+ @_determine_outdatedness_stage ||= Stages::DetermineOutdatedness.new(
163
+ reps: reps,
164
+ outdatedness_checker: outdatedness_checker,
165
+ outdatedness_store: @outdatedness_store,
166
+ )
167
+ end
162
168
 
163
- def store_pre_compilation_state_stage(action_sequences, reps)
164
- @_store_pre_compilation_state_stage ||= Stages::StorePreCompilationState.new(
165
- reps: reps,
166
- layouts: @site.layouts,
167
- checksum_store: @checksum_store,
168
- action_sequence_store: @action_sequence_store,
169
- action_sequences: action_sequences,
170
- )
171
- end
169
+ def store_pre_compilation_state_stage(action_sequences, reps)
170
+ @_store_pre_compilation_state_stage ||= Stages::StorePreCompilationState.new(
171
+ reps: reps,
172
+ layouts: @site.layouts,
173
+ checksum_store: @checksum_store,
174
+ action_sequence_store: @action_sequence_store,
175
+ action_sequences: action_sequences,
176
+ )
177
+ end
172
178
 
173
- def compile_reps_stage(action_sequences, reps)
174
- @_compile_reps_stage ||= Stages::CompileReps.new(
175
- reps: reps,
176
- outdatedness_store: @outdatedness_store,
177
- dependency_store: @dependency_store,
178
- action_sequences: action_sequences,
179
- compilation_context: compilation_context(reps: reps),
180
- compiled_content_cache: @compiled_content_cache,
181
- )
182
- end
179
+ def compile_reps_stage(action_sequences, reps)
180
+ @_compile_reps_stage ||= Stages::CompileReps.new(
181
+ reps: reps,
182
+ outdatedness_store: @outdatedness_store,
183
+ dependency_store: @dependency_store,
184
+ action_sequences: action_sequences,
185
+ compilation_context: compilation_context(reps: reps),
186
+ compiled_content_cache: @compiled_content_cache,
187
+ )
188
+ end
183
189
 
184
- def store_post_compilation_state_stage
185
- @_store_post_compilation_state_stage ||= Stages::StorePostCompilationState.new(
186
- dependency_store: @dependency_store,
187
- )
188
- end
190
+ def store_post_compilation_state_stage
191
+ @_store_post_compilation_state_stage ||= Stages::StorePostCompilationState.new(
192
+ dependency_store: @dependency_store,
193
+ )
194
+ end
189
195
 
190
- def postprocess_stage
191
- @_postprocess_stage ||= Stages::Postprocess.new(
192
- action_provider: @action_provider,
193
- site: @site,
194
- )
195
- end
196
+ def postprocess_stage
197
+ @_postprocess_stage ||= Stages::Postprocess.new(
198
+ action_provider: @action_provider,
199
+ site: @site,
200
+ )
201
+ end
196
202
 
197
- def cleanup_stage
198
- @_cleanup_stage ||= Stages::Cleanup.new(@output_dirs)
199
- end
203
+ def cleanup_stage
204
+ @_cleanup_stage ||= Stages::Cleanup.new(@output_dirs)
205
+ end
200
206
 
201
- def forget_outdated_dependencies_stage
202
- @_forget_outdated_dependencies_stage ||= Stages::ForgetOutdatedDependencies.new(
203
- dependency_store: @dependency_store,
204
- )
207
+ def forget_outdated_dependencies_stage
208
+ @_forget_outdated_dependencies_stage ||= Stages::ForgetOutdatedDependencies.new(
209
+ dependency_store: @dependency_store,
210
+ )
211
+ end
205
212
  end
206
213
  end
207
214
  end