Class: Nanoc::ItemWithoutRepsView
- Inherits:
-
View
- Object
- View
- Nanoc::ItemWithoutRepsView
- Includes:
- DocumentViewMixin
- Defined in:
- lib/nanoc/base/views/item_without_reps_view.rb
Direct Known Subclasses
Constant Summary
Instance Method Summary (collapse)
-
- (Boolean) binary?
True if the item is binary, false otherwise.
-
- (Enumerable<Nanoc::ItemWithRepsView>) children
Returns the children of this item.
-
- (Nanoc::ItemWithRepsView?) parent
Returns the parent of this item, if one exists.
Methods included from DocumentViewMixin
#==, #[], #attributes, #fetch, #hash, #identifier, #key?
Methods inherited from View
Instance Method Details
- (Boolean) binary?
Returns True if the item is binary, false otherwise
40 41 42 |
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 40 def binary? unwrap.content.binary? end |
- (Enumerable<Nanoc::ItemWithRepsView>) children
Returns the children of this item. For items with identifiers that have extensions, returns an empty collection.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 9 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 |
- (Nanoc::ItemWithRepsView?) parent
Returns the parent of this item, if one exists. For items with identifiers that have extensions, returns nil.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 26 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 |