lib/nanoc/helpers/capturing.rb in nanoc-3.8.0 vs lib/nanoc/helpers/capturing.rb in nanoc-4.0.0a1

- old
+ new

@@ -24,17 +24,10 @@ # # <div id="sidebar"> # <h3>Summary</h3> # <%= content_for(@item, :summary) || '(no summary)' %> # </div> - # - # @example Showing captured content in a sidebar the old, deprecated way (do not use or I will become very angry) - # - # <div id="sidebar"> - # <h3>Summary</h3> - # <%= @item[:content_for_summary] || '(no summary)' %> - # </div> module Capturing # @api private class CapturesStore def initialize @store = {} @@ -49,11 +42,11 @@ @store[item.identifier] ||= {} @store[item.identifier][name] end end - class ::Nanoc::Site + class ::Nanoc::Int::Site # @api private def captures_store @captures_store ||= CapturesStore.new end @@ -69,26 +62,21 @@ # Captures the content inside the block and stores it so that it can be # referenced later on. The same method, {#content_for}, is used for # getting the captured content as well as setting it. When capturing, # the content of the block itself will not be outputted. # - # For backwards compatibility, it is also possible to fetch the captured - # content by getting the contents of the attribute named `content_for_` - # followed by the given name. This way of accessing captures is - # deprecated. - # # @param [Symbol, String] name The base name of the attribute into which # the content should be stored # # @return [void] # # @overload content_for(item, name) # # Fetches the capture with the given name from the given item and # returns it. # - # @param [Nanoc::Item] item The item for which to get the capture + # @param [Nanoc::Int::Item] item The item for which to get the capture # # @param [Symbol, String] name The name of the capture to fetch # # @return [String] The stored captured content def content_for(*args, &block) @@ -108,17 +96,18 @@ if args.size != 2 raise ArgumentError, 'expected 2 arguments (the item ' \ "and the name of the capture) but got #{args.size} instead" end item = args[0] + item = item.unwrap if item.respond_to?(:unwrap) 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) + Nanoc::Int::NotificationCenter.post(:visit_started, item) + Nanoc::Int::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 @@ -126,10 +115,10 @@ @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 } - raise Nanoc::Errors::UnmetDependency.new(r) + raise Nanoc::Int::Errors::UnmetDependency.new(r) end end end # Get content