Sha256: b1b0ab6bca30897b3abe3b06ab0750294ee1eb0f49fffd23f6c1b40364c00b87

Contents?: true

Size: 1.99 KB

Versions: 23

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Nanoc
  class BasicItemRepView < ::Nanoc::View
    # @api private
    def initialize(item_rep, context)
      super(context)
      @item_rep = item_rep
    end

    # @abstract
    def item_view_class
      Nanoc::BasicItemView
    end

    # @api private
    def _unwrap
      @item_rep
    end

    # @see Object#==
    def ==(other)
      other.respond_to?(:item) && other.respond_to?(:name) && item == other.item && name == other.name
    end

    # @see Object#eql?
    def eql?(other)
      other.is_a?(self.class) &&
        item.eql?(other.item) &&
        name.eql?(other.name)
    end

    # @see Object#hash
    def hash
      self.class.hash ^ item.identifier.hash ^ name.hash
    end

    # @return [Symbol]
    def name
      @item_rep.name
    end

    def snapshot?(name)
      @context.dependency_tracker.bounce(_unwrap.item, compiled_content: true)
      @item_rep.snapshot?(name)
    end

    # Returns the item rep’s path, as used when being linked to. It starts
    # with a slash and it is relative to the output directory. It does not
    # include the path to the output directory. It will not include the
    # filename if the filename is an index filename.
    #
    # @param [Symbol] snapshot The snapshot for which the path should be
    #   returned.
    #
    # @return [String] The item rep’s path.
    def path(snapshot: :last)
      @context.dependency_tracker.bounce(_unwrap.item, path: true)
      @item_rep.path(snapshot: snapshot)
    end

    # Returns the item that this item rep belongs to.
    #
    # @return [Nanoc::CompilationItemView]
    def item
      item_view_class.new(@item_rep.item, @context)
    end

    # @api private
    def binary?
      snapshot_def = _unwrap.snapshot_defs.find { |sd| sd.name == :last }
      raise Nanoc::Int::Errors::NoSuchSnapshot.new(_unwrap, :last) if snapshot_def.nil?

      snapshot_def.binary?
    end

    def inspect
      "<#{self.class} item.identifier=#{item.identifier} name=#{name}>"
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
nanoc-4.11.12 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.11 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.10 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.9 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.8 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.7 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.6 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.5 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.4 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.3 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.2 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.1 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.11.0 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.10.4 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.10.3 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.10.2 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.10.1 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.10.0 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.9.9 lib/nanoc/base/views/basic_item_rep_view.rb
nanoc-4.9.8 lib/nanoc/base/views/basic_item_rep_view.rb