lib/nanoc/base/compilation/compiler.rb in nanoc-4.4.1 vs lib/nanoc/base/compilation/compiler.rb in nanoc-4.4.2

- old
+ new

@@ -14,30 +14,15 @@ # # * `compilation_ended` — indicates that the compiler has finished compiling # this item representation (either successfully or with failure). Has one # argument: the item representation itself. # - # * `processing_started` — indicates that the compiler has started - # processing the specified object, which can be an item representation - # (when it is compiled) or a layout (when it is used to lay out an item - # representation or when it is used as a partial) - # - # * `processing_ended` — indicates that the compiler has finished processing - # the specified object. - # # @api private class Compiler # @api private attr_reader :site - # 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. - # - # @return [Array] The compilation stack - attr_reader :stack - # @api private attr_reader :compiled_content_cache # @api private attr_reader :checksum_store @@ -65,12 +50,10 @@ @rule_memory_store = rule_memory_store @dependency_store = dependency_store @outdatedness_checker = outdatedness_checker @reps = reps @action_provider = action_provider - - @stack = [] end def run_all @action_provider.preprocess(@site) build_reps @@ -84,11 +67,10 @@ @site.freeze # Determine which reps need to be recompiled forget_dependencies_if_outdated - @stack = [] compile_reps store ensure Nanoc::Int::TempFilenameFactory.instance.cleanup( Nanoc::Filter::TMP_BINARY_ITEMS_DIR, @@ -192,31 +174,29 @@ def prune_config_exclude prune_config[:exclude] || {} end def compile_reps - # Listen to processing start/stop - Nanoc::Int::NotificationCenter.on(:processing_started, self) { |obj| @stack.push(obj) } - Nanoc::Int::NotificationCenter.on(:processing_ended, self) { |_obj| @stack.pop } - # Assign snapshots @reps.each do |rep| rep.snapshot_defs = action_provider.snapshots_defs_for(rep) end # Find item reps to compile and compile them outdated_reps = @reps.select { |r| outdatedness_checker.outdated?(r) } selector = Nanoc::Int::ItemRepSelector.new(outdated_reps) selector.each do |rep| - @stack = [] - compile_rep(rep) + handle_errors_while(rep) { compile_rep(rep) } end - ensure - Nanoc::Int::NotificationCenter.remove(:processing_started, self) - Nanoc::Int::NotificationCenter.remove(:processing_ended, self) end + def handle_errors_while(item_rep) + yield + rescue => e + raise Nanoc::Int::Errors::CompilationError.new(e, item_rep) + end + # Compiles the given item representation. # # This method should not be called directly; please use # {Nanoc::Int::Compiler#run} instead, and pass this item representation's item # as its first argument. @@ -248,22 +228,24 @@ end end fiber = @fibers[rep] while fiber.alive? - Nanoc::Int::NotificationCenter.post(:processing_started, rep) Nanoc::Int::NotificationCenter.post(:compilation_started, rep) res = fiber.resume - if res.is_a?(Nanoc::Int::Errors::UnmetDependency) + case res + when Nanoc::Int::Errors::UnmetDependency Nanoc::Int::NotificationCenter.post(:compilation_suspended, rep, res) - Nanoc::Int::NotificationCenter.post(:processing_ended, rep) raise(res) + when Proc + fiber.resume(res.call) + else + # TODO: raise end end Nanoc::Int::NotificationCenter.post(:compilation_ended, rep) - Nanoc::Int::NotificationCenter.post(:processing_ended, rep) end # @return [Boolean] def can_reuse_content_for_rep?(rep) !outdatedness_checker.outdated?(rep) && compiled_content_cache[rep]