nanoc-core 4.14.6 → 4.14.8
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/lib/nanoc/core/action_sequence.rb +1 -1
- data/lib/nanoc/core/action_sequence_builder.rb +12 -4
- data/lib/nanoc/core/action_sequence_store.rb +8 -5
- data/lib/nanoc/core/assertions.rb +12 -2
- data/lib/nanoc/core/basic_outdatedness_checker.rb +26 -10
- data/lib/nanoc/core/binary_compiled_content_cache.rb +24 -10
- data/lib/nanoc/core/checksum_collection.rb +7 -2
- data/lib/nanoc/core/checksum_store.rb +26 -9
- data/lib/nanoc/core/checksummer.rb +63 -32
- data/lib/nanoc/core/code_snippet.rb +1 -1
- data/lib/nanoc/core/compilation_stages/build_reps.rb +7 -2
- data/lib/nanoc/core/compilation_stages/calculate_checksums.rb +2 -0
- data/lib/nanoc/core/compilation_stages/cleanup.rb +8 -2
- data/lib/nanoc/core/compilation_stages/compile_reps.rb +78 -36
- data/lib/nanoc/core/compilation_stages/determine_outdatedness.rb +2 -0
- data/lib/nanoc/core/compilation_stages/forget_outdated_dependencies.rb +5 -1
- data/lib/nanoc/core/compilation_stages/load_stores.rb +6 -1
- data/lib/nanoc/core/compilation_stages/postprocess.rb +2 -0
- data/lib/nanoc/core/compilation_stages/preprocess.rb +12 -3
- data/lib/nanoc/core/compilation_stages/prune.rb +6 -1
- data/lib/nanoc/core/compilation_stages/store_post_compilation_state.rb +2 -0
- data/lib/nanoc/core/compilation_stages/store_pre_compilation_state.rb +6 -1
- data/lib/nanoc/core/compiled_content_cache.rb +7 -2
- data/lib/nanoc/core/compiled_content_repo.rb +13 -5
- data/lib/nanoc/core/compiler.rb +12 -3
- data/lib/nanoc/core/compiler_loader.rb +13 -4
- data/lib/nanoc/core/config_loader.rb +14 -4
- data/lib/nanoc/core/configuration.rb +36 -15
- data/lib/nanoc/core/content.rb +5 -1
- data/lib/nanoc/core/context.rb +4 -5
- data/lib/nanoc/core/contracts_support.rb +26 -8
- data/lib/nanoc/core/core_ext/hash.rb +12 -2
- data/lib/nanoc/core/data_source.rb +22 -6
- data/lib/nanoc/core/dependency.rb +8 -2
- data/lib/nanoc/core/dependency_props.rb +27 -8
- data/lib/nanoc/core/dependency_store.rb +55 -22
- data/lib/nanoc/core/dependency_tracker.rb +20 -4
- data/lib/nanoc/core/directed_graph.rb +27 -64
- data/lib/nanoc/core/document.rb +4 -1
- data/lib/nanoc/core/errors.rb +45 -12
- data/lib/nanoc/core/executor.rb +26 -9
- data/lib/nanoc/core/feature.rb +2 -1
- data/lib/nanoc/core/filter.rb +27 -11
- data/lib/nanoc/core/identifiable_collection.rb +2 -1
- data/lib/nanoc/core/identifier.rb +23 -8
- data/lib/nanoc/core/in_memory_data_source.rb +3 -1
- data/lib/nanoc/core/item.rb +1 -1
- data/lib/nanoc/core/item_collection.rb +2 -2
- data/lib/nanoc/core/item_rep.rb +1 -1
- data/lib/nanoc/core/item_rep_builder.rb +14 -5
- data/lib/nanoc/core/item_rep_router.rb +27 -13
- data/lib/nanoc/core/item_rep_writer.rb +28 -5
- data/lib/nanoc/core/layout.rb +1 -1
- data/lib/nanoc/core/layout_collection.rb +2 -2
- data/lib/nanoc/core/mutable_document_view_mixin.rb +3 -6
- data/lib/nanoc/core/outdatedness_checker.rb +170 -95
- data/lib/nanoc/core/outdatedness_reasons.rb +45 -16
- data/lib/nanoc/core/outdatedness_rules/attributes_modified.rb +24 -10
- data/lib/nanoc/core/outdatedness_rules/item_added.rb +9 -4
- data/lib/nanoc/core/outdatedness_rules/layout_added.rb +9 -4
- data/lib/nanoc/core/outdatedness_rules/not_written.rb +7 -2
- data/lib/nanoc/core/outdatedness_rules/rules_modified.rb +14 -6
- data/lib/nanoc/core/outdatedness_rules/uses_always_outdated_filter.rb +1 -1
- data/lib/nanoc/core/outdatedness_store.rb +7 -1
- data/lib/nanoc/core/pattern.rb +4 -1
- data/lib/nanoc/core/prefixed_data_source.rb +6 -2
- data/lib/nanoc/core/processing_actions/filter.rb +2 -0
- data/lib/nanoc/core/processing_actions/layout.rb +2 -0
- data/lib/nanoc/core/processing_actions/snapshot.rb +12 -3
- data/lib/nanoc/core/pruner.rb +11 -3
- data/lib/nanoc/core/regexp_pattern.rb +1 -1
- data/lib/nanoc/core/site.rb +10 -4
- data/lib/nanoc/core/site_loader.rb +25 -17
- data/lib/nanoc/core/store.rb +33 -6
- data/lib/nanoc/core/string_pattern.rb +1 -1
- data/lib/nanoc/core/textual_compiled_content_cache.rb +60 -5
- data/lib/nanoc/core/textual_content.rb +4 -1
- data/lib/nanoc/core/version.rb +1 -1
- data/lib/nanoc/core/view_context_for_compilation.rb +6 -2
- data/lib/nanoc/core/views/basic_item_rep_collection_view.rb +11 -4
- data/lib/nanoc/core/views/basic_item_rep_view.rb +9 -2
- data/lib/nanoc/core/views/basic_item_view.rb +17 -9
- data/lib/nanoc/core/views/compilation_item_rep_view.rb +12 -4
- data/lib/nanoc/core/views/compilation_item_view.rb +3 -1
- data/lib/nanoc/core/views/identifiable_collection_view.rb +17 -5
- data/lib/nanoc/core/views/mutable_item_collection_view.rb +5 -2
- data/lib/nanoc/core/views/mutable_layout_collection_view.rb +5 -2
- data/lib/nanoc/core/views/post_compile_item_view.rb +3 -1
- data/lib/nanoc/core.rb +4 -4
- metadata +3 -9
- data/lib/nanoc/core/compilation_phases/abstract.rb +0 -48
- data/lib/nanoc/core/compilation_phases/cache.rb +0 -28
- data/lib/nanoc/core/compilation_phases/mark_done.rb +0 -23
- data/lib/nanoc/core/compilation_phases/notify.rb +0 -22
- data/lib/nanoc/core/compilation_phases/recalculate.rb +0 -59
- data/lib/nanoc/core/compilation_phases/write.rb +0 -31
|
@@ -12,11 +12,15 @@ module Nanoc
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def items
|
|
15
|
-
@data_source.items.map
|
|
15
|
+
@data_source.items.map do |d|
|
|
16
|
+
d.with_identifier_prefix(@items_prefix)
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def layouts
|
|
19
|
-
@data_source.layouts.map
|
|
21
|
+
@data_source.layouts.map do |d|
|
|
22
|
+
d.with_identifier_prefix(@layouts_prefix)
|
|
23
|
+
end
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
def item_changes
|
|
@@ -14,6 +14,8 @@ module Nanoc
|
|
|
14
14
|
|
|
15
15
|
contract C::IterOf[Symbol], C::IterOf[String] => C::Any
|
|
16
16
|
def initialize(snapshot_names, paths)
|
|
17
|
+
super()
|
|
18
|
+
|
|
17
19
|
@snapshot_names = snapshot_names
|
|
18
20
|
@paths = paths
|
|
19
21
|
end
|
|
@@ -23,9 +25,14 @@ module Nanoc
|
|
|
23
25
|
[:snapshot, @snapshot_names, true, @paths]
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
contract C::KeywordArgs[
|
|
28
|
+
contract C::KeywordArgs[
|
|
29
|
+
snapshot_names: C::Optional[C::IterOf[Symbol]],
|
|
30
|
+
paths: C::Optional[C::IterOf[String]]] => self
|
|
27
31
|
def update(snapshot_names: [], paths: [])
|
|
28
|
-
self.class.new(
|
|
32
|
+
self.class.new(
|
|
33
|
+
@snapshot_names + snapshot_names.to_a,
|
|
34
|
+
@paths + paths.to_a,
|
|
35
|
+
)
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
contract C::None => String
|
|
@@ -38,7 +45,9 @@ module Nanoc
|
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
def ==(other)
|
|
41
|
-
self.class == other.class &&
|
|
48
|
+
self.class == other.class &&
|
|
49
|
+
snapshot_names == other.snapshot_names &&
|
|
50
|
+
paths == other.paths
|
|
42
51
|
end
|
|
43
52
|
|
|
44
53
|
def eql?(other)
|
data/lib/nanoc/core/pruner.rb
CHANGED
|
@@ -7,7 +7,12 @@ module Nanoc
|
|
|
7
7
|
class Pruner
|
|
8
8
|
include Nanoc::Core::ContractsSupport
|
|
9
9
|
|
|
10
|
-
contract Nanoc::Core::Configuration,
|
|
10
|
+
contract Nanoc::Core::Configuration,
|
|
11
|
+
Nanoc::Core::ItemRepRepo,
|
|
12
|
+
C::KeywordArgs[
|
|
13
|
+
dry_run: C::Optional[C::Bool],
|
|
14
|
+
exclude: C::Optional[C::IterOf[String]],
|
|
15
|
+
] => C::Any
|
|
11
16
|
def initialize(config, reps, dry_run: false, exclude: [])
|
|
12
17
|
@config = config
|
|
13
18
|
@reps = reps
|
|
@@ -18,8 +23,11 @@ module Nanoc
|
|
|
18
23
|
def run
|
|
19
24
|
return unless File.directory?(@config.output_dir)
|
|
20
25
|
|
|
21
|
-
compiled_files = @reps.flat_map
|
|
22
|
-
|
|
26
|
+
compiled_files = @reps.flat_map do |r|
|
|
27
|
+
r.raw_paths.values.flatten
|
|
28
|
+
end.compact
|
|
29
|
+
present_files, present_dirs =
|
|
30
|
+
files_and_dirs_in("#{@config.output_dir}/")
|
|
23
31
|
|
|
24
32
|
remove_stray_files(present_files, compiled_files)
|
|
25
33
|
remove_empty_directories(present_dirs)
|
data/lib/nanoc/core/site.rb
CHANGED
|
@@ -4,10 +4,12 @@ module Nanoc
|
|
|
4
4
|
module Core
|
|
5
5
|
# @api private
|
|
6
6
|
class Site
|
|
7
|
-
# Error that is raised when multiple items or layouts with the same
|
|
7
|
+
# Error that is raised when multiple items or layouts with the same
|
|
8
|
+
# identifier exist.
|
|
8
9
|
class DuplicateIdentifierError < ::Nanoc::Core::Error
|
|
9
10
|
def initialize(identifier, type)
|
|
10
|
-
super(
|
|
11
|
+
super(
|
|
12
|
+
"There are multiple #{type}s with the #{identifier} identifier.")
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -17,7 +19,10 @@ module Nanoc
|
|
|
17
19
|
attr_reader :config
|
|
18
20
|
attr_accessor :data_source
|
|
19
21
|
|
|
20
|
-
contract C::KeywordArgs[
|
|
22
|
+
contract C::KeywordArgs[
|
|
23
|
+
config: Nanoc::Core::Configuration,
|
|
24
|
+
code_snippets: C::IterOf[Nanoc::Core::CodeSnippet],
|
|
25
|
+
data_source: C::Named['Nanoc::Core::DataSource']] => C::Any
|
|
21
26
|
def initialize(config:, code_snippets:, data_source:)
|
|
22
27
|
@config = config
|
|
23
28
|
@code_snippets = code_snippets
|
|
@@ -54,7 +59,8 @@ module Nanoc
|
|
|
54
59
|
self
|
|
55
60
|
end
|
|
56
61
|
|
|
57
|
-
contract C::IterOf[C::Or[Nanoc::Core::Item, Nanoc::Core::Layout]],
|
|
62
|
+
contract C::IterOf[C::Or[Nanoc::Core::Item, Nanoc::Core::Layout]],
|
|
63
|
+
String => self
|
|
58
64
|
def ensure_identifier_uniqueness(objects, type)
|
|
59
65
|
seen = Set.new
|
|
60
66
|
objects.each do |obj|
|
|
@@ -3,42 +3,48 @@
|
|
|
3
3
|
module Nanoc
|
|
4
4
|
module Core
|
|
5
5
|
class SiteLoader
|
|
6
|
-
ENCODING_REGEX =
|
|
6
|
+
ENCODING_REGEX =
|
|
7
|
+
/\A#\s+(-\*-\s+)?(en)?coding: (?<encoding>[^\s]+)(\s+-\*-\s*)?\n{0,2}/
|
|
8
|
+
|
|
7
9
|
# @return [Boolean]
|
|
8
10
|
def self.cwd_is_nanoc_site?
|
|
9
11
|
Nanoc::Core::ConfigLoader.cwd_is_nanoc_site?
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def new_from_cwd
|
|
13
|
-
|
|
15
|
+
new_from_config(Nanoc::Core::ConfigLoader.new.new_from_cwd)
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def gen_data_source_for_config(config)
|
|
17
19
|
data_sources_to_aggregate =
|
|
18
20
|
with_data_sources(config) do |data_sources|
|
|
19
21
|
data_sources.map do |ds|
|
|
20
|
-
Nanoc::Core::PrefixedDataSource.new(
|
|
22
|
+
Nanoc::Core::PrefixedDataSource.new(
|
|
23
|
+
ds, ds.items_root, ds.layouts_root
|
|
24
|
+
)
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
Nanoc::Core::AggregateDataSource.new(data_sources_to_aggregate, config)
|
|
25
29
|
end
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
code_snippets.each(&:load)
|
|
31
|
+
def new_from_config(config)
|
|
32
|
+
Nanoc::Core::Instrumentor.call(:stage_ran, 'LoadSite') do
|
|
33
|
+
code_snippets = code_snippets_from_config(config)
|
|
34
|
+
code_snippets.each(&:load)
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
data_source = gen_data_source_for_config(config)
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
Nanoc::Core::Site.new(
|
|
39
|
+
config:,
|
|
40
|
+
code_snippets:,
|
|
41
|
+
data_source:,
|
|
42
|
+
)
|
|
43
|
+
end
|
|
40
44
|
end
|
|
41
45
|
|
|
46
|
+
private
|
|
47
|
+
|
|
42
48
|
def with_data_sources(config, &)
|
|
43
49
|
data_sources = create_data_sources(config)
|
|
44
50
|
|
|
@@ -53,9 +59,11 @@ module Nanoc
|
|
|
53
59
|
def create_data_sources(config)
|
|
54
60
|
config[:data_sources].map do |data_source_hash|
|
|
55
61
|
# Get data source class
|
|
56
|
-
data_source_class =
|
|
62
|
+
data_source_class =
|
|
63
|
+
Nanoc::Core::DataSource.named(data_source_hash[:type].to_sym)
|
|
57
64
|
if data_source_class.nil?
|
|
58
|
-
raise Nanoc::Core::Errors::UnknownDataSource
|
|
65
|
+
raise Nanoc::Core::Errors::UnknownDataSource
|
|
66
|
+
.new(data_source_hash[:type])
|
|
59
67
|
end
|
|
60
68
|
|
|
61
69
|
# Create data source
|
|
@@ -70,7 +78,7 @@ module Nanoc
|
|
|
70
78
|
|
|
71
79
|
def code_snippets_from_config(config)
|
|
72
80
|
config[:lib_dirs].flat_map do |lib|
|
|
73
|
-
Dir["#{File.expand_path(lib)}/**/*.rb"].
|
|
81
|
+
Dir["#{File.expand_path(lib)}/**/*.rb"].map do |filename|
|
|
74
82
|
Nanoc::Core::CodeSnippet.new(
|
|
75
83
|
read_code_snippet_contents(filename),
|
|
76
84
|
filename,
|
data/lib/nanoc/core/store.rb
CHANGED
|
@@ -15,7 +15,10 @@ module Nanoc
|
|
|
15
15
|
|
|
16
16
|
# Logic for building tmp path from active environment and store name
|
|
17
17
|
# @api private
|
|
18
|
-
contract C::KeywordArgs[
|
|
18
|
+
contract C::KeywordArgs[
|
|
19
|
+
config: Nanoc::Core::Configuration,
|
|
20
|
+
store_name: String,
|
|
21
|
+
] => C::AbsolutePathString
|
|
19
22
|
def self.tmp_path_for(store_name:, config:)
|
|
20
23
|
File.absolute_path(
|
|
21
24
|
File.join(tmp_path_prefix(config.output_dir), store_name),
|
|
@@ -57,7 +60,9 @@ module Nanoc
|
|
|
57
60
|
#
|
|
58
61
|
# @abstract This method must be implemented by the subclass.
|
|
59
62
|
def data
|
|
60
|
-
raise NotImplementedError.new(
|
|
63
|
+
raise NotImplementedError.new(
|
|
64
|
+
'Nanoc::Core::Store subclasses must implement #data and #data=',
|
|
65
|
+
)
|
|
61
66
|
end
|
|
62
67
|
|
|
63
68
|
# @param new_data The data that has been loaded from the disk
|
|
@@ -66,7 +71,9 @@ module Nanoc
|
|
|
66
71
|
#
|
|
67
72
|
# @return [void]
|
|
68
73
|
def data=(new_data) # rubocop:disable Lint/UnusedMethodArgument
|
|
69
|
-
raise NotImplementedError.new(
|
|
74
|
+
raise NotImplementedError.new(
|
|
75
|
+
'Nanoc::Core::Store subclasses must implement #data and #data=',
|
|
76
|
+
)
|
|
70
77
|
end
|
|
71
78
|
|
|
72
79
|
# Loads the data from the filesystem into memory. This method will set the
|
|
@@ -98,7 +105,7 @@ module Nanoc
|
|
|
98
105
|
rescue
|
|
99
106
|
# An error occurred! Remove the database and try again
|
|
100
107
|
FileUtils.rm_f(version_filename)
|
|
101
|
-
|
|
108
|
+
reset_data
|
|
102
109
|
|
|
103
110
|
# Try again
|
|
104
111
|
unsafe_load_uninstrumented
|
|
@@ -108,7 +115,7 @@ module Nanoc
|
|
|
108
115
|
FileUtils.mkdir_p(File.dirname(filename))
|
|
109
116
|
|
|
110
117
|
write_obj_to_file(version_filename, version)
|
|
111
|
-
|
|
118
|
+
store_data
|
|
112
119
|
|
|
113
120
|
# Remove old file (back from the PStore days), if there are any.
|
|
114
121
|
FileUtils.rm_f(filename)
|
|
@@ -124,10 +131,30 @@ module Nanoc
|
|
|
124
131
|
read_version = read_obj_from_file(version_filename)
|
|
125
132
|
return if read_version != version
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
load_data
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Can be overridden by subclasses for finer-grained control over how data
|
|
138
|
+
# get (de)serialized. #load_data, #store_data and #reset_data must be
|
|
139
|
+
# implemented all together.
|
|
140
|
+
def load_data
|
|
128
141
|
self.data = read_obj_from_file(data_filename)
|
|
129
142
|
end
|
|
130
143
|
|
|
144
|
+
# Can be overridden by subclasses for finer-grained control over how data
|
|
145
|
+
# get (de)serialized. #load_data, #store_data and #reset_data must be
|
|
146
|
+
# implemented all together.
|
|
147
|
+
def store_data
|
|
148
|
+
write_obj_to_file(data_filename, data)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Can be overridden by subclasses for finer-grained control over how data
|
|
152
|
+
# get (de)serialized. #load_data, #store_data and #reset_data must be
|
|
153
|
+
# implemented all together.
|
|
154
|
+
def reset_data
|
|
155
|
+
FileUtils.rm_f(data_filename)
|
|
156
|
+
end
|
|
157
|
+
|
|
131
158
|
def write_obj_to_file(filename, obj)
|
|
132
159
|
data = Marshal.dump(obj)
|
|
133
160
|
compressed_data = Zlib::Deflate.deflate(data, Zlib::BEST_SPEED)
|
|
@@ -9,21 +9,56 @@ module Nanoc
|
|
|
9
9
|
class TextualCompiledContentCache < ::Nanoc::Core::Store
|
|
10
10
|
include Nanoc::Core::ContractsSupport
|
|
11
11
|
|
|
12
|
+
class LazyCompressedValue
|
|
13
|
+
def initialize(uncompressed: nil, compressed: nil)
|
|
14
|
+
if uncompressed.nil? && compressed.nil?
|
|
15
|
+
raise ArgumentError, 'must specify at least uncompressed or compressed'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
@_uncompressed = uncompressed
|
|
19
|
+
@_compressed = compressed
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def compressed
|
|
23
|
+
@_compressed ||= Zlib::Deflate.deflate(Marshal.dump(@_uncompressed), Zlib::BEST_SPEED)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def uncompressed
|
|
27
|
+
@_uncompressed ||= Marshal.load(Zlib::Inflate.inflate(@_compressed))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def marshal_dump
|
|
31
|
+
[compressed]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def marshal_load(array)
|
|
35
|
+
@_compressed = array[0]
|
|
36
|
+
@_uncompressed = nil
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
12
40
|
contract C::KeywordArgs[config: Nanoc::Core::Configuration] => C::Any
|
|
13
41
|
def initialize(config:)
|
|
14
|
-
super(
|
|
42
|
+
super(
|
|
43
|
+
self.class.tmp_path_for(
|
|
44
|
+
config:,
|
|
45
|
+
store_name: 'compiled_content',
|
|
46
|
+
),
|
|
47
|
+
5,
|
|
48
|
+
)
|
|
15
49
|
|
|
16
50
|
@cache = {}
|
|
17
51
|
end
|
|
18
52
|
|
|
19
|
-
contract Nanoc::Core::ItemRep =>
|
|
53
|
+
contract Nanoc::Core::ItemRep =>
|
|
54
|
+
C::Maybe[C::HashOf[Symbol => Nanoc::Core::Content]]
|
|
20
55
|
# Returns the cached compiled content for the given item representation.
|
|
21
56
|
#
|
|
22
57
|
# This cached compiled content is a hash where the keys are the snapshot
|
|
23
58
|
# names, and the values the compiled content at the given snapshot.
|
|
24
59
|
def [](rep)
|
|
25
60
|
item_cache = @cache[rep.item.identifier] || {}
|
|
26
|
-
item_cache[rep.name]
|
|
61
|
+
item_cache[rep.name]&.uncompressed
|
|
27
62
|
end
|
|
28
63
|
|
|
29
64
|
contract Nanoc::Core::ItemRep => C::Bool
|
|
@@ -32,14 +67,15 @@ module Nanoc
|
|
|
32
67
|
item_cache.key?(rep.name)
|
|
33
68
|
end
|
|
34
69
|
|
|
35
|
-
contract Nanoc::Core::ItemRep,
|
|
70
|
+
contract Nanoc::Core::ItemRep,
|
|
71
|
+
C::HashOf[Symbol => Nanoc::Core::TextualContent] => C::Any
|
|
36
72
|
# Sets the compiled content for the given representation.
|
|
37
73
|
#
|
|
38
74
|
# This cached compiled content is a hash where the keys are the snapshot
|
|
39
75
|
# names, and the values the compiled content at the given snapshot.
|
|
40
76
|
def []=(rep, content)
|
|
41
77
|
@cache[rep.item.identifier] ||= {}
|
|
42
|
-
@cache[rep.item.identifier][rep.name] = content
|
|
78
|
+
@cache[rep.item.identifier][rep.name] = LazyCompressedValue.new(uncompressed: content)
|
|
43
79
|
end
|
|
44
80
|
|
|
45
81
|
def prune(items:)
|
|
@@ -53,6 +89,25 @@ module Nanoc
|
|
|
53
89
|
end
|
|
54
90
|
end
|
|
55
91
|
|
|
92
|
+
# Similar to Store#load_data, but does not use zlib compression on the
|
|
93
|
+
# data itself (instead, values are compressed individually).
|
|
94
|
+
def load_data
|
|
95
|
+
raw_data = File.binread(data_filename)
|
|
96
|
+
self.data = Marshal.load(raw_data)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Similar to Store#store_data, but does not use zlib compression on the
|
|
100
|
+
# data itself (instead, values are compressed individually).
|
|
101
|
+
def store_data
|
|
102
|
+
raw_data = Marshal.dump(data)
|
|
103
|
+
write_data_to_file(data_filename, raw_data)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Identical to Store#store_data; replicated for clarity.
|
|
107
|
+
def reset_data
|
|
108
|
+
FileUtils.rm_f(data_filename)
|
|
109
|
+
end
|
|
110
|
+
|
|
56
111
|
protected
|
|
57
112
|
|
|
58
113
|
def data
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
module Nanoc
|
|
4
4
|
module Core
|
|
5
5
|
class TextualContent < Content
|
|
6
|
-
contract C::Or[String, Proc],
|
|
6
|
+
contract C::Or[String, Proc],
|
|
7
|
+
C::KeywordArgs[
|
|
8
|
+
filename: C::Optional[C::Maybe[String]],
|
|
9
|
+
] => C::Any
|
|
7
10
|
def initialize(string, filename: nil)
|
|
8
11
|
super(filename)
|
|
9
12
|
@string = Nanoc::Core::LazyValue.new(string)
|
data/lib/nanoc/core/version.rb
CHANGED
|
@@ -18,7 +18,10 @@ module Nanoc
|
|
|
18
18
|
compilation_context: Nanoc::Core::CompilationContext,
|
|
19
19
|
compiled_content_repo: Nanoc::Core::CompiledContentRepo,
|
|
20
20
|
] => C::Any
|
|
21
|
-
def initialize(
|
|
21
|
+
def initialize(
|
|
22
|
+
reps:, items:, dependency_tracker:, compilation_context:,
|
|
23
|
+
compiled_content_repo:
|
|
24
|
+
)
|
|
22
25
|
@reps = reps
|
|
23
26
|
@items = items
|
|
24
27
|
@dependency_tracker = dependency_tracker
|
|
@@ -26,7 +29,8 @@ module Nanoc
|
|
|
26
29
|
@compiled_content_repo = compiled_content_repo
|
|
27
30
|
end
|
|
28
31
|
|
|
29
|
-
contract Nanoc::Core::ItemRep,
|
|
32
|
+
contract Nanoc::Core::ItemRep,
|
|
33
|
+
C::KeywordArgs[site: Nanoc::Core::Site] => Hash
|
|
30
34
|
def assigns_for(rep, site:)
|
|
31
35
|
last_content = @compiled_content_repo.get_current(rep)
|
|
32
36
|
content_or_filename_assigns =
|
|
@@ -31,7 +31,8 @@ module Nanoc
|
|
|
31
31
|
@item_reps.map { |ir| view_class.new(ir, @context) }
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
# Calls the given block once for each item rep, passing that item rep as a
|
|
34
|
+
# Calls the given block once for each item rep, passing that item rep as a
|
|
35
|
+
# parameter.
|
|
35
36
|
#
|
|
36
37
|
# @yieldparam [Object] item rep view
|
|
37
38
|
#
|
|
@@ -54,16 +55,22 @@ module Nanoc
|
|
|
54
55
|
#
|
|
55
56
|
# @return [nil] if no item rep with the given name was found
|
|
56
57
|
#
|
|
57
|
-
# @return [Nanoc::Core::BasicItemRepView] if an item rep with the given
|
|
58
|
+
# @return [Nanoc::Core::BasicItemRepView] if an item rep with the given
|
|
59
|
+
# name was found
|
|
58
60
|
def [](rep_name)
|
|
59
61
|
case rep_name
|
|
60
62
|
when Symbol
|
|
61
63
|
res = @item_reps.find { |ir| ir.name == rep_name }
|
|
62
64
|
res && view_class.new(res, @context)
|
|
63
65
|
when Integer
|
|
64
|
-
raise ArgumentError,
|
|
66
|
+
raise ArgumentError,
|
|
67
|
+
'expected BasicItemRepCollectionView#[] to be called with a ' \
|
|
68
|
+
'symbol (you likely want `.reps[:default]` rather than ' \
|
|
69
|
+
"`.reps[#{rep_name}]`)"
|
|
65
70
|
else
|
|
66
|
-
raise ArgumentError,
|
|
71
|
+
raise ArgumentError,
|
|
72
|
+
'expected BasicItemRepCollectionView#[] to be called with a ' \
|
|
73
|
+
'symbol'
|
|
67
74
|
end
|
|
68
75
|
end
|
|
69
76
|
|
|
@@ -21,7 +21,10 @@ module Nanoc
|
|
|
21
21
|
|
|
22
22
|
# @see Object#==
|
|
23
23
|
def ==(other)
|
|
24
|
-
other.respond_to?(:item) &&
|
|
24
|
+
other.respond_to?(:item) &&
|
|
25
|
+
other.respond_to?(:name) &&
|
|
26
|
+
item == other.item &&
|
|
27
|
+
name == other.name
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
# @see Object#eql?
|
|
@@ -70,7 +73,11 @@ module Nanoc
|
|
|
70
73
|
# @api private
|
|
71
74
|
def binary?
|
|
72
75
|
snapshot_def = _unwrap.snapshot_defs.find { |sd| sd.name == :last }
|
|
73
|
-
|
|
76
|
+
if snapshot_def.nil?
|
|
77
|
+
raise Nanoc::Core::Errors::NoSuchSnapshot.new(
|
|
78
|
+
_unwrap, :last
|
|
79
|
+
)
|
|
80
|
+
end
|
|
74
81
|
|
|
75
82
|
snapshot_def.binary?
|
|
76
83
|
end
|
|
@@ -11,28 +11,35 @@ module Nanoc
|
|
|
11
11
|
# @return [Enumerable<Nanoc::Core::CompilationItemView>]
|
|
12
12
|
def children
|
|
13
13
|
unless _unwrap.identifier.legacy?
|
|
14
|
-
raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem
|
|
14
|
+
raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem
|
|
15
|
+
.new(_unwrap.identifier)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
children_pattern = Nanoc::Core::Pattern.from(_unwrap.identifier
|
|
18
|
-
children = @context.items.select
|
|
18
|
+
children_pattern = Nanoc::Core::Pattern.from("#{_unwrap.identifier}*/")
|
|
19
|
+
children = @context.items.select do |i|
|
|
20
|
+
children_pattern.match?(i.identifier)
|
|
21
|
+
end
|
|
19
22
|
|
|
20
23
|
children.map { |i| self.class.new(i, @context) }.freeze
|
|
21
24
|
end
|
|
22
25
|
|
|
23
|
-
# Returns the parent of this item, if one exists. For items with
|
|
24
|
-
# that have extensions, returns nil.
|
|
26
|
+
# Returns the parent of this item, if one exists. For items with
|
|
27
|
+
# identifiers that have extensions, returns nil.
|
|
25
28
|
#
|
|
26
29
|
# @return [Nanoc::Core::CompilationItemView] if the item has a parent
|
|
27
30
|
#
|
|
28
31
|
# @return [nil] if the item has no parent
|
|
29
32
|
def parent
|
|
30
33
|
unless _unwrap.identifier.legacy?
|
|
31
|
-
raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem
|
|
34
|
+
raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem
|
|
35
|
+
.new(_unwrap.identifier)
|
|
32
36
|
end
|
|
33
37
|
|
|
34
|
-
parent_identifier =
|
|
35
|
-
|
|
38
|
+
parent_identifier =
|
|
39
|
+
"/#{_unwrap.identifier.components[0..-2].join('/')}/"
|
|
40
|
+
if parent_identifier == '//'
|
|
41
|
+
parent_identifier = '/'
|
|
42
|
+
end
|
|
36
43
|
|
|
37
44
|
parent = @context.items.object_with_identifier(parent_identifier)
|
|
38
45
|
|
|
@@ -44,7 +51,8 @@ module Nanoc
|
|
|
44
51
|
_unwrap.content.binary?
|
|
45
52
|
end
|
|
46
53
|
|
|
47
|
-
# @return [String, nil] The path to the file containing the uncompiled
|
|
54
|
+
# @return [String, nil] The path to the file containing the uncompiled
|
|
55
|
+
# content of this item.
|
|
48
56
|
def raw_filename
|
|
49
57
|
@context.dependency_tracker.bounce(_unwrap, raw_content: true)
|
|
50
58
|
_unwrap.content.filename
|
|
@@ -48,7 +48,10 @@ module Nanoc
|
|
|
48
48
|
def compiled_content(snapshot: nil)
|
|
49
49
|
compiled_content_repo = @context.compiled_content_repo
|
|
50
50
|
|
|
51
|
-
@context.dependency_tracker.bounce(
|
|
51
|
+
@context.dependency_tracker.bounce(
|
|
52
|
+
@item_rep.item,
|
|
53
|
+
compiled_content: true,
|
|
54
|
+
)
|
|
52
55
|
|
|
53
56
|
begin
|
|
54
57
|
compiled_content_repo.compiled_content(rep: @item_rep, snapshot:)
|
|
@@ -77,13 +80,18 @@ module Nanoc
|
|
|
77
80
|
outdated = compilation_context.outdatedness_store.include?(@item_rep)
|
|
78
81
|
return false if outdated
|
|
79
82
|
|
|
80
|
-
# Requirement: The compiled content cache must have a cache entry for
|
|
81
|
-
|
|
83
|
+
# Requirement: The compiled content cache must have a cache entry for
|
|
84
|
+
# this item rep.
|
|
85
|
+
cache_available =
|
|
86
|
+
compiled_content_cache.full_cache_available?(@item_rep)
|
|
82
87
|
return false unless cache_available
|
|
83
88
|
|
|
84
89
|
# Load the compiled content from the cache
|
|
85
90
|
Nanoc::Core::NotificationCenter.post(:cached_content_used, @item_rep)
|
|
86
|
-
compiled_content_repo.set_all(
|
|
91
|
+
compiled_content_repo.set_all(
|
|
92
|
+
@item_rep,
|
|
93
|
+
compiled_content_cache[@item_rep],
|
|
94
|
+
)
|
|
87
95
|
|
|
88
96
|
# Mark as compiled
|
|
89
97
|
@item_rep.compiled = true
|
|
@@ -40,7 +40,9 @@ module Nanoc
|
|
|
40
40
|
#
|
|
41
41
|
# @return [Nanoc::Core::BasicItemRepCollectionView]
|
|
42
42
|
def reps
|
|
43
|
-
Nanoc::Core::CompilationItemRepCollectionView.new(
|
|
43
|
+
Nanoc::Core::CompilationItemRepCollectionView.new(
|
|
44
|
+
@context.reps[_unwrap], @context
|
|
45
|
+
)
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
end
|