Class: Nanoc::Core::BasicItemView
- Includes:
- DocumentViewMixin
- Defined in:
- lib/nanoc/core/views/basic_item_view.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#binary? ⇒ Boolean
True if the item is binary, false otherwise.
-
#children ⇒ Enumerable<Nanoc::Core::CompilationItemView>
Returns the children of this item.
-
#parent ⇒ Nanoc::Core::CompilationItemView?
Returns the parent of this item, if one exists.
-
#raw_filename ⇒ String?
The path to the file containing the uncompiled content of this item.
Methods included from DocumentViewMixin
#==, #[], #_unwrap, #attributes, #eql?, #fetch, #hash, #identifier, #initialize, #inspect, #key?, #raw_content, #reference
Methods inherited from View
#_context, #_unwrap, #frozen?, #initialize, #inspect
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
Instance Method Details
#binary? ⇒ Boolean
Returns True if the item is binary, false otherwise.
50 51 52 |
# File 'lib/nanoc/core/views/basic_item_view.rb', line 50 def binary? _unwrap.content.binary? end |
#children ⇒ Enumerable<Nanoc::Core::CompilationItemView>
Returns the children of this item. For items with identifiers that have extensions, returns an empty collection.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nanoc/core/views/basic_item_view.rb', line 12 def children unless _unwrap.identifier.legacy? raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem .new(_unwrap.identifier) end children_pattern = Nanoc::Core::Pattern.from("#{_unwrap.identifier}*/") children = @context.items.select do |i| children_pattern.match?(i.identifier) end children.map { |i| self.class.new(i, @context) }.freeze end |
#parent ⇒ Nanoc::Core::CompilationItemView?
Returns the parent of this item, if one exists. For items with identifiers that have extensions, returns nil.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nanoc/core/views/basic_item_view.rb', line 32 def parent unless _unwrap.identifier.legacy? raise Nanoc::Core::Errors::CannotGetParentOrChildrenOfNonLegacyItem .new(_unwrap.identifier) end parent_identifier = "/#{_unwrap.identifier.components[0..-2].join('/')}/" if parent_identifier == '//' parent_identifier = '/' end parent = @context.items.object_with_identifier(parent_identifier) parent && self.class.new(parent, @context) end |
#raw_filename ⇒ String?
Returns The path to the file containing the uncompiled content of this item.
56 57 58 59 |
# File 'lib/nanoc/core/views/basic_item_view.rb', line 56 def raw_filename @context.dependency_tracker.bounce(_unwrap, raw_content: true) _unwrap.content.filename end |