lib/nanoc/base/result_data/item_rep.rb in nanoc-3.8.0 vs lib/nanoc/base/result_data/item_rep.rb in nanoc-4.0.0a1

- old
+ new

@@ -1,62 +1,18 @@ # encoding: utf-8 -module Nanoc - # A single representation (rep) of an item ({Nanoc::Item}). An item can +module Nanoc::Int + # A single representation (rep) of an item ({Nanoc::Int::Item}). An item can # have multiple representations. A representation has its own output file. # A single item can therefore have multiple output files, each run through # a different set of filters with a different layout. + # + # @api private class ItemRep - # Contains all deprecated methods. Mixed into {Nanoc::ItemRep}. - module Deprecated - # @deprecated Modify the {#raw_paths} attribute instead - def raw_path=(raw_path) - raw_paths[:last] = raw_path - end - - # @deprecated Modify the {#paths} attribute instead - def path=(path) - paths[:last] = path - end - - # @deprecated Use {Nanoc::ItemRep#compiled_content} instead. - def content_at_snapshot(snapshot = :pre) - compiled_content(snapshot: snapshot) - end - - # @deprecated - def created - raise NotImplementedError, 'Nanoc::ItemRep#created is no longer implemented' - end - - # @deprecated - def created? - raise NotImplementedError, 'Nanoc::ItemRep#created? is no longer implemented' - end - - # @deprecated - def modified - raise NotImplementedError, 'Nanoc::ItemRep#modified is no longer implemented' - end - - # @deprecated - def modified? - raise NotImplementedError, 'Nanoc::ItemRep#modified? is no longer implemented' - end - - # @deprecated - def written - raise NotImplementedError, 'Nanoc::ItemRep#written is no longer implemented' - end - - # @deprecated - def written? - raise NotImplementedError, 'Nanoc::ItemRep#written? is no longer implemented' - end - end - - # Contains all private methods. Mixed into {Nanoc::ItemRep}. + # Contains all private methods. Mixed into {Nanoc::Int::ItemRep}. + # + # @api private module Private # @return [Hash] A hash containing the assigns that will be used in the # next filter or layout operation. The keys (symbols) will be made # available during the next operation. attr_accessor :assigns @@ -123,11 +79,11 @@ # Check if file will be created is_created = !File.file?(raw_path) # Notify - Nanoc::NotificationCenter.post(:will_write_rep, self, snapshot) + Nanoc::Int::NotificationCenter.post(:will_write_rep, self, snapshot) if self.binary? temp_path = temporary_filenames[:last] else temp_path = temp_filename @@ -139,17 +95,17 @@ # Write FileUtils.cp(temp_path, raw_path) if is_modified # Notify - Nanoc::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified) + Nanoc::Int::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified) end TMP_TEXT_ITEMS_DIR = 'text_items' def temp_filename - Nanoc::TempFilenameFactory.instance.create(TMP_TEXT_ITEMS_DIR) + Nanoc::Int::TempFilenameFactory.instance.create(TMP_TEXT_ITEMS_DIR) end # Resets the compilation progress for this item representation. This is # necessary when an unmet dependency is detected during compilation. # @@ -170,14 +126,13 @@ def type :item_rep end end - include Deprecated include Private - # @return [Nanoc::Item] The item to which this rep belongs + # @return [Nanoc::Int::Item] The item to which this rep belongs attr_reader :item # @return [Symbol] The representation's unique name attr_reader :name @@ -190,11 +145,11 @@ # a Boolean indicating whether the snapshot is final or not attr_accessor :snapshots # Creates a new item representation for the given item. # - # @param [Nanoc::Item] item The item to which the new representation will + # @param [Nanoc::Int::Item] item The item to which the new representation will # belong. # # @param [Symbol] name The unique name for the new item representation. def initialize(item, name) # Set primary attributes @@ -225,25 +180,25 @@ # @return [String] The compiled content at the given snapshot (or the # default snapshot if no snapshot is specified) def compiled_content(params = {}) # Make sure we're not binary if item.binary? - raise Nanoc::Errors::CannotGetCompiledContentOfBinaryItem.new(self) + raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self) end # Notify - 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) # Get name of last pre-layout snapshot snapshot_name = params.fetch(:snapshot) { @content[:pre] ? :pre : :last } is_moving = [:pre, :post, :last].include?(snapshot_name) # Check existance of snapshot snapshot = snapshots.find { |s| s.first == snapshot_name } if !is_moving && (snapshot.nil? || snapshot[-1] == false) - raise Nanoc::Errors::NoSuchSnapshot.new(self, snapshot_name) + raise Nanoc::Int::Errors::NoSuchSnapshot.new(self, snapshot_name) end # Verify snapshot is usable is_still_moving = case snapshot_name @@ -252,11 +207,11 @@ when :pre snapshot.nil? || !snapshot[-1] end is_usable_snapshot = @content[snapshot_name] && (self.compiled? || !is_still_moving) unless is_usable_snapshot - raise Nanoc::Errors::UnmetDependency.new(self) + raise Nanoc::Int::Errors::UnmetDependency.new(self) end @content[snapshot_name] end @@ -277,12 +232,12 @@ # @option params [Symbol] :snapshot (:last) The snapshot for which the # path should be returned # # @return [String] The item rep’s path def raw_path(params = {}) - Nanoc3::NotificationCenter.post(:visit_started, item) - Nanoc3::NotificationCenter.post(:visit_ended, item) + Nanoc::Int::NotificationCenter.post(:visit_started, item) + Nanoc::Int::NotificationCenter.post(:visit_ended, item) snapshot_name = params[:snapshot] || :last @raw_paths[snapshot_name] end @@ -294,25 +249,25 @@ # @option params [Symbol] :snapshot (:last) The snapshot for which the # path should be returned # # @return [String] The item rep’s path def path(params = {}) - Nanoc3::NotificationCenter.post(:visit_started, item) - Nanoc3::NotificationCenter.post(:visit_ended, item) + Nanoc::Int::NotificationCenter.post(:visit_started, item) + Nanoc::Int::NotificationCenter.post(:visit_ended, item) snapshot_name = params[:snapshot] || :last @paths[snapshot_name] end # Runs the item content through the given filter with the given arguments. # This method will replace the content of the `:last` snapshot with the # filtered content of the last snapshot. # # This method is supposed to be called only in a compilation rule block - # (see {Nanoc::CompilerDSL#compile}). + # (see {Nanoc::Int::CompilerDSL#compile}). # - # @see Nanoc::ItemRepProxy#filter + # @see Nanoc::Int::ItemRepProxy#filter # # @param [Symbol] filter_name The name of the filter to run the item # representations' content through # # @param [Hash] filter_args The filter arguments that should be passed to @@ -320,22 +275,22 @@ # # @return [void] def filter(filter_name, filter_args = {}) # Get filter class klass = filter_named(filter_name) - raise Nanoc::Errors::UnknownFilter.new(filter_name) if klass.nil? + raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil? # Check whether filter can be applied if klass.from_binary? && !self.binary? - raise Nanoc::Errors::CannotUseBinaryFilter.new(self, klass) + raise Nanoc::Int::Errors::CannotUseBinaryFilter.new(self, klass) elsif !klass.from_binary? && self.binary? - raise Nanoc::Errors::CannotUseTextualFilter.new(self, klass) + raise Nanoc::Int::Errors::CannotUseTextualFilter.new(self, klass) end begin # Notify start - Nanoc::NotificationCenter.post(:filtering_started, self, filter_name) + Nanoc::Int::NotificationCenter.post(:filtering_started, self, filter_name) # Create filter filter = klass.new(assigns) # Run filter @@ -356,64 +311,64 @@ # Create snapshot snapshot(@content[:post] ? :post : :pre, final: false) unless self.binary? ensure # Notify end - Nanoc::NotificationCenter.post(:filtering_ended, self, filter_name) + Nanoc::Int::NotificationCenter.post(:filtering_ended, self, filter_name) end end # Lays out the item using the given layout. This method will replace the # content of the `:last` snapshot with the laid out content of the last # snapshot. # # This method is supposed to be called only in a compilation rule block - # (see {Nanoc::CompilerDSL#compile}). + # (see {Nanoc::Int::CompilerDSL#compile}). # - # @see Nanoc::ItemRepProxy#layout + # @see Nanoc::Int::ItemRepProxy#layout # - # @param [Nanoc::Layout] layout The layout to use + # @param [Nanoc::Int::Layout] layout The layout to use # # @param [Symbol] filter_name The name of the filter to layout the item # representations' content with # # @param [Hash] filter_args The filter arguments that should be passed to # the filter's #run method # # @return [void] def layout(layout, filter_name, filter_args) # Check whether item can be laid out - raise Nanoc::Errors::CannotLayoutBinaryItem.new(self) if self.binary? + raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(self) if self.binary? # Create "pre" snapshot if @content[:post].nil? snapshot(:pre, final: true) end # Create filter klass = filter_named(filter_name) - raise Nanoc::Errors::UnknownFilter.new(filter_name) if klass.nil? + raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil? filter = klass.new(assigns.merge({ layout: layout })) # Visit - Nanoc::NotificationCenter.post(:visit_started, layout) - Nanoc::NotificationCenter.post(:visit_ended, layout) + Nanoc::Int::NotificationCenter.post(:visit_started, layout) + Nanoc::Int::NotificationCenter.post(:visit_ended, layout) begin # Notify start - Nanoc::NotificationCenter.post(:processing_started, layout) - Nanoc::NotificationCenter.post(:filtering_started, self, filter_name) + Nanoc::Int::NotificationCenter.post(:processing_started, layout) + Nanoc::Int::NotificationCenter.post(:filtering_started, self, filter_name) # Layout @content[:last] = filter.setup_and_run(layout.raw_content, filter_args) # Create "post" snapshot snapshot(:post, final: false) ensure # Notify end - Nanoc::NotificationCenter.post(:filtering_ended, self, filter_name) - Nanoc::NotificationCenter.post(:processing_ended, layout) + Nanoc::Int::NotificationCenter.post(:filtering_ended, self, filter_name) + Nanoc::Int::NotificationCenter.post(:processing_ended, layout) end end # Creates a snapshot of the current compiled item content. # @@ -442,23 +397,23 @@ # compilation has changed, and thus whether the item rep needs to be # recompiled. # # @api private # - # @return [Nanoc::ItemRepRecorderProxy] The recording proxy + # @return [Nanoc::Int::ItemRepRecorderProxy] The recording proxy def to_recording_proxy - Nanoc::ItemRepRecorderProxy.new(self) + Nanoc::Int::ItemRepRecorderProxy.new(self) end # Returns false because this item is not yet a proxy, and therefore does # need to be wrapped in a proxy during compilation. # # @api private # # @return [false] # - # @see Nanoc::ItemRepRecorderProxy#proxy? - # @see Nanoc::ItemRepProxy#proxy? + # @see Nanoc::Int::ItemRepRecorderProxy#proxy? + # @see Nanoc::Int::ItemRepProxy#proxy? def proxy? false end alias_method :is_proxy?, :proxy?