Class: Nanoc::ItemWithoutRepsView

Inherits:
View
  • Object
show all
Includes:
DocumentViewMixin
Defined in:
lib/nanoc/base/views/item_without_reps_view.rb

Direct Known Subclasses

ItemWithRepsView, MutableItemView

Instance Method Summary collapse

Methods included from DocumentViewMixin

#==, #[], #attributes, #eql?, #fetch, #hash, #identifier, #inspect, #key?

Methods inherited from View

#frozen?, #inspect

Instance Method Details

#binary?Boolean

Returns True if the item is binary, false otherwise

Returns:

  • (Boolean)

    True if the item is binary, false otherwise



42
43
44
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 42

def binary?
  unwrap.content.binary?
end

#childrenEnumerable<Nanoc::ItemWithRepsView>

Returns the children of this item. For items with identifiers that have extensions, returns an empty collection.

Returns:



11
12
13
14
15
16
17
18
19
20
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 11

def children
  unless unwrap.identifier.legacy?
    raise Nanoc::Int::Errors::CannotGetParentOrChildrenOfNonLegacyItem.new(unwrap.identifier)
  end

  children_pattern = Nanoc::Int::Pattern.from(unwrap.identifier.to_s + '*/')
  children = @context.items.select { |i| children_pattern.match?(i.identifier) }

  children.map { |i| self.class.new(i, @context) }.freeze
end

#parentNanoc::ItemWithRepsView?

Returns the parent of this item, if one exists. For items with identifiers that have extensions, returns nil.

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 28

def parent
  unless unwrap.identifier.legacy?
    raise Nanoc::Int::Errors::CannotGetParentOrChildrenOfNonLegacyItem.new(unwrap.identifier)
  end

  parent_identifier = '/' + unwrap.identifier.components[0..-2].join('/') + '/'
  parent_identifier = '/' if parent_identifier == '//'

  parent = @context.items[parent_identifier]

  parent && self.class.new(parent, @context)
end