Class: Nanoc::ItemWithoutRepsView
- Includes:
- DocumentViewMixin
- Defined in:
- lib/nanoc/base/views/item_without_reps_view.rb
Direct Known Subclasses
Constant Summary
Constants included from DocumentViewMixin
Instance Method Summary collapse
-
#binary? ⇒ Boolean
True if the item is binary, false otherwise.
-
#children ⇒ Enumerable<Nanoc::ItemWithRepsView>
Returns the children of this item.
-
#parent ⇒ Nanoc::ItemWithRepsView?
Returns the parent of this item, if one exists.
- #raw_filename ⇒ Object private
Methods included from DocumentViewMixin
#==, #[], #attributes, #eql?, #fetch, #hash, #identifier, #initialize, #inspect, #key?, #raw_content, #reference, #unwrap
Methods inherited from View
#_context, #frozen?, #initialize, #inspect, #unwrap
Instance Method Details
#binary? ⇒ Boolean
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 |
#children ⇒ Enumerable<Nanoc::ItemWithRepsView>
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 |
#parent ⇒ Nanoc::ItemWithRepsView?
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 |
#raw_filename ⇒ Object
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.
45 46 47 |
# File 'lib/nanoc/base/views/item_without_reps_view.rb', line 45 def raw_filename unwrap.content.filename end |