Class: Nanoc3::Site

### Home Classes Methods

### In Files

- lib/nanoc3/base/site.rb

### Parent

Object

### Methods

- ::new
- #code_snippets
- #compiler
- #data_sources
- #items
- #layouts
- #load_data

### 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::Site

The in-memory representation of a nanoc site. It holds references to the following site data:

- {items} - the list of items ({Nanoc3::Item})

- {layouts} - the list of layouts ({Nanoc3::Layout})

- {code_snippets} - the list of code snippets ({Nanoc3::CodeSnippet})

In addition, each site has a {config} hash which stores the site configuration.

A site also has several helper classes:

- {data_sources} (array of {Nanoc3::DataSource}) - A list of data sources that are used for loading site data

- {compiler} ({Nanoc3::Compiler}) - The compiler that is used for compiling items and their representations

The physical representation of a {Nanoc3::Site} is usually a directory that contains a configuration file, site data, a rakefile, a rules file, etc. The way site data is stored depends on the data source.

### Constants

DEFAULT_CONFIG

  The default configuration for a site. A site’s configuration overrides these options: when a {Nanoc3::Site} is created with a configuration that lacks some options, the default value will be taken from `DEFAULT_CONFIG`.

DEFAULT_DATA_SOURCE_CONFIG

  The default configuration for a data source. A data source’s configuration overrides these options.

### Attributes

config[R]

The site configuration. The configuration has the following keys:

- `text_extensions` ({Array<String>}) - A list of file extensions that will cause nanoc to threat the file as textual instead of binary. When the data source finds a content file with an extension that is included in this list, it will be marked as textual.

- `output_dir` ({String}) - The directory to which compiled items will be written. This path is relative to the current working directory, but can also be an absolute path.

- `data_sources` ({Array<Hash>}) - A list of data sources for this site. See below for documentation on the structure of this list. By default, there is only one data source of the filesystem type mounted at `/`.

- `index_filenames` ({Array<String>}) - A list of filenames that will be stripped off full item paths to create cleaner URLs. For example, `/about/` will be used instead of `/about/index.html`). The default value should be okay in most cases.

- `enable_output_diff` ({Boolean}) - True when diffs should be generated for the compiled content of this site; false otherwise.

The list of data sources consists of hashes with the following keys:

- `:type` ({String}) - The type of data source, i.e. its identifier.

- `:items_root` ({String}) - The prefix that should be given to all items returned by the {items} method (comparable to mount points for filesystems in Unix-ish OSes).

- `:layouts_root` ({String}) - The prefix that should be given to all layouts returned by the {layouts} method (comparable to mount points for filesystems in Unix-ish OSes).

- `:config` ({Hash}) - A hash containing the configuration for this data source. nanoc itself does not use this hash. This is especially useful for online data sources; for example, a Twitter data source would need the username of the account from which to fetch tweets.

@return [Hash] The site configuration

config_mtime[R]

@return [Time] The timestamp when the site configuration was last modified

preprocessor[RW]

@return [Proc] The code block that will be executed after all data is loaded but before the site is compiled

rules_mtime[R]

@return [Time] The timestamp when the rules were last modified

### Public Class Methods

new(dir_or_config_hash) click to toggle source

Creates a site object for the site specified by the given `dir_or_config_hash` argument.

@param [Hash, String] dir_or_config_hash If a string, contains the path to the site directory; if a hash, contains the site configuration.

    # File lib/nanoc3/base/site.rb, line 107
    def initialize(dir_or_config_hash)
      build_config(dir_or_config_hash)

      @code_snippets_loaded = false
      @items_loaded         = false
      @layouts_loaded       = false
    end

### Public Instance Methods

code_snippets() click to toggle source

Returns this site’s code snippets.

@return [Array<Nanoc3::CodeSnippet>] The list of code snippets in this site

@raise [Nanoc3::Errors::DataNotYetAvailable] if the site data hasn’t been loaded yet (call {load_data} to load the site data)

    # File lib/nanoc3/base/site.rb, line 198
    def code_snippets
      raise Nanoc3::Errors::DataNotYetAvailable.new('Code snippets', false) unless @code_snippets_loaded
      @code_snippets
    end

compiler() click to toggle source

Returns the compiler for this site. Will create a new compiler if none exists yet.

@return [Nanoc3::Compiler] The compiler for this site

    # File lib/nanoc3/base/site.rb, line 119
    def compiler
      @compiler ||= Compiler.new(self)
    end

data_sources() click to toggle source

Returns the data sources for this site. Will create a new data source if none exists yet.

@return [Array<Nanoc3::DataSource>] The list of data sources for this site

@raise [Nanoc3::Errors::UnknownDataSource] if the site configuration specifies an unknown data source

    # File lib/nanoc3/base/site.rb, line 131
    def data_sources
      @data_sources ||= begin
        @config[:data_sources].map do |data_source_hash|
          # Get data source class
          data_source_class = Nanoc3::DataSource.named(data_source_hash[:type])
          raise Nanoc3::Errors::UnknownDataSource.new(data_source_hash[:type]) if data_source_class.nil?

          # Warn about deprecated data sources
          # TODO [in nanoc 4.0] remove me
          case data_source_hash[:type]
            when 'filesystem'
              warn "Warning: the 'filesystem' data source has been renamed to 'filesystem_verbose'. Using 'filesystem' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem' with 'filesystem_verbose'."
            when 'filesystem_combined', 'filesystem_compact'
              warn "Warning: the 'filesystem_combined' and 'filesystem_compact' data source has been merged into the new 'filesystem_unified' data source. Using 'filesystem_combined' and 'filesystem_compact' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem_combined' and 'filesystem_compact with 'filesystem_unified'."
          end

          # Create data source
          data_source_class.new(
            self,
            data_source_hash[:items_root],
            data_source_hash[:layouts_root],
            data_source_hash[:config] || {}
          )
        end
      end
    end

items() click to toggle source

Returns this site’s items.

@return [Array<Nanoc3::Item>] The list of items in this site

@raise [Nanoc3::Errors::DataNotYetAvailable] if the site data hasn’t been loaded yet (call {load_data} to load the site data)

    # File lib/nanoc3/base/site.rb, line 209
    def items
      raise Nanoc3::Errors::DataNotYetAvailable.new('Items', true) unless @items_loaded
      @items
    end

layouts() click to toggle source

Returns this site’s layouts.

@return [Array<Nanoc3::Layouts>] The list of layout in this site

@raise [Nanoc3::Errors::DataNotYetAvailable] if the site data hasn’t been loaded yet (call {load_data} to load the site data)

    # File lib/nanoc3/base/site.rb, line 220
    def layouts
      raise Nanoc3::Errors::DataNotYetAvailable.new('Layouts', true) unless @layouts_loaded
      @layouts
    end

load_data(force=false) click to toggle source

Loads the site data. This will query the {Nanoc3::DataSource} associated with the site and fetch all site data. The site data is cached, so calling this method will not have any effect the second time, unless the `force` parameter is true.

@param [Boolean] force If true, will force load the site data even if it has been loaded before, to circumvent caching issues

@return [void]

    # File lib/nanoc3/base/site.rb, line 167
    def load_data(force=false)
      # Don't load data twice
      return if instance_variable_defined?(:@data_loaded) && @data_loaded && !force

      # Load all data
      load_code_snippets(force)
      data_sources.each { |ds| ds.use }
      load_rules
      load_items
      load_layouts
      data_sources.each { |ds| ds.unuse }

      # Preprocess
      setup_child_parent_links
      preprocessor_context.instance_eval(&preprocessor) unless preprocessor.nil?
      link_everything_to_site
      setup_child_parent_links
      build_reps
      route_reps

      # Done
      @data_loaded = true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.