Class: Nanoc3::CompilerDSL
Nanoc3::CompilerDSL contains methods that will be executed by the site’s rules file.
Constructor Summary
Creates a new compiler DSL for the given compiler.
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
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
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
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
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
Creates a preprocessor block that will be executed after all data is loaded, but before the site is compiled.
16 17 18 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 16 def preprocess(&block) @site.preprocessor = block end |
route
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
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 |