nanoc 4.11.0 → 4.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +6 -0
- data/lib/nanoc.rb +4 -7
- data/lib/nanoc/base.rb +3 -3
- data/lib/nanoc/base/assertions.rb +1 -1
- data/lib/nanoc/base/entities.rb +2 -20
- data/lib/nanoc/base/entities/action_sequence.rb +60 -64
- data/lib/nanoc/base/entities/checksum_collection.rb +23 -21
- data/lib/nanoc/base/entities/dependency.rb +24 -22
- data/lib/nanoc/base/entities/outdatedness_reasons.rb +74 -72
- data/lib/nanoc/base/entities/outdatedness_status.rb +19 -17
- data/lib/nanoc/base/entities/props.rb +119 -117
- data/lib/nanoc/base/entities/site.rb +46 -50
- data/lib/nanoc/base/errors.rb +183 -198
- data/lib/nanoc/base/repos.rb +4 -2
- data/lib/nanoc/base/repos/action_sequence_store.rb +44 -42
- data/lib/nanoc/base/repos/aggregate_data_source.rb +24 -22
- data/lib/nanoc/base/repos/checksum_store.rb +51 -49
- data/lib/nanoc/base/repos/compiled_content_cache.rb +47 -45
- data/lib/nanoc/base/repos/compiled_content_store.rb +76 -0
- data/lib/nanoc/base/repos/config_loader.rb +74 -72
- data/lib/nanoc/base/repos/dependency_store.rb +174 -172
- data/lib/nanoc/base/repos/in_mem_data_source.rb +17 -15
- data/lib/nanoc/base/repos/item_rep_repo.rb +26 -24
- data/lib/nanoc/base/repos/outdatedness_store.rb +50 -48
- data/lib/nanoc/base/repos/prefixed_data_source.rb +21 -19
- data/lib/nanoc/base/repos/site_loader.rb +75 -73
- data/lib/nanoc/base/repos/store.rb +93 -91
- data/lib/nanoc/base/services.rb +7 -3
- data/lib/nanoc/base/services/action_provider.rb +23 -21
- data/lib/nanoc/base/services/action_sequence_builder.rb +42 -34
- data/lib/nanoc/base/services/compilation_context.rb +49 -47
- data/lib/nanoc/base/services/compiler.rb +177 -170
- data/lib/nanoc/base/services/compiler/phases.rb +8 -1
- data/lib/nanoc/base/services/compiler/phases/abstract.rb +44 -38
- data/lib/nanoc/base/services/compiler/phases/cache.rb +34 -28
- data/lib/nanoc/base/services/compiler/phases/mark_done.rb +17 -11
- data/lib/nanoc/base/services/compiler/phases/notify.rb +21 -0
- data/lib/nanoc/base/services/compiler/phases/recalculate.rb +37 -31
- data/lib/nanoc/base/services/compiler/phases/resume.rb +47 -48
- data/lib/nanoc/base/services/compiler/phases/write.rb +65 -59
- data/lib/nanoc/base/services/compiler/stage.rb +27 -8
- data/lib/nanoc/base/services/compiler/stages.rb +7 -1
- data/lib/nanoc/base/services/compiler/stages/build_reps.rb +25 -19
- data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +34 -28
- data/lib/nanoc/base/services/compiler/stages/cleanup.rb +33 -27
- data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +79 -69
- data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +46 -40
- data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +15 -9
- data/lib/nanoc/base/services/compiler/stages/load_stores.rb +28 -22
- data/lib/nanoc/base/services/compiler/stages/postprocess.rb +16 -10
- data/lib/nanoc/base/services/compiler/stages/preprocess.rb +25 -19
- data/lib/nanoc/base/services/compiler/stages/prune.rb +23 -17
- data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +15 -9
- data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +26 -20
- data/lib/nanoc/base/services/compiler_loader.rb +26 -24
- data/lib/nanoc/base/services/dependency_tracker.rb +47 -45
- data/lib/nanoc/base/services/executor.rb +16 -15
- data/lib/nanoc/base/services/filter.rb +37 -5
- data/lib/nanoc/base/services/instrumentor.rb +12 -10
- data/lib/nanoc/base/services/item_rep_builder.rb +21 -19
- data/lib/nanoc/base/services/item_rep_router.rb +72 -70
- data/lib/nanoc/base/services/item_rep_selector.rb +48 -46
- data/lib/nanoc/base/services/item_rep_writer.rb +58 -53
- data/lib/nanoc/base/services/outdatedness_checker.rb +181 -179
- data/lib/nanoc/base/services/outdatedness_rule.rb +23 -21
- data/lib/nanoc/base/services/outdatedness_rules.rb +5 -3
- data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +28 -24
- data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +20 -16
- data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +13 -9
- data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +12 -8
- data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +12 -8
- data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +10 -6
- data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +39 -35
- data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +19 -15
- data/lib/nanoc/base/services/pruner.rb +2 -2
- data/lib/nanoc/base/views.rb +7 -0
- data/lib/nanoc/base/views/basic_item_view.rb +1 -1
- data/lib/nanoc/base/views/compilation_item_rep_view.rb +2 -2
- data/lib/nanoc/base/views/identifiable_collection_view.rb +2 -2
- data/lib/nanoc/base/views/mixins/document_view_mixin.rb +1 -1
- data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +5 -5
- data/lib/nanoc/base/views/mutable_item_collection_view.rb +3 -3
- data/lib/nanoc/base/views/mutable_layout_collection_view.rb +2 -2
- data/lib/nanoc/base/views/view_context_for_compilation.rb +6 -6
- data/lib/nanoc/base/views/view_context_for_pre_compilation.rb +2 -2
- data/lib/nanoc/base/views/view_context_for_shell.rb +2 -2
- data/lib/nanoc/checking/check.rb +1 -1
- data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +24 -7
- data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +79 -15
- data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +4 -7
- data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +15 -24
- data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +22 -18
- data/lib/nanoc/cli/commands/create-site.rb +2 -7
- data/lib/nanoc/cli/commands/shell.rb +1 -1
- data/lib/nanoc/cli/commands/show-data.rb +9 -9
- data/lib/nanoc/cli/logger.rb +1 -1
- data/lib/nanoc/data_sources/filesystem.rb +8 -8
- data/lib/nanoc/filters/erb.rb +1 -1
- data/lib/nanoc/filters/erubi.rb +1 -1
- data/lib/nanoc/filters/erubis.rb +1 -1
- data/lib/nanoc/filters/haml.rb +1 -1
- data/lib/nanoc/filters/sass.rb +1 -1
- data/lib/nanoc/filters/slim.rb +1 -1
- data/lib/nanoc/helpers/breadcrumbs.rb +2 -2
- data/lib/nanoc/helpers/capturing.rb +9 -8
- data/lib/nanoc/helpers/filtering.rb +2 -2
- data/lib/nanoc/helpers/rendering.rb +1 -1
- data/lib/nanoc/rule_dsl.rb +10 -0
- data/lib/nanoc/rule_dsl/action_provider.rb +3 -3
- data/lib/nanoc/rule_dsl/action_recorder.rb +3 -3
- data/lib/nanoc/rule_dsl/action_sequence_calculator.rb +7 -7
- data/lib/nanoc/rule_dsl/compilation_rule.rb +2 -2
- data/lib/nanoc/rule_dsl/compilation_rule_context.rb +9 -9
- data/lib/nanoc/rule_dsl/compiler_dsl.rb +4 -4
- data/lib/nanoc/rule_dsl/routing_rule.rb +3 -3
- data/lib/nanoc/rule_dsl/rule.rb +5 -5
- data/lib/nanoc/rule_dsl/rule_context.rb +3 -3
- data/lib/nanoc/rule_dsl/rules_collection.rb +4 -4
- data/lib/nanoc/spec.rb +15 -15
- data/lib/nanoc/version.rb +1 -1
- metadata +10 -111
- data/lib/nanoc/base/contracts_support.rb +0 -130
- data/lib/nanoc/base/core_ext.rb +0 -5
- data/lib/nanoc/base/core_ext/array.rb +0 -50
- data/lib/nanoc/base/core_ext/hash.rb +0 -54
- data/lib/nanoc/base/core_ext/string.rb +0 -16
- data/lib/nanoc/base/entities/code_snippet.rb +0 -53
- data/lib/nanoc/base/entities/configuration-schema.json +0 -122
- data/lib/nanoc/base/entities/configuration.rb +0 -206
- data/lib/nanoc/base/entities/content.rb +0 -112
- data/lib/nanoc/base/entities/context.rb +0 -70
- data/lib/nanoc/base/entities/directed_graph.rb +0 -195
- data/lib/nanoc/base/entities/document.rb +0 -125
- data/lib/nanoc/base/entities/identifiable_collection.rb +0 -141
- data/lib/nanoc/base/entities/identifier.rb +0 -222
- data/lib/nanoc/base/entities/item.rb +0 -10
- data/lib/nanoc/base/entities/item_collection.rb +0 -14
- data/lib/nanoc/base/entities/item_rep.rb +0 -91
- data/lib/nanoc/base/entities/layout.rb +0 -10
- data/lib/nanoc/base/entities/layout_collection.rb +0 -14
- data/lib/nanoc/base/entities/lazy_value.rb +0 -43
- data/lib/nanoc/base/entities/pattern.rb +0 -85
- data/lib/nanoc/base/entities/processing_action.rb +0 -21
- data/lib/nanoc/base/entities/processing_actions.rb +0 -5
- data/lib/nanoc/base/entities/processing_actions/filter.rb +0 -36
- data/lib/nanoc/base/entities/processing_actions/layout.rb +0 -36
- data/lib/nanoc/base/entities/processing_actions/snapshot.rb +0 -46
- data/lib/nanoc/base/entities/snapshot_def.rb +0 -22
- data/lib/nanoc/base/repos/data_source.rb +0 -168
- data/lib/nanoc/base/repos/snapshot_repo.rb +0 -67
- data/lib/nanoc/base/services/checksummer.rb +0 -274
- data/lib/nanoc/base/services/notification_center.rb +0 -87
- data/lib/nanoc/base/services/temp_filename_factory.rb +0 -52
data/lib/nanoc/base/repos.rb
CHANGED
@@ -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/
|
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
|
4
|
-
|
5
|
-
|
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
|
-
# @
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
class AggregateDataSource < Nanoc::DataSource
|
6
|
+
def initialize(data_sources, config)
|
7
|
+
super({}, '/', '/', {})
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
@data_sources = data_sources
|
10
|
+
@config = config
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def item_changes
|
28
|
+
SlowEnumeratorTools.merge(@data_sources.map(&:item_changes))
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
12
|
+
attr_writer :checksums
|
13
|
+
attr_accessor :objects
|
13
14
|
|
14
|
-
|
15
|
+
c_obj = C::Or[Nanoc::Core::Item, Nanoc::Core::Layout, Nanoc::Core::Configuration, Nanoc::Core::CodeSnippet]
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
+
@objects = objects
|
21
22
|
|
22
|
-
|
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
|
-
|
37
|
-
|
26
|
+
contract c_obj => C::Maybe[String]
|
27
|
+
def [](obj)
|
28
|
+
@checksums[obj.reference]
|
38
29
|
end
|
39
30
|
|
40
|
-
|
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
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
@checksums[[obj.reference, :each_attribute]]
|
53
|
-
end
|
43
|
+
self
|
44
|
+
end
|
54
45
|
|
55
|
-
|
46
|
+
contract c_obj => C::Maybe[String]
|
47
|
+
def content_checksum_for(obj)
|
48
|
+
@checksums[[obj.reference, :content]]
|
49
|
+
end
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
62
|
+
def data=(new_data)
|
63
|
+
references = Set.new(@objects.map(&:reference))
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
4
|
-
|
5
|
-
|
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
|
-
#
|
22
|
-
|
23
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
39
|
-
|
16
|
+
@cache = {}
|
17
|
+
end
|
40
18
|
|
41
|
-
|
42
|
-
|
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
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
53
|
+
def data=(new_data)
|
54
|
+
@cache = {}
|
54
55
|
|
55
|
-
|
56
|
-
|
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
|