nanoc 4.11.0 → 4.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,24 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
class InMemDataSource < Nanoc::DataSource
|
6
|
+
attr_reader :items
|
7
|
+
attr_reader :layouts
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
def initialize(items, layouts, orig_data_source = nil)
|
10
|
+
super({}, '/', '/', {})
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
@items = items
|
13
|
+
@layouts = layouts
|
14
|
+
@orig_data_source = orig_data_source
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def item_changes
|
18
|
+
@orig_data_source ? @orig_data_source.item_changes : super
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def layout_changes
|
22
|
+
@orig_data_source ? @orig_data_source.layout_changes : super
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
# Stores item reps (in memory).
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
class ItemRepRepo
|
9
|
+
include Enumerable
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def initialize
|
12
|
+
@reps = []
|
13
|
+
@reps_by_item = {}
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def <<(rep)
|
17
|
+
@reps << rep
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
@reps_by_item[rep.item] ||= []
|
20
|
+
@reps_by_item[rep.item] << rep
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def to_a
|
24
|
+
@reps
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def each(&block)
|
28
|
+
@reps.each(&block)
|
29
|
+
self
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def [](item)
|
33
|
+
@reps_by_item.fetch(item, [])
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,53 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
# @api private
|
6
|
+
class OutdatednessStore < ::Nanoc::Int::Store
|
7
|
+
include Nanoc::Core::ContractsSupport
|
8
|
+
|
9
|
+
contract C::KeywordArgs[config: Nanoc::Core::Configuration] => C::Any
|
10
|
+
def initialize(config:)
|
11
|
+
super(Nanoc::Int::Store.tmp_path_for(config: config, store_name: 'outdatedness'), 1)
|
12
|
+
|
13
|
+
@outdated_refs = Set.new
|
14
|
+
end
|
15
|
+
|
16
|
+
contract Nanoc::Core::ItemRep => C::Bool
|
17
|
+
def include?(obj)
|
18
|
+
@outdated_refs.include?(obj.reference)
|
19
|
+
end
|
20
|
+
|
21
|
+
contract Nanoc::Core::ItemRep => self
|
22
|
+
def add(obj)
|
23
|
+
@outdated_refs << obj.reference
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
contract Nanoc::Core::ItemRep => self
|
28
|
+
def remove(obj)
|
29
|
+
@outdated_refs.delete(obj.reference)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
contract C::None => C::Bool
|
34
|
+
def empty?
|
35
|
+
@outdated_refs.empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
contract C::None => self
|
39
|
+
def clear
|
40
|
+
@outdated_refs = Set.new
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def data
|
47
|
+
@outdated_refs
|
48
|
+
end
|
49
|
+
|
50
|
+
def data=(new_data)
|
51
|
+
@outdated_refs = Set.new(new_data)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -1,29 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
class PrefixedDataSource < Nanoc::DataSource
|
6
|
+
def initialize(data_source, items_prefix, layouts_prefix)
|
7
|
+
super({}, '/', '/', {})
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
@data_source = data_source
|
10
|
+
@items_prefix = items_prefix
|
11
|
+
@layouts_prefix = layouts_prefix
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def items
|
15
|
+
@data_source.items.map { |d| d.with_identifier_prefix(@items_prefix) }
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def layouts
|
19
|
+
@data_source.layouts.map { |d| d.with_identifier_prefix(@layouts_prefix) }
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def item_changes
|
23
|
+
@data_source.item_changes
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
def layout_changes
|
27
|
+
@data_source.layout_changes
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,100 +1,102 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
class SiteLoader
|
6
|
+
def new_from_cwd
|
7
|
+
site_from_config(Nanoc::Int::ConfigLoader.new.new_from_cwd)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# @return [Boolean]
|
11
|
+
def self.cwd_is_nanoc_site?
|
12
|
+
Nanoc::Int::ConfigLoader.cwd_is_nanoc_site?
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def gen_data_source_for_config(config)
|
16
|
+
data_sources_to_aggregate =
|
17
|
+
with_data_sources(config) do |data_sources|
|
18
|
+
data_sources.map do |ds|
|
19
|
+
Nanoc::Int::PrefixedDataSource.new(ds, ds.items_root, ds.layouts_root)
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
Nanoc::Int::AggregateDataSource.new(data_sources_to_aggregate, config)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
private
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def site_from_config(config)
|
29
|
+
code_snippets = code_snippets_from_config(config)
|
30
|
+
code_snippets.each(&:load)
|
30
31
|
|
31
|
-
|
32
|
+
data_source = gen_data_source_for_config(config)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
Nanoc::Int::Site.new(
|
35
|
+
config: config,
|
36
|
+
code_snippets: code_snippets,
|
37
|
+
data_source: data_source,
|
38
|
+
)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
def with_data_sources(config, &_block)
|
42
|
+
data_sources = create_data_sources(config)
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
begin
|
45
|
+
data_sources.each(&:use)
|
46
|
+
yield(data_sources)
|
47
|
+
ensure
|
48
|
+
data_sources.each(&:unuse)
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
def create_data_sources(config)
|
53
|
+
config[:data_sources].map do |data_source_hash|
|
54
|
+
# Get data source class
|
55
|
+
data_source_class = Nanoc::DataSource.named(data_source_hash[:type].to_sym)
|
56
|
+
if data_source_class.nil?
|
57
|
+
raise Nanoc::Int::Errors::UnknownDataSource.new(data_source_hash[:type])
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
# Create data source
|
61
|
+
data_source_class.new(
|
62
|
+
config,
|
63
|
+
data_source_hash[:items_root],
|
64
|
+
data_source_hash[:layouts_root],
|
65
|
+
data_source_hash.merge(data_source_hash[:config] || {}),
|
66
|
+
)
|
67
|
+
end
|
66
68
|
end
|
67
|
-
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
def code_snippets_from_config(config)
|
71
|
+
config[:lib_dirs].flat_map do |lib|
|
72
|
+
Dir["#{lib}/**/*.rb"].sort.map do |filename|
|
73
|
+
Nanoc::Core::CodeSnippet.new(
|
74
|
+
read_code_snippet_contents(filename),
|
75
|
+
filename,
|
76
|
+
)
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
78
|
-
end
|
79
80
|
|
80
|
-
|
81
|
+
ENCODING_REGEX = /\A#\s+(-\*-\s+)?(en)?coding: (?<encoding>[^\s]+)(\s+-\*-\s*)?\n{0,2}/.freeze
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
def encoding_from_magic_comment(raw)
|
84
|
+
match = ENCODING_REGEX.match(raw)
|
85
|
+
match ? match['encoding'] : nil
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
def read_code_snippet_contents(filename)
|
89
|
+
raw = File.read(filename, encoding: 'ASCII-8BIT')
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
enc = encoding_from_magic_comment(raw)
|
92
|
+
if enc
|
93
|
+
raw = raw.force_encoding(enc).encode('UTF-8').sub(ENCODING_REGEX, '')
|
94
|
+
else
|
95
|
+
raw.force_encoding('UTF-8')
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
+
raw
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
@@ -1,112 +1,114 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Nanoc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# Each store has a version number. When attempting to load data from a store
|
9
|
-
# that has an incompatible version number, no data will be loaded, but
|
10
|
-
# {#version_mismatch_detected} will be called.
|
11
|
-
#
|
12
|
-
# @abstract Subclasses must implement {#data} and {#data=}, and may
|
13
|
-
# implement {#no_data_found} and {#version_mismatch_detected}.
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
class Store
|
17
|
-
include Nanoc::Int::ContractsSupport
|
18
|
-
|
19
|
-
# @return [String] The name of the file where data will be loaded from and
|
20
|
-
# stored to.
|
21
|
-
attr_reader :filename
|
22
|
-
|
23
|
-
# @return [Numeric] The version number corresponding to the file format
|
24
|
-
# the data is in. When the file format changes, the version number
|
25
|
-
# should be incremented.
|
26
|
-
attr_reader :version
|
27
|
-
|
28
|
-
# Creates a new store for the given filename.
|
3
|
+
module Nanoc
|
4
|
+
module Int
|
5
|
+
# An abstract superclass for classes that need to store data to the
|
6
|
+
# filesystem, such as checksums, cached compiled content and dependency
|
7
|
+
# graphs.
|
29
8
|
#
|
30
|
-
#
|
31
|
-
#
|
9
|
+
# Each store has a version number. When attempting to load data from a store
|
10
|
+
# that has an incompatible version number, no data will be loaded, but
|
11
|
+
# {#version_mismatch_detected} will be called.
|
12
|
+
#
|
13
|
+
# @abstract Subclasses must implement {#data} and {#data=}, and may
|
14
|
+
# implement {#no_data_found} and {#version_mismatch_detected}.
|
32
15
|
#
|
33
|
-
# @param [Numeric] version The version number corresponding to the file
|
34
|
-
# format the data is in. When the file format changes, the version
|
35
|
-
# number should be incremented.
|
36
|
-
def initialize(filename, version)
|
37
|
-
@filename = filename
|
38
|
-
@version = version
|
39
|
-
end
|
40
|
-
|
41
|
-
# Logic for building tmp path from active environment and store name
|
42
16
|
# @api private
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
17
|
+
class Store
|
18
|
+
include Nanoc::Core::ContractsSupport
|
19
|
+
|
20
|
+
# @return [String] The name of the file where data will be loaded from and
|
21
|
+
# stored to.
|
22
|
+
attr_reader :filename
|
23
|
+
|
24
|
+
# @return [Numeric] The version number corresponding to the file format
|
25
|
+
# the data is in. When the file format changes, the version number
|
26
|
+
# should be incremented.
|
27
|
+
attr_reader :version
|
28
|
+
|
29
|
+
# Creates a new store for the given filename.
|
30
|
+
#
|
31
|
+
# @param [String] filename The name of the file where data will be loaded
|
32
|
+
# from and stored to.
|
33
|
+
#
|
34
|
+
# @param [Numeric] version The version number corresponding to the file
|
35
|
+
# format the data is in. When the file format changes, the version
|
36
|
+
# number should be incremented.
|
37
|
+
def initialize(filename, version)
|
38
|
+
@filename = filename
|
39
|
+
@version = version
|
40
|
+
end
|
55
41
|
|
56
|
-
|
42
|
+
# Logic for building tmp path from active environment and store name
|
43
|
+
# @api private
|
44
|
+
contract C::KeywordArgs[config: Nanoc::Core::Configuration, store_name: String] => C::AbsolutePathString
|
45
|
+
def self.tmp_path_for(store_name:, config:)
|
46
|
+
File.absolute_path(
|
47
|
+
File.join(tmp_path_prefix(config.output_dir), store_name),
|
48
|
+
config.dir,
|
49
|
+
)
|
50
|
+
end
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=')
|
63
|
-
end
|
52
|
+
def self.tmp_path_prefix(output_dir)
|
53
|
+
dir = Digest::SHA1.hexdigest(output_dir)[0..12]
|
54
|
+
File.join('tmp', 'nanoc', dir)
|
55
|
+
end
|
64
56
|
|
65
|
-
|
66
|
-
#
|
67
|
-
# @abstract This method must be implemented by the subclass.
|
68
|
-
#
|
69
|
-
# @return [void]
|
70
|
-
def data=(new_data) # rubocop:disable Lint/UnusedMethodArgument
|
71
|
-
raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=')
|
72
|
-
end
|
57
|
+
# @group Loading and storing data
|
73
58
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
59
|
+
# @return The data that should be written to the disk
|
60
|
+
#
|
61
|
+
# @abstract This method must be implemented by the subclass.
|
62
|
+
def data
|
63
|
+
raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=')
|
64
|
+
end
|
80
65
|
|
81
|
-
|
82
|
-
|
83
|
-
|
66
|
+
# @param new_data The data that has been loaded from the disk
|
67
|
+
#
|
68
|
+
# @abstract This method must be implemented by the subclass.
|
69
|
+
#
|
70
|
+
# @return [void]
|
71
|
+
def data=(new_data) # rubocop:disable Lint/UnusedMethodArgument
|
72
|
+
raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=')
|
73
|
+
end
|
84
74
|
|
85
|
-
|
75
|
+
# Loads the data from the filesystem into memory. This method will set the
|
76
|
+
# loaded data using the {#data=} method.
|
77
|
+
#
|
78
|
+
# @return [void]
|
79
|
+
def load
|
80
|
+
return unless File.file?(filename)
|
81
|
+
|
82
|
+
begin
|
83
|
+
pstore.transaction do
|
84
|
+
return if pstore[:version] != version
|
85
|
+
|
86
|
+
self.data = pstore[:data]
|
87
|
+
end
|
88
|
+
rescue
|
89
|
+
FileUtils.rm_f(filename)
|
90
|
+
load
|
86
91
|
end
|
87
|
-
rescue
|
88
|
-
FileUtils.rm_f(filename)
|
89
|
-
load
|
90
92
|
end
|
91
|
-
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
# Stores the data contained in memory to the filesystem. This method will
|
95
|
+
# use the {#data} method to fetch the data that should be written.
|
96
|
+
#
|
97
|
+
# @return [void]
|
98
|
+
def store
|
99
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
pstore.transaction do
|
102
|
+
pstore[:data] = data
|
103
|
+
pstore[:version] = version
|
104
|
+
end
|
103
105
|
end
|
104
|
-
end
|
105
106
|
|
106
|
-
|
107
|
+
private
|
107
108
|
|
108
|
-
|
109
|
-
|
109
|
+
def pstore
|
110
|
+
@pstore ||= PStore.new(filename)
|
111
|
+
end
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|