lib/nanoc/base/entities/item_rep.rb in nanoc-4.4.4 vs lib/nanoc/base/entities/item_rep.rb in nanoc-4.4.5

- old
+ new

@@ -40,11 +40,11 @@ # Set default attributes @raw_paths = {} @paths = {} @snapshot_defs = [] - initialize_content + @snapshot_contents = { last: @item.content } # Reset flags @compiled = false end @@ -62,49 +62,49 @@ # any). # # @return [String] The compiled content at the given snapshot (or the # default snapshot if no snapshot is specified) def compiled_content(snapshot: nil) - # Make sure we're not binary - if binary? - raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self) - end - # Get name of last pre-layout snapshot snapshot_name = snapshot || (@snapshot_contents[:pre] ? :pre : :last) - is_moving = [:pre, :post, :last].include?(snapshot_name) + is_movable = [:pre, :post, :last].include?(snapshot_name) # Check existance of snapshot snapshot_def = snapshot_defs.reverse.find { |sd| sd.name == snapshot_name } - if !is_moving && (snapshot_def.nil? || !snapshot_def.final?) + is_final = snapshot_def && snapshot_def.final? + if !is_movable && !is_final raise Nanoc::Int::Errors::NoSuchSnapshot.new(self, snapshot_name) end # Verify snapshot is usable is_still_moving = case snapshot_name when :post, :last true when :pre - snapshot_def.nil? || !snapshot_def.final? + !is_final end is_usable_snapshot = @snapshot_contents[snapshot_name] && (compiled? || !is_still_moving) unless is_usable_snapshot Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(self)) return compiled_content(snapshot: snapshot) end - @snapshot_contents[snapshot_name].string + # Verify snapshot is not binary + snapshot_content = @snapshot_contents[snapshot_name] + if snapshot_content.binary? + raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self) + end + + snapshot_content.string end contract Symbol => C::Bool # Checks whether content exists at a given snapshot. # # @return [Boolean] True if content exists for the snapshot with the # given name, false otherwise - # - # @since 3.2.0 def snapshot?(snapshot_name) !@snapshot_contents[snapshot_name].nil? end alias has_snapshot? snapshot? @@ -143,14 +143,8 @@ [:item_rep, item.identifier, name] end def inspect "<#{self.class} name=\"#{name}\" binary=#{binary?} raw_path=\"#{raw_path}\" item.identifier=\"#{item.identifier}\">" - end - - private - - def initialize_content - @snapshot_contents = { last: @item.content } end end end