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,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc::Int
|
4
|
-
# @api private
|
5
|
-
class SnapshotRepo
|
6
|
-
include Nanoc::Int::ContractsSupport
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@contents = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
contract Nanoc::Int::ItemRep, Symbol => C::Maybe[Nanoc::Int::Content]
|
13
|
-
def get(rep, snapshot_name)
|
14
|
-
@contents[rep] ||= {}
|
15
|
-
@contents[rep][snapshot_name]
|
16
|
-
end
|
17
|
-
|
18
|
-
contract Nanoc::Int::ItemRep, Symbol, Nanoc::Int::Content => C::Any
|
19
|
-
def set(rep, snapshot_name, contents)
|
20
|
-
@contents[rep] ||= {}
|
21
|
-
@contents[rep][snapshot_name] = contents
|
22
|
-
end
|
23
|
-
|
24
|
-
contract Nanoc::Int::ItemRep => C::HashOf[Symbol => Nanoc::Int::Content]
|
25
|
-
def get_all(rep)
|
26
|
-
@contents[rep] || {}
|
27
|
-
end
|
28
|
-
|
29
|
-
contract Nanoc::Int::ItemRep, C::HashOf[Symbol => Nanoc::Int::Content] => C::Any
|
30
|
-
def set_all(rep, contents_per_snapshot)
|
31
|
-
@contents[rep] = contents_per_snapshot
|
32
|
-
end
|
33
|
-
|
34
|
-
contract C::KeywordArgs[rep: Nanoc::Int::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => Nanoc::Int::Content
|
35
|
-
def raw_compiled_content(rep:, snapshot: nil)
|
36
|
-
# Get name of last pre-layout snapshot
|
37
|
-
snapshot_name = snapshot || (get(rep, :pre) ? :pre : :last)
|
38
|
-
|
39
|
-
# Check existance of snapshot
|
40
|
-
snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
|
41
|
-
unless snapshot_def
|
42
|
-
raise Nanoc::Int::Errors::NoSuchSnapshot.new(rep, snapshot_name)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Verify snapshot is usable
|
46
|
-
stopped_moving = snapshot_name != :last || rep.compiled?
|
47
|
-
is_usable_snapshot = get(rep, snapshot_name) && stopped_moving
|
48
|
-
unless is_usable_snapshot
|
49
|
-
Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(rep))
|
50
|
-
return raw_compiled_content(rep: rep, snapshot: snapshot)
|
51
|
-
end
|
52
|
-
|
53
|
-
get(rep, snapshot_name)
|
54
|
-
end
|
55
|
-
|
56
|
-
contract C::KeywordArgs[rep: Nanoc::Int::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => String
|
57
|
-
def compiled_content(rep:, snapshot: nil)
|
58
|
-
snapshot_content = raw_compiled_content(rep: rep, snapshot: snapshot)
|
59
|
-
|
60
|
-
if snapshot_content.binary?
|
61
|
-
raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
|
62
|
-
end
|
63
|
-
|
64
|
-
snapshot_content.string
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,274 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc::Int
|
4
|
-
# Creates checksums for given objects.
|
5
|
-
#
|
6
|
-
# A checksum is a string, such as “mL+TaqNsEeiPkWloPgCtAofT1yg=”, that is used
|
7
|
-
# to determine whether a piece of data has changed.
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
class Checksummer
|
11
|
-
class VerboseDigest
|
12
|
-
def initialize
|
13
|
-
@str = +''
|
14
|
-
end
|
15
|
-
|
16
|
-
def update(str)
|
17
|
-
@str << str
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
@str
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class CompactDigest
|
26
|
-
def initialize
|
27
|
-
@digest = Digest::SHA1.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def update(str)
|
31
|
-
@digest.update(str)
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
@digest.base64digest
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class << self
|
40
|
-
# @param obj The object to create a checksum for
|
41
|
-
#
|
42
|
-
# @return [String] The digest
|
43
|
-
def calc(obj, digest_class = CompactDigest)
|
44
|
-
digest = digest_class.new
|
45
|
-
update(obj, digest)
|
46
|
-
digest.to_s
|
47
|
-
end
|
48
|
-
|
49
|
-
def calc_for_content_of(obj)
|
50
|
-
obj.content_checksum_data || obj.checksum_data || Nanoc::Int::Checksummer.calc(obj.content)
|
51
|
-
end
|
52
|
-
|
53
|
-
def calc_for_each_attribute_of(obj, digest_class = CompactDigest)
|
54
|
-
obj.attributes.each_with_object({}) do |(key, value), memo|
|
55
|
-
memo[key] = Nanoc::Int::Checksummer.calc(value, digest_class)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def update(obj, digest, visited = Hamster::Set.new)
|
62
|
-
digest.update(obj.class.to_s)
|
63
|
-
|
64
|
-
if visited.include?(obj)
|
65
|
-
digest.update('<recur>')
|
66
|
-
else
|
67
|
-
digest.update('<')
|
68
|
-
behavior_for(obj).update(obj, digest) { |o| update(o, digest, visited.add(obj)) }
|
69
|
-
digest.update('>')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def behavior_for(obj)
|
74
|
-
case obj
|
75
|
-
when String, Symbol, Numeric
|
76
|
-
RawUpdateBehavior
|
77
|
-
when Pathname
|
78
|
-
PathnameUpdateBehavior
|
79
|
-
when Nanoc::Int::BinaryContent
|
80
|
-
BinaryContentUpdateBehavior
|
81
|
-
when Array, Nanoc::Int::IdentifiableCollection
|
82
|
-
ArrayUpdateBehavior
|
83
|
-
when Hash, Nanoc::Int::Configuration
|
84
|
-
HashUpdateBehavior
|
85
|
-
when Nanoc::Int::Item, Nanoc::Int::Layout
|
86
|
-
DocumentUpdateBehavior
|
87
|
-
when Nanoc::Int::ItemRep
|
88
|
-
ItemRepUpdateBehavior
|
89
|
-
when NilClass, TrueClass, FalseClass
|
90
|
-
NoUpdateBehavior
|
91
|
-
when Time
|
92
|
-
ToIToSUpdateBehavior
|
93
|
-
when Nanoc::Identifier
|
94
|
-
ToSUpdateBehavior
|
95
|
-
when Nanoc::RuleDSL::RulesCollection, Nanoc::Int::CodeSnippet
|
96
|
-
DataUpdateBehavior
|
97
|
-
when Nanoc::Int::TextualContent
|
98
|
-
StringUpdateBehavior
|
99
|
-
when Nanoc::View
|
100
|
-
UnwrapUpdateBehavior
|
101
|
-
when Nanoc::RuleDSL::CompilationRuleContext
|
102
|
-
RuleContextUpdateBehavior
|
103
|
-
when Nanoc::Int::Context
|
104
|
-
ContextUpdateBehavior
|
105
|
-
else
|
106
|
-
RescueUpdateBehavior
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class UpdateBehavior
|
112
|
-
def self.update(_obj, _digest)
|
113
|
-
raise NotImpementedError
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class RuleContextUpdateBehavior < UpdateBehavior
|
118
|
-
def self.update(obj, digest)
|
119
|
-
digest.update('item=')
|
120
|
-
yield(obj.item)
|
121
|
-
digest.update(',rep=')
|
122
|
-
yield(obj.rep)
|
123
|
-
digest.update(',items=')
|
124
|
-
yield(obj.items)
|
125
|
-
digest.update(',layouts=')
|
126
|
-
yield(obj.layouts)
|
127
|
-
digest.update(',config=')
|
128
|
-
yield(obj.config)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class ContextUpdateBehavior < UpdateBehavior
|
133
|
-
def self.update(obj, digest)
|
134
|
-
obj.instance_variables.each do |var|
|
135
|
-
digest.update(var.to_s)
|
136
|
-
digest.update('=')
|
137
|
-
yield(obj.instance_variable_get(var))
|
138
|
-
digest.update(',')
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
class RawUpdateBehavior < UpdateBehavior
|
144
|
-
def self.update(obj, digest)
|
145
|
-
digest.update(obj.to_s)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
class ToSUpdateBehavior < UpdateBehavior
|
150
|
-
def self.update(obj, _digest)
|
151
|
-
yield(obj.to_s)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
class ToIToSUpdateBehavior < UpdateBehavior
|
156
|
-
def self.update(obj, digest)
|
157
|
-
digest.update(obj.to_i.to_s)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
class StringUpdateBehavior < UpdateBehavior
|
162
|
-
def self.update(obj, _digest)
|
163
|
-
yield(obj.string)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
class DataUpdateBehavior < UpdateBehavior
|
168
|
-
def self.update(obj, _digest)
|
169
|
-
yield(obj.data)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
class NoUpdateBehavior < UpdateBehavior
|
174
|
-
def self.update(_obj, _digest); end
|
175
|
-
end
|
176
|
-
|
177
|
-
class UnwrapUpdateBehavior < UpdateBehavior
|
178
|
-
def self.update(obj, _digest)
|
179
|
-
yield(obj._unwrap)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
class ArrayUpdateBehavior < UpdateBehavior
|
184
|
-
def self.update(obj, digest)
|
185
|
-
obj.each do |el|
|
186
|
-
yield(el)
|
187
|
-
digest.update(',')
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
class HashUpdateBehavior < UpdateBehavior
|
193
|
-
def self.update(obj, digest)
|
194
|
-
obj.each do |key, value|
|
195
|
-
yield(key)
|
196
|
-
digest.update('=')
|
197
|
-
yield(value)
|
198
|
-
digest.update(',')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
class DocumentUpdateBehavior < UpdateBehavior
|
204
|
-
def self.update(obj, digest)
|
205
|
-
if obj.checksum_data
|
206
|
-
digest.update('checksum_data=' + obj.checksum_data)
|
207
|
-
else
|
208
|
-
if obj.content_checksum_data
|
209
|
-
digest.update('content_checksum_data=' + obj.content_checksum_data)
|
210
|
-
else
|
211
|
-
digest.update('content=')
|
212
|
-
yield(obj.content)
|
213
|
-
end
|
214
|
-
|
215
|
-
if obj.attributes_checksum_data
|
216
|
-
digest.update(',attributes_checksum_data=' + obj.attributes_checksum_data)
|
217
|
-
else
|
218
|
-
digest.update(',attributes=')
|
219
|
-
yield(obj.attributes)
|
220
|
-
end
|
221
|
-
|
222
|
-
digest.update(',identifier=')
|
223
|
-
yield(obj.identifier)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
class ItemRepUpdateBehavior < UpdateBehavior
|
229
|
-
def self.update(obj, digest)
|
230
|
-
digest.update('item=')
|
231
|
-
yield(obj.item)
|
232
|
-
digest.update(',name=')
|
233
|
-
yield(obj.name)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
class PathnameUpdateBehavior < UpdateBehavior
|
238
|
-
def self.update(obj, digest)
|
239
|
-
filename = obj.to_s
|
240
|
-
if File.exist?(filename)
|
241
|
-
stat = File.stat(filename)
|
242
|
-
digest.update(stat.size.to_s + '-' + stat.mtime.to_i.to_s)
|
243
|
-
else
|
244
|
-
digest.update('???')
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
class BinaryContentUpdateBehavior < UpdateBehavior
|
250
|
-
def self.update(obj, _digest)
|
251
|
-
yield(Pathname.new(obj.filename))
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
class RescueUpdateBehavior < UpdateBehavior
|
256
|
-
def self.update(obj, digest)
|
257
|
-
if obj.class.to_s == 'Sass::Importers::Filesystem'
|
258
|
-
digest.update('root=')
|
259
|
-
digest.update(obj.root)
|
260
|
-
return
|
261
|
-
end
|
262
|
-
|
263
|
-
data =
|
264
|
-
begin
|
265
|
-
Marshal.dump(obj)
|
266
|
-
rescue
|
267
|
-
obj.inspect
|
268
|
-
end
|
269
|
-
|
270
|
-
digest.update(data)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc::Int
|
4
|
-
# Provides a way to send notifications between objects. It allows blocks
|
5
|
-
# associated with a certain notification name to be registered; these blocks
|
6
|
-
# will be called when the notification with the given name is posted.
|
7
|
-
#
|
8
|
-
# It is a slightly different implementation of the Observer pattern; the
|
9
|
-
# table of subscribers is not stored in the observable object itself, but in
|
10
|
-
# the notification center.
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
class NotificationCenter
|
14
|
-
class << self
|
15
|
-
# Adds the given block to the list of blocks that should be called when
|
16
|
-
# the notification with the given name is received.
|
17
|
-
#
|
18
|
-
# @param [String, Symbol] name The name of the notification that will
|
19
|
-
# cause the given block to be called.
|
20
|
-
#
|
21
|
-
# @param [String, Symbol, nil] id An identifier for the block. This is
|
22
|
-
# only used to be able to remove the block (using the remove method)
|
23
|
-
# later. Can be nil, but this is not recommended because it prevents
|
24
|
-
# the given notification block from being unregistered.
|
25
|
-
#
|
26
|
-
# @yield [*args] Will be executed with the arguments passed to {.post}
|
27
|
-
#
|
28
|
-
# @return [void]
|
29
|
-
def on(name, id = nil, &block)
|
30
|
-
initialize_if_necessary(name)
|
31
|
-
|
32
|
-
# Add observer
|
33
|
-
@notifications[name] << { id: id, block: block }
|
34
|
-
end
|
35
|
-
|
36
|
-
# Posts a notification with the given name and the given arguments.
|
37
|
-
#
|
38
|
-
# @param [String, Symbol] name The name of the notification that should
|
39
|
-
# be posted.
|
40
|
-
#
|
41
|
-
# @param args Arguments that wil be passed to the blocks handling the
|
42
|
-
# notification.
|
43
|
-
#
|
44
|
-
# @return [void]
|
45
|
-
def post(name, *args)
|
46
|
-
initialize_if_necessary(name)
|
47
|
-
|
48
|
-
# Notify all observers
|
49
|
-
@notifications[name].each do |observer|
|
50
|
-
observer[:block].call(*args)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Removes the block with the given identifier from the list of blocks
|
55
|
-
# that should be called when the notification with the given name is
|
56
|
-
# posted.
|
57
|
-
#
|
58
|
-
# @param [String, Symbol] name The name of the notification that should
|
59
|
-
# no longer be registered.
|
60
|
-
#
|
61
|
-
# @param [String, Symbol] id The identifier of the block that should be
|
62
|
-
# removed.
|
63
|
-
#
|
64
|
-
# @return [void]
|
65
|
-
def remove(name, id)
|
66
|
-
initialize_if_necessary(name)
|
67
|
-
|
68
|
-
# Remove relevant observers
|
69
|
-
@notifications[name].reject! { |i| i[:id] == id }
|
70
|
-
end
|
71
|
-
|
72
|
-
# @api private
|
73
|
-
#
|
74
|
-
# @return [void]
|
75
|
-
def reset
|
76
|
-
@notifications = nil
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def initialize_if_necessary(name)
|
82
|
-
@notifications ||= {} # name => observers dictionary
|
83
|
-
@notifications[name] ||= [] # list of observers
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc::Int
|
4
|
-
# @api private
|
5
|
-
class TempFilenameFactory
|
6
|
-
# @return [String] The root directory for all temporary filenames
|
7
|
-
attr_reader :root_dir
|
8
|
-
|
9
|
-
# @return [Nanoc::Int::TempFilenameFactory] A common instance
|
10
|
-
def self.instance
|
11
|
-
@instance ||= new
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@counts = {}
|
16
|
-
@root_dir = Dir.mktmpdir('nanoc')
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param [String] prefix A string prefix to include in the temporary
|
20
|
-
# filename, often the type of filename being provided.
|
21
|
-
#
|
22
|
-
# @return [String] A new unused filename
|
23
|
-
def create(prefix)
|
24
|
-
count = @counts.fetch(prefix, 0)
|
25
|
-
@counts[prefix] = count + 1
|
26
|
-
|
27
|
-
dirname = File.join(@root_dir, prefix)
|
28
|
-
filename = File.join(@root_dir, prefix, count.to_s)
|
29
|
-
|
30
|
-
FileUtils.mkdir_p(dirname)
|
31
|
-
|
32
|
-
filename
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param [String] prefix A string prefix that indicates which temporary
|
36
|
-
# filenames should be deleted.
|
37
|
-
#
|
38
|
-
# @return [void]
|
39
|
-
def cleanup(prefix)
|
40
|
-
path = File.join(@root_dir, prefix)
|
41
|
-
if File.exist?(path)
|
42
|
-
FileUtils.rm_rf(path)
|
43
|
-
end
|
44
|
-
|
45
|
-
@counts.delete(prefix)
|
46
|
-
|
47
|
-
if @counts.empty? && File.directory?(@root_dir)
|
48
|
-
FileUtils.rm_rf(@root_dir)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|