nanoc 4.11.12 → 4.11.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +788 -743
  3. data/bin/nanoc +1 -1
  4. data/lib/nanoc.rb +6 -29
  5. data/lib/nanoc/data_sources/filesystem.rb +9 -3
  6. data/lib/nanoc/data_sources/filesystem/tools.rb +4 -4
  7. data/lib/nanoc/extra.rb +2 -1
  8. data/lib/nanoc/extra/core_ext.rb +0 -1
  9. data/lib/nanoc/extra/srcset_parser.rb +79 -0
  10. data/lib/nanoc/filters/colorize_syntax/colorizers.rb +1 -1
  11. data/lib/nanoc/filters/erb.rb +1 -5
  12. data/lib/nanoc/filters/relativize_paths.rb +62 -10
  13. data/lib/nanoc/filters/sass/functions.rb +1 -1
  14. data/lib/nanoc/helpers/blogging.rb +8 -8
  15. data/lib/nanoc/helpers/capturing.rb +1 -1
  16. data/lib/nanoc/helpers/link_to.rb +1 -1
  17. data/lib/nanoc/helpers/rendering.rb +5 -4
  18. data/lib/nanoc/orig_cli.rb +15 -0
  19. data/lib/nanoc/{cli → orig_cli}/commands/show-rules.rb +3 -3
  20. data/lib/nanoc/rule_dsl.rb +1 -0
  21. data/lib/nanoc/rule_dsl/action_provider.rb +6 -6
  22. data/lib/nanoc/rule_dsl/action_recorder.rb +4 -4
  23. data/lib/nanoc/rule_dsl/compilation_rule_context.rb +1 -1
  24. data/lib/nanoc/rule_dsl/compiler_dsl.rb +2 -2
  25. data/lib/nanoc/rule_dsl/errors.rb +25 -0
  26. data/lib/nanoc/rule_dsl/rule_context.rb +6 -6
  27. data/lib/nanoc/rule_dsl/rules_loader.rb +1 -1
  28. data/lib/nanoc/version.rb +1 -1
  29. metadata +23 -158
  30. data/lib/nanoc/base.rb +0 -16
  31. data/lib/nanoc/base/changes_stream.rb +0 -53
  32. data/lib/nanoc/base/error.rb +0 -7
  33. data/lib/nanoc/base/errors.rb +0 -163
  34. data/lib/nanoc/base/feature.rb +0 -104
  35. data/lib/nanoc/base/repos.rb +0 -4
  36. data/lib/nanoc/base/repos/config_loader.rb +0 -95
  37. data/lib/nanoc/base/repos/site_loader.rb +0 -102
  38. data/lib/nanoc/base/services.rb +0 -23
  39. data/lib/nanoc/base/services/compiler.rb +0 -214
  40. data/lib/nanoc/base/services/compiler/phases.rb +0 -19
  41. data/lib/nanoc/base/services/compiler/phases/abstract.rb +0 -50
  42. data/lib/nanoc/base/services/compiler/phases/cache.rb +0 -45
  43. data/lib/nanoc/base/services/compiler/phases/mark_done.rb +0 -25
  44. data/lib/nanoc/base/services/compiler/phases/notify.rb +0 -21
  45. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +0 -51
  46. data/lib/nanoc/base/services/compiler/phases/resume.rb +0 -54
  47. data/lib/nanoc/base/services/compiler/phases/write.rb +0 -86
  48. data/lib/nanoc/base/services/compiler/stages.rb +0 -23
  49. data/lib/nanoc/base/services/compiler/stages/build_reps.rb +0 -38
  50. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +0 -44
  51. data/lib/nanoc/base/services/compiler/stages/cleanup.rb +0 -45
  52. data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +0 -98
  53. data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +0 -51
  54. data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +0 -22
  55. data/lib/nanoc/base/services/compiler/stages/load_stores.rb +0 -37
  56. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +0 -23
  57. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +0 -34
  58. data/lib/nanoc/base/services/compiler/stages/prune.rb +0 -32
  59. data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +0 -22
  60. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +0 -34
  61. data/lib/nanoc/base/services/compiler_loader.rb +0 -48
  62. data/lib/nanoc/base/services/executor.rb +0 -134
  63. data/lib/nanoc/base/services/filter.rb +0 -267
  64. data/lib/nanoc/base/services/item_rep_builder.rb +0 -54
  65. data/lib/nanoc/base/services/item_rep_selector.rb +0 -69
  66. data/lib/nanoc/base/services/item_rep_writer.rb +0 -86
  67. data/lib/nanoc/base/services/outdatedness_checker.rb +0 -222
  68. data/lib/nanoc/base/services/outdatedness_rules.rb +0 -18
  69. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +0 -41
  70. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +0 -31
  71. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +0 -21
  72. data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +0 -20
  73. data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +0 -20
  74. data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +0 -17
  75. data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +0 -45
  76. data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +0 -26
  77. data/lib/nanoc/base/services/pruner.rb +0 -123
  78. data/lib/nanoc/base/views.rb +0 -40
  79. data/lib/nanoc/base/views/basic_item_rep_collection_view.rb +0 -86
  80. data/lib/nanoc/base/views/basic_item_rep_view.rb +0 -81
  81. data/lib/nanoc/base/views/basic_item_view.rb +0 -52
  82. data/lib/nanoc/base/views/compilation_item_rep_collection_view.rb +0 -10
  83. data/lib/nanoc/base/views/compilation_item_rep_view.rb +0 -49
  84. data/lib/nanoc/base/views/compilation_item_view.rb +0 -45
  85. data/lib/nanoc/base/views/config_view.rb +0 -68
  86. data/lib/nanoc/base/views/identifiable_collection_view.rb +0 -109
  87. data/lib/nanoc/base/views/item_collection_with_reps_view.rb +0 -10
  88. data/lib/nanoc/base/views/item_collection_without_reps_view.rb +0 -10
  89. data/lib/nanoc/base/views/layout_collection_view.rb +0 -10
  90. data/lib/nanoc/base/views/layout_view.rb +0 -7
  91. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +0 -88
  92. data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +0 -58
  93. data/lib/nanoc/base/views/mutable_config_view.rb +0 -14
  94. data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +0 -17
  95. data/lib/nanoc/base/views/mutable_item_collection_view.rb +0 -32
  96. data/lib/nanoc/base/views/mutable_item_view.rb +0 -7
  97. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +0 -24
  98. data/lib/nanoc/base/views/mutable_layout_view.rb +0 -7
  99. data/lib/nanoc/base/views/post_compile_item_collection_view.rb +0 -10
  100. data/lib/nanoc/base/views/post_compile_item_rep_collection_view.rb +0 -10
  101. data/lib/nanoc/base/views/post_compile_item_rep_view.rb +0 -31
  102. data/lib/nanoc/base/views/post_compile_item_view.rb +0 -18
  103. data/lib/nanoc/base/views/view.rb +0 -41
  104. data/lib/nanoc/checking.rb +0 -14
  105. data/lib/nanoc/checking/check.rb +0 -93
  106. data/lib/nanoc/checking/checks.rb +0 -14
  107. data/lib/nanoc/checking/checks/css.rb +0 -16
  108. data/lib/nanoc/checking/checks/external_links.rb +0 -151
  109. data/lib/nanoc/checking/checks/html.rb +0 -16
  110. data/lib/nanoc/checking/checks/internal_links.rb +0 -95
  111. data/lib/nanoc/checking/checks/mixed_content.rb +0 -37
  112. data/lib/nanoc/checking/checks/stale.rb +0 -41
  113. data/lib/nanoc/checking/checks/w3c_validator.rb +0 -31
  114. data/lib/nanoc/checking/dsl.rb +0 -27
  115. data/lib/nanoc/checking/issue.rb +0 -16
  116. data/lib/nanoc/checking/loader.rb +0 -50
  117. data/lib/nanoc/checking/runner.rb +0 -136
  118. data/lib/nanoc/cli.rb +0 -241
  119. data/lib/nanoc/cli/ansi_string_colorizer.rb +0 -28
  120. data/lib/nanoc/cli/cleaning_stream.rb +0 -160
  121. data/lib/nanoc/cli/command_runner.rb +0 -72
  122. data/lib/nanoc/cli/commands/check.rb +0 -43
  123. data/lib/nanoc/cli/commands/compile.rb +0 -57
  124. data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +0 -58
  125. data/lib/nanoc/cli/commands/compile_listeners/aggregate.rb +0 -50
  126. data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +0 -100
  127. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +0 -101
  128. data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +0 -76
  129. data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +0 -170
  130. data/lib/nanoc/cli/commands/create-site.rb +0 -257
  131. data/lib/nanoc/cli/commands/deploy.rb +0 -126
  132. data/lib/nanoc/cli/commands/nanoc.rb +0 -42
  133. data/lib/nanoc/cli/commands/prune.rb +0 -49
  134. data/lib/nanoc/cli/commands/shell.rb +0 -57
  135. data/lib/nanoc/cli/commands/show-data.rb +0 -185
  136. data/lib/nanoc/cli/commands/show-plugins.rb +0 -89
  137. data/lib/nanoc/cli/commands/view.rb +0 -68
  138. data/lib/nanoc/cli/error_handler.rb +0 -365
  139. data/lib/nanoc/cli/logger.rb +0 -75
  140. data/lib/nanoc/cli/stack_trace_writer.rb +0 -50
  141. data/lib/nanoc/cli/stream_cleaners.rb +0 -10
  142. data/lib/nanoc/cli/stream_cleaners/abstract.rb +0 -21
  143. data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +0 -13
  144. data/lib/nanoc/cli/stream_cleaners/utf8.rb +0 -17
  145. data/lib/nanoc/cli/transform.rb +0 -16
  146. data/lib/nanoc/deploying.rb +0 -10
  147. data/lib/nanoc/deploying/deployer.rb +0 -45
  148. data/lib/nanoc/deploying/deployers.rb +0 -11
  149. data/lib/nanoc/deploying/deployers/fog.rb +0 -220
  150. data/lib/nanoc/deploying/deployers/git.rb +0 -112
  151. data/lib/nanoc/deploying/deployers/rsync.rb +0 -68
  152. data/lib/nanoc/extra/core_ext/pathname.rb +0 -27
  153. data/lib/nanoc/spec.rb +0 -240
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
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
9
-
10
- # @return [Boolean]
11
- def self.cwd_is_nanoc_site?
12
- Nanoc::Int::ConfigLoader.cwd_is_nanoc_site?
13
- end
14
-
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::Core::PrefixedDataSource.new(ds, ds.items_root, ds.layouts_root)
20
- end
21
- end
22
-
23
- Nanoc::Core::AggregateDataSource.new(data_sources_to_aggregate, config)
24
- end
25
-
26
- private
27
-
28
- def site_from_config(config)
29
- code_snippets = code_snippets_from_config(config)
30
- code_snippets.each(&:load)
31
-
32
- data_source = gen_data_source_for_config(config)
33
-
34
- Nanoc::Core::Site.new(
35
- config: config,
36
- code_snippets: code_snippets,
37
- data_source: data_source,
38
- )
39
- end
40
-
41
- def with_data_sources(config, &_block)
42
- data_sources = create_data_sources(config)
43
-
44
- begin
45
- data_sources.each(&:use)
46
- yield(data_sources)
47
- ensure
48
- data_sources.each(&:unuse)
49
- end
50
- end
51
-
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
59
-
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
68
- end
69
-
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
78
- end
79
- end
80
-
81
- ENCODING_REGEX = /\A#\s+(-\*-\s+)?(en)?coding: (?<encoding>[^\s]+)(\s+-\*-\s*)?\n{0,2}/.freeze
82
-
83
- def encoding_from_magic_comment(raw)
84
- match = ENCODING_REGEX.match(raw)
85
- match ? match['encoding'] : nil
86
- end
87
-
88
- def read_code_snippet_contents(filename)
89
- raw = File.read(filename, encoding: 'ASCII-8BIT')
90
-
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
97
-
98
- raw
99
- end
100
- end
101
- end
102
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'services/compiler'
4
- require_relative 'services/compiler_loader'
5
- require_relative 'services/executor'
6
- require_relative 'services/filter'
7
- require_relative 'services/item_rep_builder'
8
- require_relative 'services/item_rep_selector'
9
- require_relative 'services/item_rep_writer'
10
- require_relative 'services/pruner'
11
- require_relative 'services/outdatedness_rules'
12
-
13
- require_relative 'services/compiler/phases'
14
- require_relative 'services/compiler/stages'
15
-
16
- require_relative 'services/outdatedness_checker'
17
-
18
- # TODO: Move this into the entity, once the load order is improved (i.e. the
19
- # checksummer is loaded after CodeSnippet).
20
- Nanoc::Core::Checksummer.define_behavior(
21
- Nanoc::Core::CodeSnippet,
22
- Nanoc::Core::Checksummer::DataUpdateBehavior,
23
- )
@@ -1,214 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- class Compiler
6
- include Nanoc::Core::ContractsSupport
7
-
8
- def initialize(site, compiled_content_cache:, checksum_store:, action_sequence_store:, action_provider:, dependency_store:, outdatedness_store:)
9
- @site = site
10
-
11
- # Needed because configuration is mutable :(
12
- @output_dirs = @site.config.output_dirs
13
-
14
- @compiled_content_cache = compiled_content_cache
15
- @checksum_store = checksum_store
16
- @action_sequence_store = action_sequence_store
17
- @dependency_store = dependency_store
18
- @action_provider = action_provider
19
- @outdatedness_store = outdatedness_store
20
-
21
- @compiled_content_store = Nanoc::Core::CompiledContentStore.new
22
- end
23
-
24
- contract Nanoc::Core::Site => C::Any
25
- def self.compile(site)
26
- new_for(site).run_until_end
27
- end
28
-
29
- contract Nanoc::Core::Site => Nanoc::Int::Compiler
30
- def self.new_for(site)
31
- Nanoc::Int::CompilerLoader.new.load(site)
32
- end
33
-
34
- def run_until_preprocessed
35
- @_res_preprocessed ||= begin
36
- preprocess_stage.call
37
- {}
38
- end
39
- end
40
-
41
- def run_until_reps_built
42
- @_res_reps_built ||= begin
43
- prev = run_until_preprocessed
44
-
45
- res = build_reps_stage.call
46
-
47
- prev.merge(
48
- reps: res.fetch(:reps),
49
- action_sequences: res.fetch(:action_sequences),
50
- )
51
- end
52
- end
53
-
54
- def run_until_precompiled
55
- @_res_precompiled ||= begin
56
- prev = run_until_reps_built
57
- action_sequences = prev.fetch(:action_sequences)
58
- reps = prev.fetch(:reps)
59
-
60
- load_stores_stage.call
61
- checksums = calculate_checksums_stage.call
62
- outdatedness_checker = create_outdatedness_checker(
63
- checksums: checksums,
64
- action_sequences: action_sequences,
65
- reps: reps,
66
- )
67
- outdated_items = determine_outdatedness_stage(outdatedness_checker, reps).call
68
-
69
- prev.merge(
70
- checksums: checksums,
71
- dependency_store: @dependency_store,
72
- outdatedness_checker: outdatedness_checker,
73
- outdated_items: outdated_items,
74
- )
75
- end
76
- end
77
-
78
- def run_until_end
79
- res = run_until_precompiled
80
- action_sequences = res.fetch(:action_sequences)
81
- reps = res.fetch(:reps)
82
- checksums = res.fetch(:checksums)
83
- outdated_items = res.fetch(:outdated_items)
84
-
85
- forget_outdated_dependencies_stage.call(outdated_items)
86
- store_pre_compilation_state_stage(action_sequences, reps).call(checksums)
87
- prune_stage(reps).call
88
- compile_reps_stage(action_sequences, reps).call
89
- store_post_compilation_state_stage.call
90
- postprocess_stage.call(self)
91
- ensure
92
- cleanup_stage.call
93
- end
94
-
95
- def compilation_context(reps:)
96
- Nanoc::Core::CompilationContext.new(
97
- action_provider: @action_provider,
98
- reps: reps,
99
- site: @site,
100
- compiled_content_cache: @compiled_content_cache,
101
- compiled_content_store: @compiled_content_store,
102
- )
103
- end
104
-
105
- private
106
-
107
- def create_outdatedness_checker(checksums:, action_sequences:, reps:)
108
- Nanoc::Int::OutdatednessChecker.new(
109
- site: @site,
110
- checksum_store: @checksum_store,
111
- dependency_store: @dependency_store,
112
- action_sequence_store: @action_sequence_store,
113
- action_sequences: action_sequences,
114
- checksums: checksums,
115
- reps: reps,
116
- )
117
- end
118
-
119
- def preprocess_stage
120
- @_preprocess_stage ||= Stages::Preprocess.new(
121
- action_provider: @action_provider,
122
- site: @site,
123
- dependency_store: @dependency_store,
124
- checksum_store: @checksum_store,
125
- )
126
- end
127
-
128
- def build_reps_stage
129
- @_build_reps_stage ||= Stages::BuildReps.new(
130
- site: @site,
131
- action_provider: @action_provider,
132
- )
133
- end
134
-
135
- def prune_stage(reps)
136
- @_prune_stage ||= Stages::Prune.new(
137
- config: @site.config,
138
- reps: reps,
139
- )
140
- end
141
-
142
- def load_stores_stage
143
- @_load_stores_stage ||= Stages::LoadStores.new(
144
- checksum_store: @checksum_store,
145
- compiled_content_cache: @compiled_content_cache,
146
- dependency_store: @dependency_store,
147
- action_sequence_store: @action_sequence_store,
148
- outdatedness_store: @outdatedness_store,
149
- )
150
- end
151
-
152
- def calculate_checksums_stage
153
- @_calculate_checksums_stage ||= Stages::CalculateChecksums.new(
154
- items: @site.items,
155
- layouts: @site.layouts,
156
- code_snippets: @site.code_snippets,
157
- config: @site.config,
158
- )
159
- end
160
-
161
- def determine_outdatedness_stage(outdatedness_checker, reps)
162
- @_determine_outdatedness_stage ||= Stages::DetermineOutdatedness.new(
163
- reps: reps,
164
- outdatedness_checker: outdatedness_checker,
165
- outdatedness_store: @outdatedness_store,
166
- )
167
- end
168
-
169
- def store_pre_compilation_state_stage(action_sequences, reps)
170
- @_store_pre_compilation_state_stage ||= Stages::StorePreCompilationState.new(
171
- reps: reps,
172
- layouts: @site.layouts,
173
- checksum_store: @checksum_store,
174
- action_sequence_store: @action_sequence_store,
175
- action_sequences: action_sequences,
176
- )
177
- end
178
-
179
- def compile_reps_stage(action_sequences, reps)
180
- @_compile_reps_stage ||= Stages::CompileReps.new(
181
- reps: reps,
182
- outdatedness_store: @outdatedness_store,
183
- dependency_store: @dependency_store,
184
- action_sequences: action_sequences,
185
- compilation_context: compilation_context(reps: reps),
186
- compiled_content_cache: @compiled_content_cache,
187
- )
188
- end
189
-
190
- def store_post_compilation_state_stage
191
- @_store_post_compilation_state_stage ||= Stages::StorePostCompilationState.new(
192
- dependency_store: @dependency_store,
193
- )
194
- end
195
-
196
- def postprocess_stage
197
- @_postprocess_stage ||= Stages::Postprocess.new(
198
- action_provider: @action_provider,
199
- site: @site,
200
- )
201
- end
202
-
203
- def cleanup_stage
204
- @_cleanup_stage ||= Stages::Cleanup.new(@output_dirs)
205
- end
206
-
207
- def forget_outdated_dependencies_stage
208
- @_forget_outdated_dependencies_stage ||= Stages::ForgetOutdatedDependencies.new(
209
- dependency_store: @dependency_store,
210
- )
211
- end
212
- end
213
- end
214
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- class Compiler
6
- module Phases
7
- end
8
- end
9
- end
10
- end
11
-
12
- require_relative 'phases/abstract'
13
-
14
- require_relative 'phases/recalculate'
15
- require_relative 'phases/cache'
16
- require_relative 'phases/resume'
17
- require_relative 'phases/write'
18
- require_relative 'phases/mark_done'
19
- require_relative 'phases/notify'
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- class Compiler
6
- module Phases
7
- class Abstract
8
- include Nanoc::Core::ContractsSupport
9
-
10
- def initialize(wrapped:)
11
- @wrapped = wrapped
12
- end
13
-
14
- def start
15
- @wrapped&.start
16
- end
17
-
18
- def stop
19
- @wrapped&.stop
20
- end
21
-
22
- def call(rep, is_outdated:)
23
- notify(:phase_started, rep)
24
- run(rep, is_outdated: is_outdated) do
25
- notify(:phase_yielded, rep)
26
- @wrapped.call(rep, is_outdated: is_outdated)
27
- notify(:phase_resumed, rep)
28
- end
29
- notify(:phase_ended, rep)
30
- rescue
31
- notify(:phase_aborted, rep)
32
- raise
33
- end
34
-
35
- contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
36
- def run(_rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
37
- raise NotImplementedError
38
- end
39
-
40
- private
41
-
42
- def notify(sym, rep)
43
- name = self.class.to_s.sub(/^.*::/, '')
44
- Nanoc::Core::NotificationCenter.post(sym, name, rep)
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- class Compiler
6
- module Phases
7
- # Provides functionality for (re)calculating the content of an item rep, with caching or
8
- # outdatedness checking. Delegates to s::Recalculate if outdated or no cache available.
9
- class Cache < Abstract
10
- include Nanoc::Core::ContractsSupport
11
-
12
- def initialize(wrapped:, compiled_content_cache:, compiled_content_store:)
13
- super(wrapped: wrapped)
14
-
15
- @compiled_content_cache = compiled_content_cache
16
- @compiled_content_store = compiled_content_store
17
- end
18
-
19
- contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
20
- def run(rep, is_outdated:)
21
- if can_reuse_content_for_rep?(rep, is_outdated: is_outdated)
22
- Nanoc::Core::NotificationCenter.post(:cached_content_used, rep)
23
-
24
- @compiled_content_store.set_all(rep, @compiled_content_cache[rep])
25
- else
26
- yield
27
- end
28
-
29
- rep.compiled = true
30
- @compiled_content_cache[rep] = @compiled_content_store.get_all(rep)
31
- end
32
-
33
- contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool] => C::Bool
34
- def can_reuse_content_for_rep?(rep, is_outdated:)
35
- if is_outdated
36
- false
37
- else
38
- @compiled_content_cache.full_cache_available?(rep)
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end