lib/nanoc/base/services/executor.rb in nanoc-4.1.6 vs lib/nanoc/base/services/executor.rb in nanoc-4.2.0b1
- old
+ new
@@ -5,53 +5,40 @@
def initialize(filter_name, output_filename)
super("The #{filter_name.inspect} filter did not write anything to the required output file, #{output_filename}.")
end
end
- def initialize(compiler)
+ def initialize(compiler, dependency_tracker)
@compiler = compiler
+ @dependency_tracker = dependency_tracker
end
def filter(rep, filter_name, filter_args = {})
- # Get filter class
- klass = Nanoc::Filter.named(filter_name)
- raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?
+ filter = filter_for_filtering(rep, filter_name)
- # Check whether filter can be applied
- if klass.from_binary? && !rep.binary?
- raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(rep, klass)
- elsif !klass.from_binary? && rep.binary?
- raise Nanoc::Int::Errors::CannotUseTextualFilter.new(rep, klass)
- end
-
begin
- # Notify start
Nanoc::Int::NotificationCenter.post(:filtering_started, rep, filter_name)
- # Create filter
- filter = klass.new(assigns_for(rep))
-
# Run filter
last = rep.snapshot_contents[:last]
source = rep.binary? ? last.filename : last.string
result = filter.setup_and_run(source, filter_args)
rep.snapshot_contents[:last] =
- if klass.to_binary?
+ if filter.class.to_binary?
Nanoc::Int::BinaryContent.new(filter.output_filename).tap(&:freeze)
else
Nanoc::Int::TextualContent.new(result).tap(&:freeze)
end
# Check whether file was written
- if klass.to_binary? && !File.file?(filter.output_filename)
+ if filter.class.to_binary? && !File.file?(filter.output_filename)
raise OutputNotWrittenError.new(filter_name, filter.output_filename)
end
# Create snapshot
snapshot(rep, rep.snapshot_contents[:post] ? :post : :pre, final: false) unless rep.binary?
ensure
- # Notify end
Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, filter_name)
end
end
def layout(rep, layout_identifier, extra_filter_args = nil)
@@ -71,16 +58,16 @@
end
# Create filter
klass = Nanoc::Filter.named(filter_name)
raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?
- layout_view = Nanoc::LayoutView.new(layout, nil)
+ view_context = @compiler.create_view_context(@dependency_tracker)
+ layout_view = Nanoc::LayoutView.new(layout, view_context)
filter = klass.new(assigns_for(rep).merge({ layout: layout_view }))
# Visit
- Nanoc::Int::NotificationCenter.post(:visit_started, layout)
- Nanoc::Int::NotificationCenter.post(:visit_ended, layout)
+ @dependency_tracker.bounce(layout)
begin
# Notify start
Nanoc::Int::NotificationCenter.post(:processing_started, layout)
Nanoc::Int::NotificationCenter.post(:filtering_started, rep, filter_name)
@@ -118,11 +105,11 @@
end
end
end
def assigns_for(rep)
- @compiler.assigns_for(rep)
+ @compiler.assigns_for(rep, @dependency_tracker)
end
def layouts
@compiler.site.layouts
end
@@ -137,9 +124,22 @@
layout = layouts.find { |l| pat.match?(l.identifier) }
return layout if layout
end
raise Nanoc::Int::Errors::UnknownLayout.new(arg)
+ end
+
+ def filter_for_filtering(rep, filter_name)
+ klass = Nanoc::Filter.named(filter_name)
+ raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?
+
+ if klass.from_binary? && !rep.binary?
+ raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(rep, klass)
+ elsif !klass.from_binary? && rep.binary?
+ raise Nanoc::Int::Errors::CannotUseTextualFilter.new(rep, klass)
+ end
+
+ klass.new(assigns_for(rep))
end
def use_globs?
@compiler.site.config[:string_pattern_type] == 'glob'
end