nanoc 4.11.12 → 4.11.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +7 -1
- data/bin/nanoc +1 -1
- data/lib/nanoc.rb +2 -27
- data/lib/nanoc/base.rb +3 -6
- data/lib/nanoc/base/errors.rb +6 -104
- data/lib/nanoc/checking/check.rb +4 -4
- data/lib/nanoc/checking/checks/external_links.rb +1 -1
- data/lib/nanoc/checking/checks/stale.rb +1 -1
- data/lib/nanoc/checking/runner.rb +2 -2
- data/lib/nanoc/data_sources/filesystem/tools.rb +4 -4
- data/lib/nanoc/extra.rb +1 -1
- data/lib/nanoc/helpers/blogging.rb +8 -8
- data/lib/nanoc/helpers/capturing.rb +1 -1
- data/lib/nanoc/helpers/link_to.rb +1 -1
- data/lib/nanoc/orig_cli.rb +20 -0
- data/lib/nanoc/{cli → orig_cli}/commands/check.rb +3 -3
- data/lib/nanoc/{cli → orig_cli}/commands/deploy.rb +8 -8
- data/lib/nanoc/{cli → orig_cli}/commands/show-rules.rb +3 -3
- data/lib/nanoc/rule_dsl/action_provider.rb +5 -5
- data/lib/nanoc/rule_dsl/action_recorder.rb +4 -4
- data/lib/nanoc/rule_dsl/compilation_rule_context.rb +1 -1
- data/lib/nanoc/rule_dsl/compiler_dsl.rb +1 -1
- data/lib/nanoc/rule_dsl/rule_context.rb +6 -6
- data/lib/nanoc/version.rb +1 -1
- metadata +13 -152
- data/lib/nanoc/base/error.rb +0 -7
- data/lib/nanoc/base/feature.rb +0 -104
- data/lib/nanoc/base/repos.rb +0 -4
- data/lib/nanoc/base/repos/config_loader.rb +0 -95
- data/lib/nanoc/base/repos/site_loader.rb +0 -102
- data/lib/nanoc/base/services.rb +0 -23
- data/lib/nanoc/base/services/compiler.rb +0 -214
- data/lib/nanoc/base/services/compiler/phases.rb +0 -19
- data/lib/nanoc/base/services/compiler/phases/abstract.rb +0 -50
- data/lib/nanoc/base/services/compiler/phases/cache.rb +0 -45
- data/lib/nanoc/base/services/compiler/phases/mark_done.rb +0 -25
- data/lib/nanoc/base/services/compiler/phases/notify.rb +0 -21
- data/lib/nanoc/base/services/compiler/phases/recalculate.rb +0 -51
- data/lib/nanoc/base/services/compiler/phases/resume.rb +0 -54
- data/lib/nanoc/base/services/compiler/phases/write.rb +0 -86
- data/lib/nanoc/base/services/compiler/stages.rb +0 -23
- data/lib/nanoc/base/services/compiler/stages/build_reps.rb +0 -38
- data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +0 -44
- data/lib/nanoc/base/services/compiler/stages/cleanup.rb +0 -45
- data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +0 -98
- data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +0 -51
- data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +0 -22
- data/lib/nanoc/base/services/compiler/stages/load_stores.rb +0 -37
- data/lib/nanoc/base/services/compiler/stages/postprocess.rb +0 -23
- data/lib/nanoc/base/services/compiler/stages/preprocess.rb +0 -34
- data/lib/nanoc/base/services/compiler/stages/prune.rb +0 -32
- data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +0 -22
- data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +0 -34
- data/lib/nanoc/base/services/compiler_loader.rb +0 -48
- data/lib/nanoc/base/services/executor.rb +0 -134
- data/lib/nanoc/base/services/filter.rb +0 -267
- data/lib/nanoc/base/services/item_rep_builder.rb +0 -54
- data/lib/nanoc/base/services/item_rep_selector.rb +0 -69
- data/lib/nanoc/base/services/item_rep_writer.rb +0 -86
- data/lib/nanoc/base/services/outdatedness_checker.rb +0 -222
- data/lib/nanoc/base/services/outdatedness_rules.rb +0 -18
- data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +0 -41
- data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +0 -31
- data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +0 -21
- data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +0 -20
- data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +0 -20
- data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +0 -17
- data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +0 -45
- data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +0 -26
- data/lib/nanoc/base/services/pruner.rb +0 -123
- data/lib/nanoc/base/views.rb +0 -40
- data/lib/nanoc/base/views/basic_item_rep_collection_view.rb +0 -86
- data/lib/nanoc/base/views/basic_item_rep_view.rb +0 -81
- data/lib/nanoc/base/views/basic_item_view.rb +0 -52
- data/lib/nanoc/base/views/compilation_item_rep_collection_view.rb +0 -10
- data/lib/nanoc/base/views/compilation_item_rep_view.rb +0 -49
- data/lib/nanoc/base/views/compilation_item_view.rb +0 -45
- data/lib/nanoc/base/views/config_view.rb +0 -68
- data/lib/nanoc/base/views/identifiable_collection_view.rb +0 -109
- data/lib/nanoc/base/views/item_collection_with_reps_view.rb +0 -10
- data/lib/nanoc/base/views/item_collection_without_reps_view.rb +0 -10
- data/lib/nanoc/base/views/layout_collection_view.rb +0 -10
- data/lib/nanoc/base/views/layout_view.rb +0 -7
- data/lib/nanoc/base/views/mixins/document_view_mixin.rb +0 -88
- data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +0 -58
- data/lib/nanoc/base/views/mutable_config_view.rb +0 -14
- data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +0 -17
- data/lib/nanoc/base/views/mutable_item_collection_view.rb +0 -32
- data/lib/nanoc/base/views/mutable_item_view.rb +0 -7
- data/lib/nanoc/base/views/mutable_layout_collection_view.rb +0 -24
- data/lib/nanoc/base/views/mutable_layout_view.rb +0 -7
- data/lib/nanoc/base/views/post_compile_item_collection_view.rb +0 -10
- data/lib/nanoc/base/views/post_compile_item_rep_collection_view.rb +0 -10
- data/lib/nanoc/base/views/post_compile_item_rep_view.rb +0 -31
- data/lib/nanoc/base/views/post_compile_item_view.rb +0 -18
- data/lib/nanoc/base/views/view.rb +0 -41
- data/lib/nanoc/cli.rb +0 -241
- data/lib/nanoc/cli/ansi_string_colorizer.rb +0 -28
- data/lib/nanoc/cli/cleaning_stream.rb +0 -160
- data/lib/nanoc/cli/command_runner.rb +0 -72
- data/lib/nanoc/cli/commands/compile.rb +0 -57
- data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +0 -58
- data/lib/nanoc/cli/commands/compile_listeners/aggregate.rb +0 -50
- data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +0 -100
- data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +0 -101
- data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +0 -76
- data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +0 -170
- data/lib/nanoc/cli/commands/create-site.rb +0 -257
- data/lib/nanoc/cli/commands/nanoc.rb +0 -42
- data/lib/nanoc/cli/commands/prune.rb +0 -49
- data/lib/nanoc/cli/commands/shell.rb +0 -57
- data/lib/nanoc/cli/commands/show-data.rb +0 -185
- data/lib/nanoc/cli/commands/show-plugins.rb +0 -89
- data/lib/nanoc/cli/commands/view.rb +0 -68
- data/lib/nanoc/cli/error_handler.rb +0 -365
- data/lib/nanoc/cli/logger.rb +0 -75
- data/lib/nanoc/cli/stack_trace_writer.rb +0 -50
- data/lib/nanoc/cli/stream_cleaners.rb +0 -10
- data/lib/nanoc/cli/stream_cleaners/abstract.rb +0 -21
- data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +0 -13
- data/lib/nanoc/cli/stream_cleaners/utf8.rb +0 -17
- data/lib/nanoc/cli/transform.rb +0 -16
- data/lib/nanoc/spec.rb +0 -240
@@ -1,134 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc
|
4
|
-
module Int
|
5
|
-
class Executor
|
6
|
-
def initialize(rep, compilation_context, dependency_tracker)
|
7
|
-
@rep = rep
|
8
|
-
@compilation_context = compilation_context
|
9
|
-
@dependency_tracker = dependency_tracker
|
10
|
-
end
|
11
|
-
|
12
|
-
def filter(filter_name, filter_args = {})
|
13
|
-
filter = filter_for_filtering(filter_name)
|
14
|
-
|
15
|
-
begin
|
16
|
-
Nanoc::Core::NotificationCenter.post(:filtering_started, @rep, filter_name)
|
17
|
-
|
18
|
-
# Run filter
|
19
|
-
last = @compilation_context.compiled_content_store.get_current(@rep)
|
20
|
-
source = last.binary? ? last.filename : last.string
|
21
|
-
filter_args.freeze
|
22
|
-
result = filter.setup_and_run(source, filter_args)
|
23
|
-
last =
|
24
|
-
if filter.class.to_binary?
|
25
|
-
Nanoc::Core::BinaryContent.new(filter.output_filename).tap(&:freeze)
|
26
|
-
else
|
27
|
-
Nanoc::Core::TextualContent.new(result).tap(&:freeze)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Store
|
31
|
-
@compilation_context.compiled_content_store.set_current(@rep, last)
|
32
|
-
ensure
|
33
|
-
Nanoc::Core::NotificationCenter.post(:filtering_ended, @rep, filter_name)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def layout(layout_identifier, extra_filter_args = nil)
|
38
|
-
layout = find_layout(layout_identifier)
|
39
|
-
filter_name_and_args = @compilation_context.filter_name_and_args_for_layout(layout)
|
40
|
-
filter_name = filter_name_and_args.name
|
41
|
-
if filter_name.nil?
|
42
|
-
raise ::Nanoc::Core::Error, "Cannot find rule for layout matching #{layout_identifier}"
|
43
|
-
end
|
44
|
-
|
45
|
-
filter_args = filter_name_and_args.args
|
46
|
-
filter_args = filter_args.merge(extra_filter_args || {})
|
47
|
-
filter_args.freeze
|
48
|
-
|
49
|
-
# Check whether item can be laid out
|
50
|
-
last = @compilation_context.compiled_content_store.get_current(@rep)
|
51
|
-
raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(@rep) if last.binary?
|
52
|
-
|
53
|
-
# Create filter
|
54
|
-
klass = Nanoc::Filter.named!(filter_name)
|
55
|
-
layout_view = Nanoc::LayoutView.new(layout, view_context)
|
56
|
-
filter = klass.new(assigns.merge(layout: layout_view))
|
57
|
-
|
58
|
-
# Visit
|
59
|
-
@dependency_tracker.bounce(layout, raw_content: true)
|
60
|
-
|
61
|
-
begin
|
62
|
-
Nanoc::Core::NotificationCenter.post(:filtering_started, @rep, filter_name)
|
63
|
-
|
64
|
-
# Layout
|
65
|
-
content = layout.content
|
66
|
-
arg = content.binary? ? content.filename : content.string
|
67
|
-
res = filter.setup_and_run(arg, filter_args)
|
68
|
-
|
69
|
-
# Store
|
70
|
-
last = Nanoc::Core::TextualContent.new(res).tap(&:freeze)
|
71
|
-
@compilation_context.compiled_content_store.set_current(@rep, last)
|
72
|
-
ensure
|
73
|
-
Nanoc::Core::NotificationCenter.post(:filtering_ended, @rep, filter_name)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def snapshot(snapshot_name)
|
78
|
-
last = @compilation_context.compiled_content_store.get_current(@rep)
|
79
|
-
@compilation_context.compiled_content_store.set(@rep, snapshot_name, last)
|
80
|
-
Nanoc::Core::NotificationCenter.post(:snapshot_created, @rep, snapshot_name)
|
81
|
-
end
|
82
|
-
|
83
|
-
def assigns
|
84
|
-
view_context.assigns_for(@rep, site: @compilation_context.site)
|
85
|
-
end
|
86
|
-
|
87
|
-
def layouts
|
88
|
-
@compilation_context.site.layouts
|
89
|
-
end
|
90
|
-
|
91
|
-
def find_layout(arg)
|
92
|
-
req_id = arg.__nanoc_cleaned_identifier
|
93
|
-
layout = layouts[req_id]
|
94
|
-
return layout if layout
|
95
|
-
|
96
|
-
if use_globs?
|
97
|
-
pat = Nanoc::Core::Pattern.from(arg)
|
98
|
-
layout = layouts.find { |l| pat.match?(l.identifier) }
|
99
|
-
return layout if layout
|
100
|
-
end
|
101
|
-
|
102
|
-
raise Nanoc::Int::Errors::UnknownLayout.new(arg)
|
103
|
-
end
|
104
|
-
|
105
|
-
def filter_for_filtering(filter_name)
|
106
|
-
klass = Nanoc::Filter.named!(filter_name)
|
107
|
-
|
108
|
-
last = @compilation_context.compiled_content_store.get_current(@rep)
|
109
|
-
if klass.from_binary? && !last.binary?
|
110
|
-
raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(@rep, klass)
|
111
|
-
elsif !klass.from_binary? && last.binary?
|
112
|
-
raise Nanoc::Int::Errors::CannotUseTextualFilter.new(@rep, klass)
|
113
|
-
end
|
114
|
-
|
115
|
-
klass.new(assigns)
|
116
|
-
end
|
117
|
-
|
118
|
-
def use_globs?
|
119
|
-
@compilation_context.site.config[:string_pattern_type] == 'glob'
|
120
|
-
end
|
121
|
-
|
122
|
-
def view_context
|
123
|
-
@_view_context ||=
|
124
|
-
Nanoc::Core::ViewContextForCompilation.new(
|
125
|
-
reps: @compilation_context.reps,
|
126
|
-
items: @compilation_context.site.items,
|
127
|
-
dependency_tracker: @dependency_tracker,
|
128
|
-
compilation_context: @compilation_context,
|
129
|
-
compiled_content_store: @compilation_context.compiled_content_store,
|
130
|
-
)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc
|
4
|
-
# Nanoc::Filter is responsible for filtering items. It is the superclass
|
5
|
-
# for all textual filters.
|
6
|
-
#
|
7
|
-
# A filter instance should only be used once. Filters should not be reused
|
8
|
-
# since they store state.
|
9
|
-
#
|
10
|
-
# When creating a filter with a hash containing assigned variables, those
|
11
|
-
# variables will be made available in the `@assigns` instance variable and
|
12
|
-
# the {#assigns} method. The assigns itself will also be available as
|
13
|
-
# instance variables and instance methods.
|
14
|
-
#
|
15
|
-
# @example Accessing assigns in different ways
|
16
|
-
#
|
17
|
-
# filter = SomeFilter.new({ :foo => 'bar' })
|
18
|
-
# filter.instance_eval { @assigns[:foo] }
|
19
|
-
# # => 'bar'
|
20
|
-
# filter.instance_eval { assigns[:foo] }
|
21
|
-
# # => 'bar'
|
22
|
-
# filter.instance_eval { @foo }
|
23
|
-
# # => 'bar'
|
24
|
-
# filter.instance_eval { foo }
|
25
|
-
# # => 'bar'
|
26
|
-
#
|
27
|
-
# @abstract Subclass and override {#run} to implement a custom filter.
|
28
|
-
class Filter < Nanoc::Core::Context
|
29
|
-
# @api private
|
30
|
-
TMP_BINARY_ITEMS_DIR = 'binary_items'
|
31
|
-
|
32
|
-
extend DDPlugin::Plugin
|
33
|
-
|
34
|
-
include Nanoc::Core::ContractsSupport
|
35
|
-
|
36
|
-
class UnknownFilterError < Nanoc::Core::Error
|
37
|
-
include Nanoc::Core::ContractsSupport
|
38
|
-
|
39
|
-
contract C::Or[String, Symbol] => self
|
40
|
-
def initialize(filter_name)
|
41
|
-
super("The requested filter, “#{filter_name}”, does not exist.")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class OutputNotWrittenError < Nanoc::Core::Error
|
46
|
-
include Nanoc::Core::ContractsSupport
|
47
|
-
|
48
|
-
contract C::Or[String, Symbol], String => self
|
49
|
-
def initialize(filter_name, output_filename)
|
50
|
-
super("The #{filter_name.inspect} filter did not write anything to the required output file, #{output_filename}.")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class FilterReturnedNilError < Nanoc::Core::Error
|
55
|
-
include Nanoc::Core::ContractsSupport
|
56
|
-
|
57
|
-
contract C::Or[String, Symbol] => self
|
58
|
-
def initialize(filter_name)
|
59
|
-
super("The #{filter_name.inspect} filter returned nil, but is required to return a String.")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class << self
|
64
|
-
def define(ident, &block)
|
65
|
-
filter_class = Class.new(::Nanoc::Filter) { identifier(ident) }
|
66
|
-
filter_class.send(:define_method, :run) do |content, params = {}|
|
67
|
-
instance_exec(content, params, &block)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def named!(name)
|
72
|
-
klass = named(name)
|
73
|
-
raise UnknownFilterError.new(name) if klass.nil?
|
74
|
-
|
75
|
-
klass
|
76
|
-
end
|
77
|
-
|
78
|
-
# Sets the new type for the filter. The type can be `:binary` (default)
|
79
|
-
# or `:text`. The given argument can either be a symbol indicating both
|
80
|
-
# “from” and “to” types, or a hash where the only key is the “from” type
|
81
|
-
# and the only value is the “to” type.
|
82
|
-
#
|
83
|
-
# @example Specifying a text-to-text filter
|
84
|
-
#
|
85
|
-
# type :text
|
86
|
-
#
|
87
|
-
# @example Specifying a text-to-binary filter
|
88
|
-
#
|
89
|
-
# type :text => :binary
|
90
|
-
#
|
91
|
-
# @param [Symbol, Hash] arg The new type of this filter
|
92
|
-
#
|
93
|
-
# @return [void]
|
94
|
-
def type(arg)
|
95
|
-
if arg.is_a?(Hash)
|
96
|
-
@from = arg.keys[0]
|
97
|
-
@to = arg.values[0]
|
98
|
-
else
|
99
|
-
@from = arg
|
100
|
-
@to = arg
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# @return [Boolean] True if this filter can be applied to binary item
|
105
|
-
# representations, false otherwise
|
106
|
-
#
|
107
|
-
# @api private
|
108
|
-
def from_binary?
|
109
|
-
(@from || :text) == :binary
|
110
|
-
end
|
111
|
-
|
112
|
-
# @return [Boolean] True if this filter results in a binary item
|
113
|
-
# representation, false otherwise
|
114
|
-
#
|
115
|
-
# @api private
|
116
|
-
def to_binary?
|
117
|
-
(@to || :text) == :binary
|
118
|
-
end
|
119
|
-
|
120
|
-
# @api private
|
121
|
-
def to_text?
|
122
|
-
(@to || :text) == :text
|
123
|
-
end
|
124
|
-
|
125
|
-
# @return [Boolean]
|
126
|
-
#
|
127
|
-
# @api private
|
128
|
-
def always_outdated?
|
129
|
-
@always_outdated || false
|
130
|
-
end
|
131
|
-
|
132
|
-
# Marks this filter as always causing the item rep to be outdated. This is useful for filters
|
133
|
-
# that cannot do dependency tracking properly.
|
134
|
-
#
|
135
|
-
# @return [void]
|
136
|
-
def always_outdated
|
137
|
-
@always_outdated = true
|
138
|
-
end
|
139
|
-
|
140
|
-
# @overload requires(*requires)
|
141
|
-
# Sets the required libraries for this filter.
|
142
|
-
# @param [Array<String>] requires A list of library names that are required
|
143
|
-
# @return [void]
|
144
|
-
# @overload requires
|
145
|
-
# Returns the required libraries for this filter.
|
146
|
-
# @return [Enumerable<String>] This filter’s list of library names that are required
|
147
|
-
def requires(*requires)
|
148
|
-
if requires.any?
|
149
|
-
@requires = requires
|
150
|
-
else
|
151
|
-
@requires || []
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
# Requires the filter’s required library if necessary.
|
156
|
-
#
|
157
|
-
# @return [void]
|
158
|
-
#
|
159
|
-
# @api private
|
160
|
-
def setup
|
161
|
-
@setup ||= begin
|
162
|
-
requires.each { |r| require r }
|
163
|
-
true
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
# Creates a new filter that has access to the given assigns.
|
169
|
-
#
|
170
|
-
# @param [Hash] hash A hash containing variables that should be made
|
171
|
-
# available during filtering.
|
172
|
-
#
|
173
|
-
# @api private
|
174
|
-
def initialize(hash = {})
|
175
|
-
@assigns = hash
|
176
|
-
super
|
177
|
-
end
|
178
|
-
|
179
|
-
# Sets up the filter and runs the filter. This method passes its arguments
|
180
|
-
# to {#run} unchanged and returns the return value from {#run}.
|
181
|
-
#
|
182
|
-
# @see #run
|
183
|
-
#
|
184
|
-
# @api private
|
185
|
-
def setup_and_run(*args)
|
186
|
-
self.class.setup
|
187
|
-
run(*args).tap { |res| verify(res) }
|
188
|
-
end
|
189
|
-
|
190
|
-
# Runs the filter on the given content or filename.
|
191
|
-
#
|
192
|
-
# @abstract
|
193
|
-
#
|
194
|
-
# @param [String] content_or_filename The unprocessed content that should
|
195
|
-
# be filtered (if the item is a textual item) or the path to the file
|
196
|
-
# that should be filtered (if the item is a binary item)
|
197
|
-
#
|
198
|
-
# @param [Hash] params A hash containing parameters. Filter subclasses can
|
199
|
-
# use these parameters to allow modifying the filter's behaviour.
|
200
|
-
#
|
201
|
-
# @return [String, void] If the filter output binary content, the return
|
202
|
-
# value is undefined; if the filter outputs textual content, the return
|
203
|
-
# value will be the filtered content.
|
204
|
-
def run(content_or_filename, params = {}) # rubocop:disable Lint/UnusedMethodArgument
|
205
|
-
raise NotImplementedError.new('Nanoc::Filter subclasses must implement #run')
|
206
|
-
end
|
207
|
-
|
208
|
-
def verify(res)
|
209
|
-
if self.class.to_binary?
|
210
|
-
unless File.file?(output_filename)
|
211
|
-
raise Nanoc::Filter::OutputNotWrittenError.new(self.class.identifier, output_filename)
|
212
|
-
end
|
213
|
-
elsif self.class.to_text?
|
214
|
-
unless res
|
215
|
-
raise Nanoc::Filter::FilterReturnedNilError.new(self.class.identifier)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
contract C::None => String
|
221
|
-
# Returns a filename that is used to write data to. This method is only
|
222
|
-
# used on binary items. When running a binary filter on a file, the
|
223
|
-
# resulting file must end up in the location returned by this method.
|
224
|
-
#
|
225
|
-
# The returned filename will be absolute, so it is safe to change to
|
226
|
-
# another directory inside the filter.
|
227
|
-
#
|
228
|
-
# @return [String] The output filename
|
229
|
-
def output_filename
|
230
|
-
@output_filename ||=
|
231
|
-
Nanoc::Core::TempFilenameFactory.instance.create(TMP_BINARY_ITEMS_DIR)
|
232
|
-
end
|
233
|
-
|
234
|
-
contract C::None => String
|
235
|
-
# Returns the filename associated with the item that is being filtered.
|
236
|
-
# It is in the format `item <identifier> (rep <name>)`.
|
237
|
-
#
|
238
|
-
# @return [String] The filename
|
239
|
-
#
|
240
|
-
# @api private
|
241
|
-
def filename
|
242
|
-
if @layout
|
243
|
-
"layout #{@layout.identifier}"
|
244
|
-
elsif @item
|
245
|
-
"item #{@item.identifier} (rep #{@item_rep.name})"
|
246
|
-
else
|
247
|
-
'?'
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
# @api private
|
252
|
-
def on_main_fiber(&block)
|
253
|
-
Fiber.yield(block)
|
254
|
-
end
|
255
|
-
|
256
|
-
contract C::ArrayOf[C::Named['Nanoc::BasicItemView']] => C::Any
|
257
|
-
# Creates a dependency from the item that is currently being filtered onto
|
258
|
-
# the given collection of items. In other words, require the given items
|
259
|
-
# to be compiled first before this items is processed.
|
260
|
-
#
|
261
|
-
# @return [void]
|
262
|
-
def depend_on(items)
|
263
|
-
items.flat_map(&:reps).flat_map(&:raw_path)
|
264
|
-
items.each(&:raw_filename)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nanoc
|
4
|
-
module Int
|
5
|
-
# @api private
|
6
|
-
class ItemRepBuilder
|
7
|
-
include Nanoc::Core::ContractsSupport
|
8
|
-
|
9
|
-
attr_reader :reps
|
10
|
-
|
11
|
-
contract Nanoc::Core::Site, Nanoc::Core::ActionProvider, Nanoc::Core::ItemRepRepo => C::Any
|
12
|
-
def initialize(site, action_provider, reps)
|
13
|
-
@site = site
|
14
|
-
@action_provider = action_provider
|
15
|
-
@reps = reps
|
16
|
-
end
|
17
|
-
|
18
|
-
def run
|
19
|
-
@site.items.each do |item|
|
20
|
-
@action_provider.rep_names_for(item).each do |rep_name|
|
21
|
-
@reps << Nanoc::Core::ItemRep.new(item, rep_name)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
action_sequences = Nanoc::Core::ItemRepRouter.new(@reps, @action_provider, @site).run
|
26
|
-
|
27
|
-
@reps.each do |rep|
|
28
|
-
rep.snapshot_defs = self.class.snapshot_defs_for(action_sequences[rep])
|
29
|
-
end
|
30
|
-
|
31
|
-
action_sequences
|
32
|
-
end
|
33
|
-
|
34
|
-
contract Nanoc::Core::ActionSequence => C::ArrayOf[Nanoc::Core::SnapshotDef]
|
35
|
-
def self.snapshot_defs_for(action_sequence)
|
36
|
-
is_binary = action_sequence.item_rep.item.content.binary?
|
37
|
-
snapshot_defs = []
|
38
|
-
|
39
|
-
action_sequence.each do |action|
|
40
|
-
case action
|
41
|
-
when Nanoc::Core::ProcessingActions::Snapshot
|
42
|
-
action.snapshot_names.each do |snapshot_name|
|
43
|
-
snapshot_defs << Nanoc::Core::SnapshotDef.new(snapshot_name, binary: is_binary)
|
44
|
-
end
|
45
|
-
when Nanoc::Core::ProcessingActions::Filter
|
46
|
-
is_binary = Nanoc::Filter.named!(action.filter_name).to_binary?
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
snapshot_defs
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|