Class: Nanoc3::Compiler

### Home Classes Methods

### In Files

- lib/nanoc3/base/compiler.rb

### Parent

Object

### Methods

- ::new
- #compilation_rule_for
- #filter_for_layout
- #routing_rule_for
- #run

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

Responsible for compiling a site’s item representations.

### Attributes

item_compilation_rules[R]

The list of compilation rules that will be used to compile items. This array will be filled by {Nanoc3::Site#load_data}.

@return [Array<Nanoc3::Rule>] The list of item compilation rules

item_routing_rules[R]

The list of routing rules that will be used to give all items a path. This array will be filled by {Nanoc3::Site#load_data}.

@return [Array<Nanoc3::Rule>] The list of item routing rules

layout_filter_mapping[R]

The hash containing layout-to-filter mapping rules. This hash is ordered: iterating over the hash will happen in insertion order.

@return [Hash] The layout-to-filter mapping rules

stack[R]

The compilation stack. When the compiler begins compiling a rep or a layout, it will be placed on the stack; when it is done compiling the rep or layout, it will be removed from the stack.

@return [Array] The compilation stack

### Public Class Methods

new(site) click to toggle source

Creates a new compiler fo the given site

@param [Nanoc3::Site] site The site this compiler belongs to

    # File lib/nanoc3/base/compiler.rb, line 35
    def initialize(site)
      @site = site

      @stack = []

      @item_compilation_rules  = []
      @item_routing_rules      = []
      @layout_filter_mapping   = OrderedHash.new
    end

### Public Instance Methods

compilation_rule_for(rep) click to toggle source

Finds the first matching compilation rule for the given item representation.

@param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule

@return [Nanoc3::Rule, nil] The compilation rule for the given item rep, or nil if no rules have been found

    # File lib/nanoc3/base/compiler.rb, line 98
    def compilation_rule_for(rep)
      @item_compilation_rules.find do |rule|
        rule.applicable_to?(rep.item) && rule.rep_name == rep.name
      end
    end

filter_for_layout(layout) click to toggle source

Finds the filter name and arguments to use for the given layout.

@param [Nanoc3::Layout] layout The layout for which to fetch the filter.

@return [Array, nil] A tuple containing the filter name and the filter arguments for the given layout.

    # File lib/nanoc3/base/compiler.rb, line 122
    def filter_for_layout(layout)
      @layout_filter_mapping.each_pair do |layout_identifier, filter_name_and_args|
        return filter_name_and_args if layout.identifier =~ layout_identifier
      end
      nil
    end

routing_rule_for(rep) click to toggle source

Finds the first matching routing rule for the given item representation.

@param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule

@return [Nanoc3::Rule, nil] The routing rule for the given item rep, or nil if no rules have been found

    # File lib/nanoc3/base/compiler.rb, line 110
    def routing_rule_for(rep)
      @item_routing_rules.find do |rule|
        rule.applicable_to?(rep.item) && rule.rep_name == rep.name
      end
    end

run(item=nil, params={}) click to toggle source

Compiles (part of) the site and writes out the compiled item representations.

@param [Nanoc3::Item] item The item that should be compiled, along with its dependencies. Pass `nil` if the entire site should be compiled.

@option params [Boolean] :force (false) true if the rep should be compiled even if it is not outdated, false if not

@return [void]

    # File lib/nanoc3/base/compiler.rb, line 55
    def run(item=nil, params={})
      # Create output directory if necessary
      FileUtils.mkdir_p(@site.config[:output_dir])

      # Load dependencies
      dependency_tracker.load_graph

      # Get items and reps to compile
      if item
        items = [ item ] + dependency_tracker.successors_of(item)
        items.uniq!
      else
        items = @site.items
      end
      reps = items.map { |i| i.reps }.flatten

      # Prepare dependencies
      if params.has_key?(:force) && params[:force]
        reps.each { |r| r.force_outdated = true }
      else
        dependency_tracker.propagate_outdatedness
      end
      forget_dependencies_if_outdated(items)

      # Compile reps
      dependency_tracker.start
      compile_reps(reps)
      dependency_tracker.stop

      # Cleanup
      FileUtils.rm_rf(Nanoc3::Filter::TMP_BINARY_ITEMS_DIR)

      # Store dependencies
      dependency_tracker.store_graph
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.