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,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Re-exported from Nanoc::Core
4
+ Nanoc::DataSource = Nanoc::Core::DataSource
5
+
3
6
  require_relative 'repos/store'
4
7
 
5
8
  require_relative 'repos/checksum_store'
6
9
  require_relative 'repos/compiled_content_cache'
7
10
  require_relative 'repos/config_loader'
8
- require_relative 'repos/data_source'
9
11
  require_relative 'repos/dependency_store'
10
12
  require_relative 'repos/item_rep_repo'
11
13
  require_relative 'repos/outdatedness_store'
12
14
  require_relative 'repos/action_sequence_store'
13
15
  require_relative 'repos/site_loader'
14
- require_relative 'repos/snapshot_repo'
16
+ require_relative 'repos/compiled_content_store'
15
17
  require_relative 'repos/in_mem_data_source'
16
18
  require_relative 'repos/aggregate_data_source'
17
19
  require_relative 'repos/prefixed_data_source'
@@ -1,48 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- # Stores action sequences for objects that can be run through a rule (item
5
- # representations and layouts).
6
- #
7
- # @api private
8
- class ActionSequenceStore < ::Nanoc::Int::Store
9
- include Nanoc::Int::ContractsSupport
10
-
11
- contract C::KeywordArgs[config: Nanoc::Int::Configuration] => C::Any
12
- def initialize(config:)
13
- super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'rule_memory'), 1)
14
-
15
- @action_sequences = {}
16
- end
17
-
18
- # @param [Nanoc::Int::ItemRep, Nanoc::Int::Layout] obj The item representation or
19
- # the layout to get the action sequence for
20
- #
21
- # @return [Array] The action sequence for the given object
22
- def [](obj)
23
- @action_sequences[obj.reference]
24
- end
25
-
26
- # @param [Nanoc::Int::ItemRep, Nanoc::Int::Layout] obj The item representation or
27
- # the layout to set the action sequence for
28
- #
29
- # @param [Array] action_sequence The new action sequence to be stored
3
+ module Nanoc
4
+ module Int
5
+ # Stores action sequences for objects that can be run through a rule (item
6
+ # representations and layouts).
30
7
  #
31
- # @return [void]
32
- def []=(obj, action_sequence)
33
- @action_sequences[obj.reference] = action_sequence
34
- end
35
-
36
- protected
37
-
38
- # @see Nanoc::Int::Store#data
39
- def data
40
- @action_sequences
41
- end
42
-
43
- # @see Nanoc::Int::Store#data=
44
- def data=(new_data)
45
- @action_sequences = new_data
8
+ # @api private
9
+ class ActionSequenceStore < ::Nanoc::Int::Store
10
+ include Nanoc::Core::ContractsSupport
11
+
12
+ contract C::KeywordArgs[config: Nanoc::Core::Configuration] => C::Any
13
+ def initialize(config:)
14
+ super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'rule_memory'), 1)
15
+
16
+ @action_sequences = {}
17
+ end
18
+
19
+ # @param [Nanoc::Core::ItemRep, Nanoc::Core::Layout] obj The item representation or
20
+ # the layout to get the action sequence for
21
+ #
22
+ # @return [Array] The action sequence for the given object
23
+ def [](obj)
24
+ @action_sequences[obj.reference]
25
+ end
26
+
27
+ # @param [Nanoc::Core::ItemRep, Nanoc::Core::Layout] obj The item representation or
28
+ # the layout to set the action sequence for
29
+ #
30
+ # @param [Array] action_sequence The new action sequence to be stored
31
+ #
32
+ # @return [void]
33
+ def []=(obj, action_sequence)
34
+ @action_sequences[obj.reference] = action_sequence
35
+ end
36
+
37
+ protected
38
+
39
+ # @see Nanoc::Int::Store#data
40
+ def data
41
+ @action_sequences
42
+ end
43
+
44
+ # @see Nanoc::Int::Store#data=
45
+ def data=(new_data)
46
+ @action_sequences = new_data
47
+ end
46
48
  end
47
49
  end
48
50
  end
@@ -1,34 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- class AggregateDataSource < Nanoc::DataSource
5
- def initialize(data_sources, config)
6
- super({}, '/', '/', {})
3
+ module Nanoc
4
+ module Int
5
+ class AggregateDataSource < Nanoc::DataSource
6
+ def initialize(data_sources, config)
7
+ super({}, '/', '/', {})
7
8
 
8
- @data_sources = data_sources
9
- @config = config
10
- end
9
+ @data_sources = data_sources
10
+ @config = config
11
+ end
11
12
 
12
- def items
13
- @_items ||= begin
14
- objs = @data_sources.flat_map(&:items)
15
- Nanoc::Int::ItemCollection.new(@config, objs)
13
+ def items
14
+ @_items ||= begin
15
+ objs = @data_sources.flat_map(&:items)
16
+ Nanoc::Core::ItemCollection.new(@config, objs)
17
+ end
16
18
  end
17
- end
18
19
 
19
- def layouts
20
- @_layouts ||= begin
21
- objs = @data_sources.flat_map(&:layouts)
22
- Nanoc::Int::LayoutCollection.new(@config, objs)
20
+ def layouts
21
+ @_layouts ||= begin
22
+ objs = @data_sources.flat_map(&:layouts)
23
+ Nanoc::Core::LayoutCollection.new(@config, objs)
24
+ end
23
25
  end
24
- end
25
26
 
26
- def item_changes
27
- SlowEnumeratorTools.merge(@data_sources.map(&:item_changes))
28
- end
27
+ def item_changes
28
+ SlowEnumeratorTools.merge(@data_sources.map(&:item_changes))
29
+ end
29
30
 
30
- def layout_changes
31
- SlowEnumeratorTools.merge(@data_sources.map(&:layout_changes))
31
+ def layout_changes
32
+ SlowEnumeratorTools.merge(@data_sources.map(&:layout_changes))
33
+ end
32
34
  end
33
35
  end
34
36
  end
@@ -1,70 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- # Stores checksums for objects in order to be able to detect whether a file
5
- # has changed since the last site compilation.
6
- #
7
- # @api private
8
- class ChecksumStore < ::Nanoc::Int::Store
9
- include Nanoc::Int::ContractsSupport
3
+ module Nanoc
4
+ module Int
5
+ # Stores checksums for objects in order to be able to detect whether a file
6
+ # has changed since the last site compilation.
7
+ #
8
+ # @api private
9
+ class ChecksumStore < ::Nanoc::Int::Store
10
+ include Nanoc::Core::ContractsSupport
10
11
 
11
- attr_writer :checksums
12
- attr_accessor :objects
12
+ attr_writer :checksums
13
+ attr_accessor :objects
13
14
 
14
- c_obj = C::Or[Nanoc::Int::Item, Nanoc::Int::Layout, Nanoc::Int::Configuration, Nanoc::Int::CodeSnippet]
15
+ c_obj = C::Or[Nanoc::Core::Item, Nanoc::Core::Layout, Nanoc::Core::Configuration, Nanoc::Core::CodeSnippet]
15
16
 
16
- contract C::KeywordArgs[config: Nanoc::Int::Configuration, objects: C::IterOf[c_obj]] => C::Any
17
- def initialize(config:, objects:)
18
- super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'checksums'), 2)
17
+ contract C::KeywordArgs[config: Nanoc::Core::Configuration, objects: C::IterOf[c_obj]] => C::Any
18
+ def initialize(config:, objects:)
19
+ super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'checksums'), 2)
19
20
 
20
- @objects = objects
21
+ @objects = objects
21
22
 
22
- @checksums = {}
23
- end
24
-
25
- contract c_obj => C::Maybe[String]
26
- def [](obj)
27
- @checksums[obj.reference]
28
- end
29
-
30
- contract c_obj => self
31
- def add(obj)
32
- if obj.is_a?(Nanoc::Int::Document)
33
- @checksums[[obj.reference, :content]] = Nanoc::Int::Checksummer.calc_for_content_of(obj)
23
+ @checksums = {}
34
24
  end
35
25
 
36
- if obj.is_a?(Nanoc::Int::Document) || obj.is_a?(Nanoc::Int::Configuration)
37
- @checksums[[obj.reference, :each_attribute]] = Nanoc::Int::Checksummer.calc_for_each_attribute_of(obj)
26
+ contract c_obj => C::Maybe[String]
27
+ def [](obj)
28
+ @checksums[obj.reference]
38
29
  end
39
30
 
40
- @checksums[obj.reference] = Nanoc::Int::Checksummer.calc(obj)
31
+ contract c_obj => self
32
+ def add(obj)
33
+ if obj.is_a?(Nanoc::Core::Document)
34
+ @checksums[[obj.reference, :content]] = Nanoc::Core::Checksummer.calc_for_content_of(obj)
35
+ end
41
36
 
42
- self
43
- end
37
+ if obj.is_a?(Nanoc::Core::Document) || obj.is_a?(Nanoc::Core::Configuration)
38
+ @checksums[[obj.reference, :each_attribute]] = Nanoc::Core::Checksummer.calc_for_each_attribute_of(obj)
39
+ end
44
40
 
45
- contract c_obj => C::Maybe[String]
46
- def content_checksum_for(obj)
47
- @checksums[[obj.reference, :content]]
48
- end
41
+ @checksums[obj.reference] = Nanoc::Core::Checksummer.calc(obj)
49
42
 
50
- contract c_obj => C::Maybe[C::HashOf[Symbol, String]]
51
- def attributes_checksum_for(obj)
52
- @checksums[[obj.reference, :each_attribute]]
53
- end
43
+ self
44
+ end
54
45
 
55
- protected
46
+ contract c_obj => C::Maybe[String]
47
+ def content_checksum_for(obj)
48
+ @checksums[[obj.reference, :content]]
49
+ end
56
50
 
57
- def data
58
- @checksums
59
- end
51
+ contract c_obj => C::Maybe[C::HashOf[Symbol, String]]
52
+ def attributes_checksum_for(obj)
53
+ @checksums[[obj.reference, :each_attribute]]
54
+ end
55
+
56
+ protected
57
+
58
+ def data
59
+ @checksums
60
+ end
60
61
 
61
- def data=(new_data)
62
- references = Set.new(@objects.map(&:reference))
62
+ def data=(new_data)
63
+ references = Set.new(@objects.map(&:reference))
63
64
 
64
- @checksums = {}
65
- new_data.each_pair do |key, checksum|
66
- if references.include?(key) || references.include?(key.first)
67
- @checksums[key] = checksum
65
+ @checksums = {}
66
+ new_data.each_pair do |key, checksum|
67
+ if references.include?(key) || references.include?(key.first)
68
+ @checksums[key] = checksum
69
+ end
68
70
  end
69
71
  end
70
72
  end
@@ -1,59 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Nanoc::Int
4
- # Represents a cache than can be used to store already compiled content,
5
- # to prevent it from being needlessly recompiled.
6
- #
7
- # @api private
8
- class CompiledContentCache < ::Nanoc::Int::Store
9
- include Nanoc::Int::ContractsSupport
10
-
11
- contract C::KeywordArgs[config: Nanoc::Int::Configuration] => C::Any
12
- def initialize(config:)
13
- super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'compiled_content'), 2)
14
-
15
- @cache = {}
16
- end
17
-
18
- contract Nanoc::Int::ItemRep => C::Maybe[C::HashOf[Symbol => Nanoc::Int::Content]]
19
- # Returns the cached compiled content for the given item representation.
3
+ module Nanoc
4
+ module Int
5
+ # Represents a cache than can be used to store already compiled content,
6
+ # to prevent it from being needlessly recompiled.
20
7
  #
21
- # This cached compiled content is a hash where the keys are the snapshot
22
- # names. and the values the compiled content at the given snapshot.
23
- def [](rep)
24
- item_cache = @cache[rep.item.identifier] || {}
25
- item_cache[rep.name]
26
- end
8
+ # @api private
9
+ class CompiledContentCache < ::Nanoc::Int::Store
10
+ include Nanoc::Core::ContractsSupport
27
11
 
28
- contract Nanoc::Int::ItemRep, C::HashOf[Symbol => Nanoc::Int::Content] => C::HashOf[Symbol => Nanoc::Int::Content]
29
- # Sets the compiled content for the given representation.
30
- #
31
- # This cached compiled content is a hash where the keys are the snapshot
32
- # names. and the values the compiled content at the given snapshot.
33
- def []=(rep, content)
34
- @cache[rep.item.identifier] ||= {}
35
- @cache[rep.item.identifier][rep.name] = content
36
- end
12
+ contract C::KeywordArgs[config: Nanoc::Core::Configuration] => C::Any
13
+ def initialize(config:)
14
+ super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'compiled_content'), 2)
37
15
 
38
- def prune(items:)
39
- item_identifiers = Set.new(items.map(&:identifier))
16
+ @cache = {}
17
+ end
40
18
 
41
- @cache.keys.each do |key|
42
- @cache.delete(key) unless item_identifiers.include?(key)
19
+ contract Nanoc::Core::ItemRep => C::Maybe[C::HashOf[Symbol => Nanoc::Core::Content]]
20
+ # Returns the cached compiled content for the given item representation.
21
+ #
22
+ # This cached compiled content is a hash where the keys are the snapshot
23
+ # names. and the values the compiled content at the given snapshot.
24
+ def [](rep)
25
+ item_cache = @cache[rep.item.identifier] || {}
26
+ item_cache[rep.name]
43
27
  end
44
- end
45
28
 
46
- protected
29
+ contract Nanoc::Core::ItemRep, C::HashOf[Symbol => Nanoc::Core::Content] => C::HashOf[Symbol => Nanoc::Core::Content]
30
+ # Sets the compiled content for the given representation.
31
+ #
32
+ # This cached compiled content is a hash where the keys are the snapshot
33
+ # names. and the values the compiled content at the given snapshot.
34
+ def []=(rep, content)
35
+ @cache[rep.item.identifier] ||= {}
36
+ @cache[rep.item.identifier][rep.name] = content
37
+ end
47
38
 
48
- def data
49
- @cache
50
- end
39
+ def prune(items:)
40
+ item_identifiers = Set.new(items.map(&:identifier))
41
+
42
+ @cache.keys.each do |key|
43
+ @cache.delete(key) unless item_identifiers.include?(key)
44
+ end
45
+ end
46
+
47
+ protected
48
+
49
+ def data
50
+ @cache
51
+ end
51
52
 
52
- def data=(new_data)
53
- @cache = {}
53
+ def data=(new_data)
54
+ @cache = {}
54
55
 
55
- new_data.each_pair do |item_identifier, content_per_rep|
56
- @cache[item_identifier] ||= content_per_rep
56
+ new_data.each_pair do |item_identifier, content_per_rep|
57
+ @cache[item_identifier] ||= content_per_rep
58
+ end
57
59
  end
58
60
  end
59
61
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Int
5
+ # @api private
6
+ class CompiledContentStore
7
+ include Nanoc::Core::ContractsSupport
8
+
9
+ def initialize
10
+ @contents = Hash.new { |hash, rep| hash[rep] = {} }
11
+ @current_content = {}
12
+ end
13
+
14
+ contract Nanoc::Core::ItemRep, Symbol => C::Maybe[Nanoc::Core::Content]
15
+ def get(rep, snapshot_name)
16
+ @contents[rep][snapshot_name]
17
+ end
18
+
19
+ contract Nanoc::Core::ItemRep => C::Maybe[Nanoc::Core::Content]
20
+ def get_current(rep)
21
+ @current_content[rep]
22
+ end
23
+
24
+ contract Nanoc::Core::ItemRep, Symbol, Nanoc::Core::Content => C::Any
25
+ def set(rep, snapshot_name, contents)
26
+ @contents[rep][snapshot_name] = contents
27
+ end
28
+
29
+ contract Nanoc::Core::ItemRep, Nanoc::Core::Content => C::Any
30
+ def set_current(rep, content)
31
+ @current_content[rep] = content
32
+ end
33
+
34
+ contract Nanoc::Core::ItemRep => C::HashOf[Symbol => Nanoc::Core::Content]
35
+ def get_all(rep)
36
+ @contents[rep]
37
+ end
38
+
39
+ contract Nanoc::Core::ItemRep, C::HashOf[Symbol => Nanoc::Core::Content] => C::Any
40
+ def set_all(rep, contents_per_snapshot)
41
+ @contents[rep] = contents_per_snapshot
42
+ end
43
+
44
+ contract C::KeywordArgs[rep: Nanoc::Core::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => Nanoc::Core::Content
45
+ def raw_compiled_content(rep:, snapshot: nil)
46
+ # Get name of last pre-layout snapshot
47
+ snapshot_name = snapshot || (get(rep, :pre) ? :pre : :last)
48
+
49
+ # Check existance of snapshot
50
+ snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
51
+ unless snapshot_def
52
+ raise Nanoc::Int::Errors::NoSuchSnapshot.new(rep, snapshot_name)
53
+ end
54
+
55
+ # Return content if it is available
56
+ content = get(rep, snapshot_name)
57
+ return content if content
58
+
59
+ # Content is unavailable; notify and try again
60
+ Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(rep, snapshot_name))
61
+ get(rep, snapshot_name)
62
+ end
63
+
64
+ contract C::KeywordArgs[rep: Nanoc::Core::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => String
65
+ def compiled_content(rep:, snapshot: nil)
66
+ snapshot_content = raw_compiled_content(rep: rep, snapshot: snapshot)
67
+
68
+ if snapshot_content.binary?
69
+ raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
70
+ end
71
+
72
+ snapshot_content.string
73
+ end
74
+ end
75
+ end
76
+ end