class Nanoc::Int::ItemRep

@api private

Attributes

compiled[RW]

@return [Boolean]

compiled?[RW]

@return [Boolean]

item[R]

@return [Nanoc::Int::Item]

modified[RW]

@return [Boolean]

modified?[RW]

@return [Boolean]

name[R]

@return [Symbol]

paths[RW]

@return [Hash<Symbol,String>]

raw_paths[RW]

@return [Hash<Symbol,String>]

snapshot_contents[RW]

@return [Hash<Symbol,Nanoc::Int::Content]

snapshot_defs[RW]

@return [Enumerable<Nanoc::Int:SnapshotDef]

Public Class Methods

new(item, name) click to toggle source

@param [Nanoc::Int::Item] item

@param [Symbol] name

# File lib/nanoc/base/entities/item_rep.rb, line 33
def initialize(item, name)
  # Set primary attributes
  @item   = item
  @name   = name

  # Set default attributes
  @raw_paths  = {}
  @paths      = {}
  @snapshot_defs = []
  initialize_content

  # Reset flags
  @compiled = false
end

Public Instance Methods

binary?() click to toggle source
# File lib/nanoc/base/entities/item_rep.rb, line 48
def binary?
  @snapshot_contents[:last].binary?
end
compiled_content(snapshot: nil) click to toggle source

Returns the compiled content from a given snapshot.

@param [Symbol] snapshot The name of the snapshot from which to

fetch the compiled content. By default, the returned compiled content
will be the content compiled right before the first layout call (if
any).

@return [String] The compiled content at the given snapshot (or the

default snapshot if no snapshot is specified)
# File lib/nanoc/base/entities/item_rep.rb, line 61
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)

  # Check existance of snapshot
  snapshot_def = snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
  if !is_moving && (snapshot_def.nil? || !snapshot_def.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?
    end
  is_usable_snapshot = @snapshot_contents[snapshot_name] && (compiled? || !is_still_moving)
  unless is_usable_snapshot
    raise Nanoc::Int::Errors::UnmetDependency.new(self)
  end

  @snapshot_contents[snapshot_name].string
end
forget_progress() click to toggle source

Resets the compilation progress for this item representation. This is necessary when an unmet dependency is detected during compilation.

@api private

@return [void]

# File lib/nanoc/base/entities/item_rep.rb, line 134
def forget_progress
  initialize_content
end
has_snapshot?(snapshot_name)
Alias for: snapshot?
inspect() click to toggle source
# File lib/nanoc/base/entities/item_rep.rb, line 147
def inspect
  "<#{self.class} name=\"#{name}\" binary=#{binary?} raw_path=\"#{raw_path}\" item.identifier=\"#{item.identifier}\">"
end
path(snapshot: :last) click to toggle source

Returns the item rep’s path, as used when being linked to. It starts with a slash and it is relative to the output directory. It does not include the path to the output directory. It will not include the filename if the filename is an index filename.

@param [Symbol] snapshot The snapshot for which the path should be

returned

@return [String] The item rep’s path

# File lib/nanoc/base/entities/item_rep.rb, line 124
def path(snapshot: :last)
  @paths[snapshot]
end
raw_path(snapshot: :last) click to toggle source

Returns the item rep’s raw path. It includes the path to the output directory and the full filename.

@param [Symbol] snapshot The snapshot for which the path should be

returned

@return [String] The item rep’s path

# File lib/nanoc/base/entities/item_rep.rb, line 111
def raw_path(snapshot: :last)
  @raw_paths[snapshot]
end
reference() click to toggle source

Returns an object that can be used for uniquely identifying objects.

@api private

@return [Object] An unique reference to this object

# File lib/nanoc/base/entities/item_rep.rb, line 143
def reference
  [:item_rep, item.identifier, name]
end
snapshot?(snapshot_name) click to toggle source

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

# File lib/nanoc/base/entities/item_rep.rb, line 99
def snapshot?(snapshot_name)
  !@snapshot_contents[snapshot_name].nil?
end
Also aliased as: has_snapshot?

Private Instance Methods

initialize_content() click to toggle source
# File lib/nanoc/base/entities/item_rep.rb, line 153
def initialize_content
  # FIXME: Where is :raw?
  @snapshot_contents = { last: @item.content }
end