Class/Module Index [+]

Quicksearch

Nanoc::ItemRep::Private

Contains all private methods. Mixed into {Nanoc::ItemRep}.

Constants

TMP_TEXT_ITEMS_DIR

Attributes

assigns[RW]

@return [Hash] A hash containing the assigns that will be used in the

next filter or layout operation. The keys (symbols) will be made
available during the next operation.
compiled[RW]

@return [Boolean] true if this representation has already been

compiled during the current or last compilation session; false
otherwise

@api private

compiled?[RW]

@return [Boolean] true if this representation has already been

compiled during the current or last compilation session; false
otherwise

@api private

content[RW]

@return [Hash<Symbol,String>] A hash containing the content at all

snapshots. The keys correspond with the snapshot names, and the
values with the content.

@api private

paths[RW]

@return [Hash<Symbol,String>] A hash containing the paths for all

snapshots. The keys correspond with the snapshot names, and the
values with the path.

@api private

raw_paths[RW]

@return [Hash<Symbol,String>] A hash containing the raw paths (paths

including the path to the output directory and the filename) for all
snapshots. The keys correspond with the snapshot names, and the
values with the path.

@api private

temporary_filenames[R]

@return [Hash<Symbol,String>] A hash containing the paths to the

temporary _files_ that filters write binary content to. This is only
used when the item representation is binary. The keys correspond
with the snapshot names, and the values with the filename. When
writing the item representation, the file corresponding with the
requested snapshot (usually `:last`) will be copied from
`filenames[snapshot]` to `raw_paths[snapshot]`.

@api private

Public Instance Methods

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/result_data/item_rep.rb, line 168
def forget_progress
  initialize_content
end
temp_filename() click to toggle source
# File lib/nanoc/base/result_data/item_rep.rb, line 153
def temp_filename
  FileUtils.mkdir_p(TMP_TEXT_ITEMS_DIR)
  tempfile = Tempfile.new('', TMP_TEXT_ITEMS_DIR)
  new_filename = tempfile.path
  tempfile.close!

  File.expand_path(new_filename)
end
type() click to toggle source

Returns the type of this object. Will always return `:item_rep`, because this is an item rep. For layouts, this method returns `:layout`.

@api private

@return [Symbol] :item_rep

# File lib/nanoc/base/result_data/item_rep.rb, line 179
def type
  :item_rep
end
write(snapshot=:last) click to toggle source

Writes the item rep's compiled content to the rep's output file.

This method will send two notifications: one before writing the item representation, and one after. These notifications can be used for generating diffs, for example.

@api private

@param [Symbol, nil] snapshot The name of the snapshot to write.

@return [void]

# File lib/nanoc/base/result_data/item_rep.rb, line 120
def write(snapshot=:last)
  # Get raw path
  raw_path = self.raw_path(:snapshot => snapshot)
  return if raw_path.nil?

  # Create parent directory
  FileUtils.mkdir_p(File.dirname(raw_path))

  # Check if file will be created
  is_created = !File.file?(raw_path)

  # Notify
  Nanoc::NotificationCenter.post(:will_write_rep, self, snapshot)

  if self.binary?
    temp_path = temporary_filenames[:last]
  else
    temp_path = self.temp_filename
    File.open(temp_path, 'w') { |io| io.write(@content[:last]) }
  end

  # Check whether content was modified
  is_modified = is_created || !FileUtils.identical?(raw_path, temp_path)

  # Write
  FileUtils.cp(temp_path, raw_path) if is_modified

  # Notify
  Nanoc::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.