lib/nanoc/helpers/capturing.rb in nanoc-3.3.6 vs lib/nanoc/helpers/capturing.rb in nanoc-3.3.7

- old
+ new

@@ -60,10 +60,16 @@ # @api private def captures_store @captures_store ||= CapturesStore.new end + # @api private + def captures_store_compiled_items + require 'set' + @captures_store_compiled_items ||= Set.new + end + end # @overload content_for(name, &block) # # Captures the content inside the block and stores it so that it can be @@ -109,9 +115,30 @@ raise ArgumentError, "expected 2 arguments (the item " + "and the name of the capture) but got #{args.size} instead" end item = args[0] name = args[1] + + # Create dependency + current_item = @site.compiler.dependency_tracker.top + if item != current_item + Nanoc::NotificationCenter.post(:visit_started, item) + Nanoc::NotificationCenter.post(:visit_ended, item) + + # This is an extremely ugly hack to get the compiler to recompile the + # item from which we use content. For this, we need to manually edit + # the content attribute to reset it. :( + # FIXME clean this up + if !@site.captures_store_compiled_items.include? item + @site.captures_store_compiled_items << item + item.forced_outdated = true + item.reps.each do |r| + raw_content = item.raw_content + r.content = { :raw => raw_content, :last => raw_content } + @site.compiler.send(:compile_rep, r) + end + end + end # Get content @site.captures_store[item, name.to_sym] end end