Class | Nanoc3::ItemRep |
In: |
lib/nanoc3/base/item_rep.rb
|
Parent: | Object |
A single representation (rep) of an item ({Nanoc3::Item}). An item can have multiple representations. A representation has its own output file. A single item can therefore have multiple output files, each run through a different set of filters with a different layout.
An item representation is observable. The following events will be notified:
The compilation-related events have one parameters (the item representation); the filtering-related events have two (the item representation, and a symbol containing the filter class name).
OUTDATEDNESS_REASON_DESCRIPTIONS | = | { :no_mtime => 'No file modification time is available.', :forced => 'All pages are recompiled because of a `--force` flag given to the compilation command.', :no_raw_path => 'The routing rules do not specify a path where this item should be written to, i.e. the item representation will never be written to the output directory.', :not_written => 'This item representation has not yet been written to the output directory (but it does have a path).', :source_modified => 'The source file of this item has been modified since the last time this item representation was compiled.', :layouts_outdated => 'The source of one or more layouts has been modified since the last time this item representation was compiled.', :code_outdated => 'The code snippets in the `lib/` directory have been modified since the last time this item representation was compiled.', :config_outdated => 'The site configuration has been modified since the last time this item representation was compiled.', :rules_outdated => 'The rules file has been modified since the last time this item representation was compiled.', } | The descriptive strings for each outdatedness reason. This hash is used by the {outdatedness_reason} method. |
binary | -> | binary? |
modified | -> | modified? |
created | -> | created? |
compiled | -> | compiled? |
written | -> | written? |
binary | [R] | @return [Boolean] true if this rep is currently binary; false otherwise |
compiled | [RW] | @return [Boolean] true if this representation has already been compiled during the current or last compilation session; false otherwise |
created | [RW] | @return [Boolean] true if this rep’s output file was created during the current or last compilation session; false otherwise |
force_outdated | [RW] | @return [Boolean] true if this rep is forced to be dirty (e.g. because of the `—force` commandline option); false otherwise |
item | [R] | @return [Nanoc3::Item] The item to which this rep belongs |
modified | [RW] | @return [Boolean] true if this rep’s output file has changed since the last time it was compiled; false otherwise |
name | [R] | @return [Symbol] The representation‘s unique name |
path | [RW] | @return [String] 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. |
raw_path | [RW] | @return [String] The item rep‘s raw path. It is relative to the current working directory and includes the path to the output directory. It also includes the filename, even if it is an index filename. |
written | [R] | @return [Boolean] true if this representation’s compiled content has been written during the current or last compilation session; false otherwise |
Creates a new item representation for the given item.
@param [Nanoc3::Item] item The item to which the new representation will belong.
@param [Symbol] name The unique name for the new item representation.
Returns the compiled content from a given snapshot.
@option params [String] :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)
Creates and returns a diff between the compiled content before the current compilation session and the content compiled in the current compilation session.
@return [String, nil] The difference between the old and new compiled content in `diff(1)` format, or nil if there is no previous compiled content
Runs the item content through the given filter with the given arguments. This method will replace the content of the `:last` snapshot with the filtered content of the last snapshot.
This method is supposed to be called only in a compilation rule block (see {Nanoc3::CompilerDSL#compile}).
@param [Symbol] filter_name The name of the filter to run the item representations’ content through
@param [Hash] filter_args The filter arguments that should be passed to the filter‘s run method
@return [void]
Resets the compilation progress for this item representation. This is necessary when an unmet dependency is detected during compilation. This method should probably not be called directly.
@return [void]
Lays out the item using the given layout. This method will replace the content of the `:last` snapshot with the laid out content of the last snapshot.
This method is supposed to be called only in a compilation rule block (see {Nanoc3::CompilerDSL#compile}).
@param [String] layout_identifier The identifier of the layout the item should be laid out with
@return [void]
@return [Boolean] true if this item rep‘s output file is outdated and must be regenerated, false otherwise
Calculates the reason why this item representation is outdated. The output will be a hash with a `:type` key, containing the reason why the item is outdated in the form of a symbol, and a `:description` key, containing a descriptive string that can be printed if necessary.
For documentation on the types that this method can return, check the {OUTDATEDNESS_REASON_DESCRIPTIONS} hash in this class.
@return [Hash, nil] A hash containing the reason why this item rep is
outdated, both in the form of a symbol and as a descriptive string, or nil if the item representation is not outdated.