Class: Nanoc3::CompilerDSL

Nanoc3::CompilerDSL contains methods that will be executed by the site’s rules file.

Constructor Summary

public initialize(site)

Creates a new compiler DSL for the given compiler.

[View source]


10
11
12
# File 'lib/nanoc3/base/compiler_dsl.rb', line 10

def initialize(site)
  @site = site
end

Public Visibility

Public Instance Method Summary

#compile(identifier, params = {}, &block)

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.

#layout(identifier, filter_name, params = {})

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.

#preprocess(&block)

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

#route(identifier, params = {}, &block)

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.

Public Instance Method Details

compile

public compile(identifier, params = {}, &block)

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" unless an explicit :rep parameter is given.

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

Example:

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

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

Meta Tags

Raises:

[ArgumentError]
[View source]


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nanoc3/base/compiler_dsl.rb', line 39

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

public layout(identifier, filter_name, params = {})

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.

Example:

  layout '/default/', :erb
  layout '/custom/',  :haml, :format => :html5
[View source]


92
93
94
# File 'lib/nanoc3/base/compiler_dsl.rb', line 92

def layout(identifier, filter_name, params={})
  @site.compiler.layout_filter_mapping[identifier_to_regex(identifier)] = [ filter_name, params ]
end

preprocess

public preprocess(&block)

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

[View source]


16
17
18
# File 'lib/nanoc3/base/compiler_dsl.rb', line 16

def preprocess(&block)
  @site.preprocessor = block
end

route

public route(identifier, params = {}, &block)

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 givign 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.

Example:

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

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

Meta Tags

Raises:

[ArgumentError]
[View source]


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nanoc3/base/compiler_dsl.rb', line 70

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
Generated on Sunday, August 09 2009 at 01:43:09 PM by YARD 0.2.3.2 (ruby-1.8.7).