Class: Nanoc3::Compiler
- Inherits:
-
Object
- Object
- Nanoc3::Compiler
- Defined in:
- lib/nanoc3/base/compiler.rb
Overview
Responsible for compiling a site’s item representations.
Instance Attribute Summary (collapse)
-
- (Array<Nanoc3::Rule>) item_compilation_rules
readonly
The list of compilation rules that will be used to compile items.
-
- (Array<Nanoc3::Rule>) item_routing_rules
readonly
The list of routing rules that will be used to give all items a path.
-
- (Hash) layout_filter_mapping
readonly
The hash containing layout-to-filter mapping rules.
-
- (Array) stack
readonly
The compilation stack.
Instance Method Summary (collapse)
-
- (Nanoc3::Rule?) compilation_rule_for(rep)
Finds the first matching compilation rule for the given item representation.
-
- (Array?) filter_for_layout(layout)
Finds the filter name and arguments to use for the given layout.
-
- (Compiler) initialize(site)
constructor
Creates a new compiler fo the given site.
-
- (Nanoc3::Rule?) routing_rule_for(rep)
Finds the first matching routing rule for the given item representation.
-
- (void) run(item = nil, params = {})
Compiles (part of) the site and writes out the compiled item representations.
Constructor Details
- (Compiler) initialize(site)
Creates a new compiler fo the given site
36 37 38 39 40 41 42 43 44 |
# File 'lib/nanoc3/base/compiler.rb', line 36 def initialize(site) @site = site @stack = [] @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |
Instance Attribute Details
- (Array<Nanoc3::Rule>) item_compilation_rules (readonly)
The list of compilation rules that will be used to compile items. This array will be filled by Site#load_data.
19 20 21 |
# File 'lib/nanoc3/base/compiler.rb', line 19 def item_compilation_rules @item_compilation_rules end |
- (Array<Nanoc3::Rule>) item_routing_rules (readonly)
The list of routing rules that will be used to give all items a path. This array will be filled by Site#load_data.
25 26 27 |
# File 'lib/nanoc3/base/compiler.rb', line 25 def item_routing_rules @item_routing_rules end |
- (Hash) layout_filter_mapping (readonly)
The hash containing layout-to-filter mapping rules. This hash is ordered: iterating over the hash will happen in insertion order.
31 32 33 |
# File 'lib/nanoc3/base/compiler.rb', line 31 def layout_filter_mapping @layout_filter_mapping end |
- (Array) stack (readonly)
The compilation stack. When the compiler begins compiling a rep or a layout, it will be placed on the stack; when it is done compiling the rep or layout, it will be removed from the stack.
13 14 15 |
# File 'lib/nanoc3/base/compiler.rb', line 13 def stack @stack end |
Instance Method Details
- (Nanoc3::Rule?) compilation_rule_for(rep)
Finds the first matching compilation rule for the given item representation.
or nil if no rules have been found
99 100 101 102 103 |
# File 'lib/nanoc3/base/compiler.rb', line 99 def compilation_rule_for(rep) @item_compilation_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
- (Array?) filter_for_layout(layout)
Finds the filter name and arguments to use for the given layout.
arguments for the given layout.
123 124 125 126 127 128 |
# File 'lib/nanoc3/base/compiler.rb', line 123 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 |
- (Nanoc3::Rule?) routing_rule_for(rep)
Finds the first matching routing rule for the given item representation.
nil if no rules have been found
111 112 113 114 115 |
# File 'lib/nanoc3/base/compiler.rb', line 111 def routing_rule_for(rep) @item_routing_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
- (void) run(item = nil, params = {})
This method returns an undefined value.
Compiles (part of) the site and writes out the compiled item representations.
its dependencies. Pass nil if the entire site should be compiled.
compiled even if it is not outdated, false if not
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nanoc3/base/compiler.rb', line 56 def run(item=nil, params={}) # Create output directory if necessary FileUtils.mkdir_p(@site.config[:output_dir]) # Load dependencies dependency_tracker.load_graph # Get items and reps to compile if item items = [ item ] + dependency_tracker.successors_of(item) items.uniq! else items = @site.items end reps = items.map { |i| i.reps }.flatten # Prepare dependencies if params.has_key?(:force) && params[:force] reps.each { |r| r.force_outdated = true } else dependency_tracker.propagate_outdatedness end forget_dependencies_if_outdated(items) # Compile reps dependency_tracker.start compile_reps(reps) dependency_tracker.stop # Cleanup FileUtils.rm_rf(Nanoc3::Filter::TMP_BINARY_ITEMS_DIR) # Store dependencies dependency_tracker.store_graph end |