Responsible for compiling a site’s item representations.
The list of compilation rules that will be used to compile items. This array will be filled by {Nanoc3::Site#load_data}.
@return [Array<Nanoc3::Rule>] The list of item compilation rules
The list of routing rules that will be used to give all items a path. This array will be filled by {Nanoc3::Site#load_data}.
@return [Array<Nanoc3::Rule>] The list of item routing rules
Creates a new compiler fo the given site
@param [Nanoc3::Site] site The site this compiler belongs to
# File lib/nanoc3/base/compiler.rb, line 35 def initialize(site) @site = site @stack = [] @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end
Finds the first matching compilation rule for the given item representation.
@param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule
@return [Nanoc3::Rule, nil] The compilation rule for the given item rep, or nil if no rules have been found
# File lib/nanoc3/base/compiler.rb, line 98 def compilation_rule_for(rep) @item_compilation_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end
Finds the filter name and arguments to use for the given layout.
@param [Nanoc3::Layout] layout The layout for which to fetch the filter.
@return [Array, nil] A tuple containing the filter name and the filter arguments for the given layout.
# File lib/nanoc3/base/compiler.rb, line 122 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
Finds the first matching routing rule for the given item representation.
@param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule
@return [Nanoc3::Rule, nil] The routing rule for the given item rep, or nil if no rules have been found
# File lib/nanoc3/base/compiler.rb, line 110 def routing_rule_for(rep) @item_routing_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end
Compiles (part of) the site and writes out the compiled item representations.
@param [Nanoc3::Item] item The item that should be compiled, along with its dependencies. Pass `nil` if the entire site should be compiled.
@option params [Boolean] :force (false) true if the rep should be compiled even if it is not outdated, false if not
@return [void]
# File lib/nanoc3/base/compiler.rb, line 55 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
Generated with the Darkfish Rdoc Generator 2.