Class: Nanoc::Core::BasicItemRepView

Inherits:
View
  • Object
show all
Defined in:
lib/nanoc/core/views/basic_item_rep_view.rb

Instance Method Summary collapse

Methods inherited from View

#_context, #frozen?

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(item_rep, context) ⇒ BasicItemRepView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BasicItemRepView.



7
8
9
10
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 7

def initialize(item_rep, context)
  super(context)
  @item_rep = item_rep
end

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


23
24
25
26
27
28
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 23

def ==(other)
  other.respond_to?(:item) &&
    other.respond_to?(:name) &&
    item == other.item &&
    name == other.name
end

#_unwrapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 18

def _unwrap
  @item_rep
end

#binary?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 74

def binary?
  snapshot_def = _unwrap.snapshot_defs.find { |sd| sd.name == :last }
  if snapshot_def.nil?
    raise Nanoc::Core::Errors::NoSuchSnapshot.new(
      _unwrap, :last
    )
  end

  snapshot_def.binary?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?


31
32
33
34
35
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 31

def eql?(other)
  other.is_a?(self.class) &&
    item.eql?(other.item) &&
    name.eql?(other.name)
end

#hashObject

See Also:

  • Object#hash


38
39
40
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 38

def hash
  [self.class, item.identifier, name].hash
end

#inspectObject



85
86
87
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 85

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

#itemNanoc::Core::CompilationItemView

Returns the item that this item rep belongs to.



69
70
71
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 69

def item
  item_view_class.new(@item_rep.item, @context)
end

#item_view_classObject

This method is abstract.


13
14
15
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 13

def item_view_class
  Nanoc::Core::BasicItemView
end

#nameSymbol

Returns:

  • (Symbol)


43
44
45
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 43

def name
  @item_rep.name
end

#path(snapshot: :last) ⇒ String

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.

Parameters:

  • snapshot (Symbol) (defaults to: :last)

    The snapshot for which the path should be returned.

Returns:

  • (String)

    The item rep’s path.



61
62
63
64
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 61

def path(snapshot: :last)
  @context.dependency_tracker.bounce(_unwrap.item, path: true)
  @item_rep.path(snapshot:)
end

#snapshot?(name) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/nanoc/core/views/basic_item_rep_view.rb', line 47

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