lib/nanoc/base/compilation/compiler.rb in nanoc-4.1.6 vs lib/nanoc/base/compilation/compiler.rb in nanoc-4.2.0b1

- old
+ new

@@ -14,22 +14,10 @@ # # * `compilation_ended` — indicates that the compiler has finished compiling # this item representation (either successfully or with failure). Has one # argument: the item representation itself. # - # * `visit_started` — indicates that the compiler requires content or - # attributes from the item representation that will be visited. Has one - # argument: the visited item identifier. This notification is used to - # track dependencies of items on other items; a `visit_started` event - # followed by another `visit_started` event indicates that the item - # corresponding to the former event will depend on the item from the - # latter event. - # - # * `visit_ended` — indicates that the compiler has finished visiting the - # item representation and that the requested attributes or content have - # been fetched (either successfully or with failure) - # # * `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) # @@ -96,14 +84,11 @@ # Determine which reps need to be recompiled forget_dependencies_if_outdated @stack = [] - dependency_tracker = Nanoc::Int::DependencyTracker.new(@dependency_store) - dependency_tracker.run do - compile_reps - end + compile_reps store ensure Nanoc::Int::TempFilenameFactory.instance.cleanup( Nanoc::Filter::TMP_BINARY_ITEMS_DIR) Nanoc::Int::TempFilenameFactory.instance.cleanup( @@ -145,34 +130,37 @@ # # @return [Hash] The assigns that should be used in the next filter/layout # operation # # @api private - def assigns_for(rep) + def assigns_for(rep, dependency_tracker) content_or_filename_assigns = if rep.binary? { filename: rep.snapshot_contents[:last].filename } else { content: rep.snapshot_contents[:last].string } end - view_context = create_view_context + view_context = create_view_context(dependency_tracker) - # TODO: Do not expose @site (necessary for captures store though…) content_or_filename_assigns.merge( item: Nanoc::ItemWithRepsView.new(rep.item, view_context), rep: Nanoc::ItemRepView.new(rep, view_context), item_rep: Nanoc::ItemRepView.new(rep, view_context), items: Nanoc::ItemCollectionWithRepsView.new(site.items, view_context), layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context), config: Nanoc::ConfigView.new(site.config, view_context), - site: Nanoc::SiteView.new(site, view_context), ) end - def create_view_context - Nanoc::ViewContext.new(reps: @reps, items: @site.items) + def create_view_context(dependency_tracker) + Nanoc::ViewContext.new( + reps: @reps, + items: @site.items, + dependency_tracker: dependency_tracker, + compiler: self, + ) end # @api private def filter_name_and_args_for_layout(layout) mem = action_provider.memory_for(layout) @@ -214,19 +202,21 @@ # # @param [Nanoc::Int::ItemRep] rep The rep that is to be compiled # # @return [void] def compile_rep(rep) + dependency_tracker = Nanoc::Int::DependencyTracker.new(@dependency_store) + Nanoc::Int::NotificationCenter.post(:compilation_started, rep) Nanoc::Int::NotificationCenter.post(:processing_started, rep) - Nanoc::Int::NotificationCenter.post(:visit_started, rep.item) + dependency_tracker.enter(rep.item) if can_reuse_content_for_rep?(rep) Nanoc::Int::NotificationCenter.post(:cached_content_used, rep) rep.snapshot_contents = compiled_content_cache[rep] else - recalculate_content_for_rep(rep) + recalculate_content_for_rep(rep, dependency_tracker) end rep.compiled = true compiled_content_cache[rep] = rep.snapshot_contents @@ -235,20 +225,20 @@ rescue => e rep.forget_progress Nanoc::Int::NotificationCenter.post(:compilation_failed, rep, e) raise e ensure - Nanoc::Int::NotificationCenter.post(:visit_ended, rep.item) + dependency_tracker.exit(rep.item) end # @return [Boolean] def can_reuse_content_for_rep?(rep) - !rep.item.forced_outdated? && !outdatedness_checker.outdated?(rep) && compiled_content_cache[rep] + !outdatedness_checker.outdated?(rep) && compiled_content_cache[rep] end # @return [void] - def recalculate_content_for_rep(rep) - executor = Nanoc::Int::Executor.new(self) + def recalculate_content_for_rep(rep, dependency_tracker) + executor = Nanoc::Int::Executor.new(self, dependency_tracker) action_provider.memory_for(rep).each do |action| case action when Nanoc::Int::RuleMemoryActions::Filter executor.filter(rep, action.filter_name, action.params)