Class: Nanoc3::CompilerDSL
- Inherits:
-
Object
- Object
- Nanoc3::CompilerDSL
- Defined in:
- lib/nanoc3/base/compiler_dsl.rb
Overview
Contains methods that will be executed by the site’s Rules file.
Instance Method Summary
-
- (void) compile(identifier, params = {}) { ... }
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.
-
- (CompilerDSL) initialize(site)
constructor
Creates a new compiler DSL for the given compiler.
-
- (void) 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.
-
- (void) preprocess { ... }
Creates a preprocessor block that will be executed after all data is loaded, but before the site is compiled.
-
- (void) route(identifier, params = {}) { ... }
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.
Constructor Details
- (CompilerDSL) initialize(site)
Creates a new compiler DSL for the given compiler.
11 12 13 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 11 def initialize(site) @site = site end |
Instance Method Details
- (void) compile(identifier, params = {}) { ... }
This method returns an undefined value.
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.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 57 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 |
- (void) layout(identifier, filter_name, params = {})
This method returns an undefined value.
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.
137 138 139 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 137 def layout(identifier, filter_name, params={}) @site.compiler.layout_filter_mapping[identifier_to_regex(identifier)] = [ filter_name, params ] end |
- (void) preprocess { ... }
This method returns an undefined value.
Creates a preprocessor block that will be executed after all data is loaded, but before the site is compiled.
21 22 23 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 21 def preprocess(&block) @site.preprocessor = block end |
- (void) route(identifier, params = {}) { ... }
This method returns an undefined value.
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.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/nanoc3/base/compiler_dsl.rb', line 101 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 |