Class: Nanoc3::Compiler
Nanoc3::Compiler is responsible for compiling a site’s item representations.
Attributes
Instance Attributes
| item_compilation_rules | [R] | public |
The list of compilation rules that will be used to compile items. |
|---|---|---|---|
| item_routing_rules | [R] | public |
The list of routing rules that will be used to give all items a path. |
| layout_filter_mapping | [R] | public |
The hash containing layout-to-filter mapping rules. |
| stack | [R] | public |
The compilation stack. |
Constructor Summary
Creates a new compiler for the given site.
26 27 28 29 30 31 32 33 34 |
# File 'lib/nanoc3/base/compiler.rb', line 26 def initialize(site) @site = site @stack = [] @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = {} end |
Public Visibility
Public Instance Method Summary
| #compilation_rule_for(rep) |
Returns the first matching compilation rule for the given rep. |
|---|---|
| #filter_for_layout(layout) |
Returns a tuple containing the filter name and the filter arguments for the given layout. |
| #routing_rule_for(rep) |
Returns the first matching routing rule for the given rep. |
| #run(item = nil, params = {}) |
Compiles (part of) the site and writes out the compiled item representations. |
Public Instance Method Details
compilation_rule_for
Returns the first matching compilation rule for the given rep.
78 79 80 81 82 |
# File 'lib/nanoc3/base/compiler.rb', line 78 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
Returns a tuple containing the filter name and the filter arguments for the given layout.
93 94 95 96 97 98 |
# File 'lib/nanoc3/base/compiler.rb', line 93 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
Returns the first matching routing rule for the given rep.
85 86 87 88 89 |
# File 'lib/nanoc3/base/compiler.rb', line 85 def routing_rule_for(rep) @item_routing_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
run
Compiles (part of) the site and writes out the compiled item representations.
| items: | The items that should be compiled, along with their dependencies. Pass nil if the entire site should be compiled. |
This method also accepts a few optional parameters:
| :force: | true if the rep should be compiled even if it is not outdated, false if not. Defaults to false. |
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nanoc3/base/compiler.rb', line 47 def run(item=nil, params={}) # Create output directory if necessary FileUtils.mkdir_p(@site.config[:output_dir]) # Load dependencies dependency_tracker.load_graph print_dependency_graph if $DEBUG # Get items and reps to compile if item items = [ item ] + dependency_tracker.all_inverse_dependencies_for(item) items.uniq! else items = @site.items end reps = items.map { |i| i.reps }.flatten # Prepare dependencies mark_outdated_items(reps, params.has_key?(:force) && params[:force]) forget_dependencies_if_outdated(items) # Compile reps dependency_tracker.start compile_reps(reps) dependency_tracker.stop # Store dependencies dependency_tracker.store_graph end |