Module: Nanoc::Core::DocumentViewMixin
- Included in:
- BasicItemView, LayoutView
- Defined in:
- lib/nanoc/core/document_view_mixin.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #_unwrap ⇒ Object private
- #attributes ⇒ Hash
- #eql?(other) ⇒ Boolean
- #fetch(key, fallback = Nanoc::Core::UNDEFINED) ⇒ Object
- #hash ⇒ Object
- #identifier ⇒ Nanoc::Core::Identifier
- #initialize(document, context) ⇒ Object private
- #inspect ⇒ Object
- #key?(key) ⇒ Boolean
- #raw_content ⇒ Object private
- #reference ⇒ Object private
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 18 def ==(other) other.respond_to?(:identifier) && identifier == other.identifier end |
#[](key) ⇒ Object
38 39 40 41 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 38 def [](key) @context.dependency_tracker.bounce(_unwrap, attributes: [key]) _unwrap.attributes[key] end |
#_unwrap ⇒ 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.
13 14 15 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 13 def _unwrap @document end |
#attributes ⇒ Hash
44 45 46 47 48 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 44 def attributes # TODO: Refine dependencies @context.dependency_tracker.bounce(_unwrap, attributes: true) _unwrap.attributes end |
#eql?(other) ⇒ Boolean
23 24 25 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 23 def eql?(other) other.is_a?(self.class) && identifier.eql?(other.identifier) end |
#fetch(key, fallback = Nanoc::Core::UNDEFINED) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 51 def fetch(key, fallback = Nanoc::Core::UNDEFINED, &) @context.dependency_tracker.bounce(_unwrap, attributes: [key]) if _unwrap.attributes.key?(key) _unwrap.attributes[key] elsif !Nanoc::Core::UNDEFINED.equal?(fallback) fallback elsif block_given? yield(key) else raise KeyError, "key not found: #{key.inspect}" end end |
#hash ⇒ Object
28 29 30 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 28 def hash [self.class, identifier].hash end |
#identifier ⇒ Nanoc::Core::Identifier
33 34 35 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 33 def identifier _unwrap.identifier end |
#initialize(document, context) ⇒ 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.
7 8 9 10 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 7 def initialize(document, context) super(context) @document = document end |
#inspect ⇒ Object
82 83 84 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 82 def inspect "<#{self.class} identifier=#{_unwrap.identifier}>" end |
#key?(key) ⇒ Boolean
66 67 68 69 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 66 def key?(key) @context.dependency_tracker.bounce(_unwrap, attributes: [key]) _unwrap.attributes.key?(key) end |
#raw_content ⇒ 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.
77 78 79 80 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 77 def raw_content @context.dependency_tracker.bounce(_unwrap, raw_content: true) _unwrap.content.string end |
#reference ⇒ 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.
72 73 74 |
# File 'lib/nanoc/core/document_view_mixin.rb', line 72 def reference _unwrap.reference end |