Class: Nanoc3::CompilerDSL

### Home Classes Methods

### In Files

- lib/nanoc3/base/compiler_dsl.rb

### Parent

Object

### Methods

- ::new
- #compile
- #layout
- #preprocess
- #route

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

Contains methods that will be executed by the site’s `Rules` file.

### Public Class Methods

new(site) click to toggle source

Creates a new compiler DSL for the given compiler.

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

    # File lib/nanoc3/base/compiler_dsl.rb, line 10
    def initialize(site)
      @site = site
    end

### Public Instance Methods

compile(identifier, params={}, &block) click to toggle source

Creates a compilation rule for all items whose identifier match the given identifier, which may either be a string containing the * wildcard, or a regular expression.

This rule will be applicable to reps with a name equal to `:default`; this can be changed by giving an explicit `:rep` parameter.

An item rep will be compiled by calling the given block and passing the rep as a block argument.

@param [String] identifier A pattern matching identifiers of items that should be compiled using this rule

@option params [Symbol] :rep (:default) The name of the representation that should be compiled using this rule

@yield The block that will be executed when an item matching this compilation rule needs to be compiled

@return [void]

@example Compiling the default rep of the `/foo/` item

    compile '/foo/' do
      rep.filter :erb
    end

@example Compiling the `:raw` rep of the `/bar/` item

    compile '/bar/', :rep => :raw do
      # do nothing
    end

    # File lib/nanoc3/base/compiler_dsl.rb, line 56
    def compile(identifier, params={}, &block)
      # Require block
      raise ArgumentError.new("#compile requires a block") unless block_given?

      # Get rep name
      rep_name = params[:rep] || :default

      # Create rule
      rule = Rule.new(identifier_to_regex(identifier), rep_name, block)
      @site.compiler.item_compilation_rules << rule
    end

layout(identifier, filter_name, params={}) click to toggle source

Creates a layout rule for all layouts whose identifier match the given identifier, which may either be a string containing the * wildcard, or a regular expression. The layouts matching the identifier will be filtered using the filter specified in the second argument. The params hash contains filter arguments that will be passed to the filter.

@param [String] identifier A pattern matching identifiers of layouts that should be filtered using this rule

@param [Symbol] filter_name The name of the filter that should be run when processing the layout

@param [Hash] params Extra filter arguments that should be passed to the filter when processing the layout (see {Nanoc3::Filter#run})

@return [void]

@example Specifying the filter to use for a layout

    layout '/default/', :erb

@example Using custom filter arguments for a layout

    layout '/custom/',  :haml, :format => :html5

    # File lib/nanoc3/base/compiler_dsl.rb, line 136
    def layout(identifier, filter_name, params={})
      @site.compiler.layout_filter_mapping[identifier_to_regex(identifier)] = [ filter_name, params ]
    end

preprocess(&block) click to toggle source

Creates a preprocessor block that will be executed after all data is loaded, but before the site is compiled.

@yield The block that will be executed before site compilation starts

@return [void]

    # File lib/nanoc3/base/compiler_dsl.rb, line 20
    def preprocess(&block)
      @site.preprocessor = block
    end

route(identifier, params={}, &block) click to toggle source

Creates a routing rule for all items whose identifier match the given identifier, which may either be a string containing the `*` wildcard, or a regular expression.

This rule will be applicable to reps with a name equal to `:default`; this can be changed by giving an explicit `:rep` parameter.

The path of an item rep will be determined by calling the given block and passing the rep as a block argument.

@param [String] identifier A pattern matching identifiers of items that should be routed using this rule

@option params [Symbol] :rep (:default) The name of the representation that should be routed using this rule

@yield The block that will be executed when an item matching this compilation rule needs to be routed

@return [void]

@example Routing the default rep of the `/foo/` item

    route '/foo/' do
      item.identifier + 'index.html'
    end

@example Routing the `:raw` rep of the `/bar/` item

    route '/bar/', :rep => :raw do
      '/raw' + item.identifier + 'index.txt'
    end

    # File lib/nanoc3/base/compiler_dsl.rb, line 100
    def route(identifier, params={}, &block)
      # Require block
      raise ArgumentError.new("#route requires a block") unless block_given?

      # Get rep name
      rep_name = params[:rep] || :default

      # Create rule
      rule = Rule.new(identifier_to_regex(identifier), rep_name, block)
      @site.compiler.item_routing_rules << rule
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.