lib/nanoc/base/services/executor.rb in nanoc-4.5.2 vs lib/nanoc/base/services/executor.rb in nanoc-4.5.3

- old
+ new

@@ -18,21 +18,24 @@ begin Nanoc::Int::NotificationCenter.post(:filtering_started, @rep, filter_name) # Run filter - last = @rep.snapshot_contents[:last] - source = @rep.binary? ? last.filename : last.string + last = @compilation_context.snapshot_repo.get(@rep, :last) + source = last.binary? ? last.filename : last.string filter_args.freeze result = filter.setup_and_run(source, filter_args) - @rep.snapshot_contents[:last] = + last = if filter.class.to_binary? Nanoc::Int::BinaryContent.new(filter.output_filename).tap(&:freeze) else Nanoc::Int::TextualContent.new(result).tap(&:freeze) end + # Store + @compilation_context.snapshot_repo.set(@rep, :last, last) + # Check whether file was written if filter.class.to_binary? && !File.file?(filter.output_filename) raise OutputNotWrittenError.new(filter_name, filter.output_filename) end ensure @@ -48,11 +51,12 @@ end filter_args = filter_args.merge(extra_filter_args || {}) filter_args.freeze # Check whether item can be laid out - raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(@rep) if @rep.binary? + last = @compilation_context.snapshot_repo.get(@rep, :last) + raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(@rep) if last.binary? # Create filter klass = Nanoc::Filter.named(filter_name) raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil? view_context = @compilation_context.create_view_context(@dependency_tracker) @@ -67,18 +71,22 @@ # Layout content = layout.content arg = content.binary? ? content.filename : content.string res = filter.setup_and_run(arg, filter_args) - @rep.snapshot_contents[:last] = Nanoc::Int::TextualContent.new(res).tap(&:freeze) + + # Store + last = Nanoc::Int::TextualContent.new(res).tap(&:freeze) + @compilation_context.snapshot_repo.set(@rep, :last, last) ensure Nanoc::Int::NotificationCenter.post(:filtering_ended, @rep, filter_name) end end def snapshot(snapshot_name) - @rep.snapshot_contents[snapshot_name] = @rep.snapshot_contents[:last] + last = @compilation_context.snapshot_repo.get(@rep, :last) + @compilation_context.snapshot_repo.set(@rep, snapshot_name, last) end def assigns_for(rep) @compilation_context.assigns_for(rep, @dependency_tracker) end @@ -103,12 +111,13 @@ 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? + last = @compilation_context.snapshot_repo.get(@rep, :last) + if klass.from_binary? && !last.binary? raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(rep, klass) - elsif !klass.from_binary? && rep.binary? + elsif !klass.from_binary? && last.binary? raise Nanoc::Int::Errors::CannotUseTextualFilter.new(rep, klass) end klass.new(assigns_for(rep)) end