Class: Nanoc3::Item

### Home Classes Methods

### In Files

- lib/nanoc3/base/item.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #binary?
- #compiled_content
- #inspect
- #outdated?
- #path
- #rep_named

### Files

- ChangeLog
- LICENSE

### Class/Module Index

Quicksearch

- Nanoc3
- Nanoc3::ArrayExtensions
- Nanoc3::CLI
- Nanoc3::CLI::Base
- Nanoc3::CLI::Commands
- Nanoc3::CLI::Commands::Autocompile
- Nanoc3::CLI::Commands::Compile
- Nanoc3::CLI::Commands::CreateItem
- Nanoc3::CLI::Commands::CreateLayout
- Nanoc3::CLI::Commands::CreateSite
- Nanoc3::CLI::Commands::Debug
- Nanoc3::CLI::Commands::Help
- Nanoc3::CLI::Commands::Info
- Nanoc3::CLI::Commands::Update
- Nanoc3::CLI::Commands::View
- Nanoc3::CLI::Logger
- Nanoc3::CodeSnippet
- Nanoc3::Compiler
- Nanoc3::CompilerDSL
- Nanoc3::Context
- Nanoc3::DataSource
- Nanoc3::DataSources
- Nanoc3::DataSources::Delicious
- Nanoc3::DataSources::Filesystem
- Nanoc3::DataSources::FilesystemUnified
- Nanoc3::DataSources::FilesystemVerbose
- Nanoc3::DataSources::LastFM
- Nanoc3::DataSources::Twitter
- Nanoc3::DependencyTracker
- Nanoc3::DirectedGraph
- Nanoc3::Errors
- Nanoc3::Errors::CannotDetermineFilter
- Nanoc3::Errors::CannotLayoutBinaryItem
- Nanoc3::Errors::CannotUseBinaryFilter
- Nanoc3::Errors::CannotUseTextualFilter
- Nanoc3::Errors::DataNotYetAvailable
- Nanoc3::Errors::Generic
- Nanoc3::Errors::NoMatchingCompilationRuleFound
- Nanoc3::Errors::NoMatchingRoutingRuleFound
- Nanoc3::Errors::NoRulesFileFound
- Nanoc3::Errors::RecursiveCompilation
- Nanoc3::Errors::UnknownDataSource
- Nanoc3::Errors::UnknownFilter
- Nanoc3::Errors::UnknownLayout
- Nanoc3::Errors::UnmetDependency
- Nanoc3::Extra
- Nanoc3::Extra::AutoCompiler
- Nanoc3::Extra::CHiCk
- Nanoc3::Extra::CHiCk::CacheController
- Nanoc3::Extra::CHiCk::Client
- Nanoc3::Extra::CHiCk::RackClient
- Nanoc3::Extra::Deployers
- Nanoc3::Extra::Deployers::Rsync
- Nanoc3::Extra::FileProxy
- Nanoc3::Extra::TimeExtensions
- Nanoc3::Extra::VCS
- Nanoc3::Extra::VCSes
- Nanoc3::Extra::VCSes::Bazaar
- Nanoc3::Extra::VCSes::Dummy
- Nanoc3::Extra::VCSes::Git
- Nanoc3::Extra::VCSes::Mercurial
- Nanoc3::Extra::VCSes::Subversion
- Nanoc3::Extra::Validators
- Nanoc3::Extra::Validators::Links
- Nanoc3::Extra::Validators::Links::EachPairEnumerator
- Nanoc3::Extra::Validators::W3C
- Nanoc3::Filter
- Nanoc3::Filters
- Nanoc3::Filters::BlueCloth
- Nanoc3::Filters::CodeRay
- Nanoc3::Filters::ColorizeSyntax
- Nanoc3::Filters::ERB
- Nanoc3::Filters::Erubis
- Nanoc3::Filters::Haml
- Nanoc3::Filters::Kramdown
- Nanoc3::Filters::Less
- Nanoc3::Filters::Markaby
- Nanoc3::Filters::Maruku
- Nanoc3::Filters::RDiscount
- Nanoc3::Filters::RDoc
- Nanoc3::Filters::Rainpress
- Nanoc3::Filters::RedCloth
- Nanoc3::Filters::RelativizePaths
- Nanoc3::Filters::RubyPants
- Nanoc3::Filters::Sass
- Nanoc3::HashExtensions
- Nanoc3::Helpers
- Nanoc3::Helpers::Blogging
- Nanoc3::Helpers::Breadcrumbs
- Nanoc3::Helpers::Capturing
- Nanoc3::Helpers::Filtering
- Nanoc3::Helpers::HTMLEscape
- Nanoc3::Helpers::LinkTo
- Nanoc3::Helpers::Rendering
- Nanoc3::Helpers::Tagging
- Nanoc3::Helpers::Text
- Nanoc3::Helpers::XMLSitemap
- Nanoc3::Item
- Nanoc3::ItemRep
- Nanoc3::Layout
- Nanoc3::NotificationCenter
- Nanoc3::PluginRegistry
- Nanoc3::PluginRegistry::PluginMethods
- Nanoc3::Rule
- Nanoc3::RuleContext
- Nanoc3::Site
- Nanoc3::StringExtensions
- Nanoc3::Tasks
- Nanoc3::Tasks::Clean
- Array
- Enumerable
- Hash
- Object
- OrderedHash
- String
- Time

No matching classes.

# Nanoc3::Item

Represents a compileable item in a site. It has content and attributes, as well as an identifier (which starts and ends with a slash). It can also store the modification time to speed up compilation.

### Attributes

attributes[RW]

@return [Hash] This item’s attributes

children[RW]

@return [Array<Nanoc3::Item>] The child items of this item

identifier[RW]

@return [String] This item’s identifier

mtime[R]

@return [Time] The time when this item was last modified

outdated_due_to_dependencies[RW]

@return [Boolean] Whether or not this item is outdated because of its dependencies are outdated

outdated_due_to_dependencies?[RW]

@return [Boolean] Whether or not this item is outdated because of its dependencies are outdated

parent[RW]

@return [Nanoc3::Item, nil] The parent item of this item. This can be nil even for non-root items.

raw_content[R]

@return [String] This item’s raw, uncompiled content of this item (only available for textual items)

raw_filename[R]

@return [String] The filename pointing to the file containing this item’s content (only available for binary items)

reps[R]

@return [Array<Nanoc3::ItemRep>] This item’s list of item reps

site[RW]

@return [Nanoc3::Site] The site this item belongs to

### Public Class Methods

new(raw_content_or_raw_filename, attributes, identifier, params_or_mtime=nil) click to toggle source

Creates a new item with the given content or filename, attributes and identifier.

Note that the API in 3.1 has changed a bit since 3.0; the API remains backwards compatible, however. Passing the modification time as the 4th parameter is deprecated; pass it as the `:mtime` method option instead.

@param [String] raw_content_or_raw_filename The uncompiled item content (if it is a textual item) or the path to the filename containing the content (if it is a binary item).

@param [Hash] attributes A hash containing this item’s attributes.

@param [String] identifier This item’s identifier.

@param [Time, Hash, nil] params_or_mtime Extra parameters for the item, or the time when this item was last modified (deprecated).

@option params_or_mtime [Time, nil] :mtime (nil) The time when this item was last modified

@option params_or_mtime [Symbol, nil] :binary (true) Whether or not this item is binary

    # File lib/nanoc3/base/item.rb, line 67
    def initialize(raw_content_or_raw_filename, attributes, identifier, params_or_mtime=nil)
      # Get params and mtime
      # TODO [in nanoc 4.0] clean this up
      if params_or_mtime.nil? || params_or_mtime.is_a?(Time)
        params = {}
        @mtime = params_or_mtime
      elsif params_or_mtime.is_a?(Hash)
        params = params_or_mtime
        @mtime = params[:mtime]
      end

      # Get type and raw content or raw filename
      @is_binary = params.has_key?(:binary) ? params[:binary] : false
      if @is_binary
        @raw_filename = raw_content_or_raw_filename
      else
        @raw_content  = raw_content_or_raw_filename
      end

      # Get rest of params
      @attributes   = attributes.symbolize_keys
      @identifier   = identifier.cleaned_identifier

      @parent       = nil
      @children     = []

      @reps         = []
    end

### Public Instance Methods

[](key) click to toggle source

Requests the attribute with the given key.

@param [Symbol] key The name of the attribute to fetch

@return [Object] The value of the requested attribute

    # File lib/nanoc3/base/item.rb, line 164
    def [](key)
      Nanoc3::NotificationCenter.post(:visit_started, self)
      Nanoc3::NotificationCenter.post(:visit_ended,   self)

      @attributes[key]
    end

[]=(key, value) click to toggle source

Sets the attribute with the given key to the given value.

@param [Symbol] key The name of the attribute to set

@param [Object] value The value of the attribute to set

    # File lib/nanoc3/base/item.rb, line 176
    def []=(key, value)
      @attributes[key] = value
    end

binary?() click to toggle source

@return [Boolean] True if the item is binary; false if it is not

    # File lib/nanoc3/base/item.rb, line 181
    def binary?
      !!@is_binary
    end

compiled_content(params={}) click to toggle source

Returns the compiled content from a given representation and a given snapshot. This is a convenience method that makes fetching compiled content easier.

@option params [String] :rep (:default) The name of the representation from which the compiled content should be fetched. By default, the compiled content will be fetched from the default representation.

@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 of the given rep (or the default rep if no rep is specified) at the given snapshot (or the default snapshot if no snapshot is specified)

@see ItemRep#compiled_content

    # File lib/nanoc3/base/item.rb, line 123
    def compiled_content(params={})
      # Get rep
      rep_name = params[:rep] || :default
      rep = reps.find { |r| r.name == rep_name }
      if rep.nil?
        raise Nanoc3::Errors::Generic,
          "No rep named #{rep_name.inspect} was found."
      end

      # Get rep's content
      rep.compiled_content(params)
    end

inspect() click to toggle source

    # File lib/nanoc3/base/item.rb, line 193
    def inspect
      "<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier} binary?=#{self.binary?}>"
    end

outdated?() click to toggle source

Determines whether this item (or rather, its reps) is outdated and should be recompiled (or rather, its reps should be recompiled).

@return [Boolean] true if any reps are outdated; false otherwise.

    # File lib/nanoc3/base/item.rb, line 189
    def outdated?
      @reps.any? { |r| r.outdated? }
    end

path(params={}) click to toggle source

Returns the path from a given representation. This is a convenience method that makes fetching the path of a rep easier.

@option params [String] :rep (:default) The name of the representation from which the path should be fetched. By default, the path will be fetched from the default representation.

@return [String] The path of the given rep ( or the default rep if no rep is specified)

    # File lib/nanoc3/base/item.rb, line 145
    def path(params={})
      rep_name = params[:rep] || :default

      # Get rep
      rep = reps.find { |r| r.name == rep_name }
      if rep.nil?
        raise Nanoc3::Errors::Generic,
          "No rep named #{rep_name.inspect} was found."
      end

      # Get rep's path
      rep.path
    end

rep_named(rep_name) click to toggle source

Returns the rep with the given name.

@param [Symbol] rep_name The name of the representation to return

@return [Nanoc3::ItemRep] The representation with the given name

    # File lib/nanoc3/base/item.rb, line 101
    def rep_named(rep_name)
      @reps.find { |r| r.name == rep_name }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.