lib/nanoc/base/compilation/compiler.rb in nanoc-4.0.0rc1 vs lib/nanoc/base/compilation/compiler.rb in nanoc-4.0.0rc2

- old
+ new

@@ -38,10 +38,16 @@ # # @api private class Compiler extend Nanoc::Int::Memoization + class IdenticalRoutesError < ::Nanoc::Error + def initialize(output_path, rep_a, rep_b) + super("The item representations #{rep_a.inspect} and #{rep_b.inspect} are both routed to #{output_path}.") + end + end + # @group Accessors # @return [Nanoc::Int::Site] The site this compiler belongs to attr_reader :site @@ -63,13 +69,13 @@ @stack = [] end # Compiles the site and writes out the compiled item representations. # - # Previous versions of nanoc (< 3.2) allowed passing items to compile, and + # Previous versions of Nanoc (< 3.2) allowed passing items to compile, and # had a “force” option to make the compiler recompile all pages, even - # when not outdated. These arguments and options are, as of nanoc 3.2, no + # when not outdated. These arguments and options are, as of Nanoc 3.2, no # longer used, and will simply be ignored when passed to {#run}. # # @overload run # @return [void] def run(*_args) @@ -213,10 +219,12 @@ # Determines the paths of all item representations. # # @api private def route_reps + paths_to_reps = {} + reps.each do |rep| # Find matching rules rules = rules_collection.routing_rules_for(rep) raise Nanoc::Int::Errors::NoMatchingRoutingRuleFound.new(rep) if rules[:last].nil? @@ -224,9 +232,16 @@ # Get basic path by applying matching rule basic_path = rule.apply_to(rep, executor: nil, compiler: self) next if basic_path.nil? if basic_path !~ %r{^/} raise "The path returned for the #{rep.inspect} item representation, “#{basic_path}”, does not start with a slash. Please ensure that all routing rules return a path that starts with a slash." + end + + # Check for duplicate paths + if paths_to_reps.key?(basic_path) + raise IdenticalRoutesError.new(basic_path, paths_to_reps[basic_path], rep) + else + paths_to_reps[basic_path] = rep end # Get raw path by prepending output directory rep.raw_paths[snapshot] = @site.config[:output_dir] + basic_path