lib/nanoc/base/result_data/item_rep.rb in nanoc-3.7.5 vs lib/nanoc/base/result_data/item_rep.rb in nanoc-3.8.0

- old
+ new

@@ -233,24 +233,33 @@ # Notify Nanoc::NotificationCenter.post(:visit_started, item) Nanoc::NotificationCenter.post(:visit_ended, item) # Get name of last pre-layout snapshot - snapshot = params.fetch(:snapshot) { @content[:pre] ? :pre : :last } - is_moving = [:pre, :post, :last].include?(snapshot) + snapshot_name = params.fetch(:snapshot) { @content[:pre] ? :pre : :last } + is_moving = [:pre, :post, :last].include?(snapshot_name) # Check existance of snapshot - if !is_moving && snapshots.find { |s| s.first == snapshot && s.last == true }.nil? - raise Nanoc::Errors::NoSuchSnapshot.new(self, snapshot) + snapshot = snapshots.find { |s| s.first == snapshot_name } + if !is_moving && (snapshot.nil? || snapshot[-1] == false) + raise Nanoc::Errors::NoSuchSnapshot.new(self, snapshot_name) end - # Require compilation - if @content[snapshot].nil? || (!self.compiled? && is_moving) + # Verify snapshot is usable + is_still_moving = + case snapshot_name + when :post, :last + true + when :pre + snapshot.nil? || !snapshot[-1] + end + is_usable_snapshot = @content[snapshot_name] && (self.compiled? || !is_still_moving) + unless is_usable_snapshot raise Nanoc::Errors::UnmetDependency.new(self) - else - @content[snapshot] end + + @content[snapshot_name] end # Checks whether content exists at a given snapshot. # # @return [Boolean] True if content exists for the snapshot with the @@ -414,11 +423,19 @@ # the snapshot will be updated; false if it is a non-final moving # snapshot (such as `:pre`, `:post` or `:last`) # # @return [void] def snapshot(snapshot_name, params = {}) - is_final = params.fetch(:final) { true } - @content[snapshot_name] = @content[:last] unless self.binary? + is_final = params.fetch(:final, true) + + unless self.binary? + @content[snapshot_name] = @content[:last] + end + + if snapshot_name == :pre && is_final + snapshots << [:pre, true] + end + write(snapshot_name) if is_final end # Returns a recording proxy that is used for determining whether the # compilation has changed, and thus whether the item rep needs to be