Module: Nanoc::DocumentViewMixin
- Included in:
- ItemWithoutRepsView, LayoutView
- Defined in:
- lib/nanoc/base/views/mixins/document_view_mixin.rb
Constant Summary collapse
- NONE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new.freeze
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #attributes ⇒ Hash
- #eql?(other) ⇒ Boolean
- #fetch(key, fallback = NONE, &_block) ⇒ Object
- #hash ⇒ Object
- #identifier ⇒ Nanoc::Identifier
- #initialize(document, context) ⇒ Object private
- #inspect ⇒ Object
- #key?(key) ⇒ Boolean
- #raw_content ⇒ Object private
- #reference ⇒ Object private
- #unwrap ⇒ Object private
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/nanoc/base/views/mixins/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/base/views/mixins/document_view_mixin.rb', line 38 def [](key) @context.dependency_tracker.bounce(unwrap) unwrap.attributes[key] end |
#attributes ⇒ Hash
44 45 46 47 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 44 def attributes @context.dependency_tracker.bounce(unwrap) unwrap.attributes end |
#eql?(other) ⇒ Boolean
23 24 25 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 23 def eql?(other) other.is_a?(self.class) && identifier.eql?(other.identifier) end |
#fetch(key, fallback = NONE, &_block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 50 def fetch(key, fallback = NONE, &_block) @context.dependency_tracker.bounce(unwrap) if unwrap.attributes.key?(key) unwrap.attributes[key] elsif !fallback.equal?(NONE) fallback elsif block_given? yield(key) else raise KeyError, "key not found: #{key.inspect}" end end |
#hash ⇒ Object
28 29 30 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 28 def hash self.class.hash ^ identifier.hash end |
#identifier ⇒ Nanoc::Identifier
33 34 35 |
# File 'lib/nanoc/base/views/mixins/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/base/views/mixins/document_view_mixin.rb', line 7 def initialize(document, context) super(context) @document = document end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 80 def inspect "<#{self.class} identifier=#{unwrap.identifier}>" end |
#key?(key) ⇒ Boolean
65 66 67 68 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 65 def key?(key) @context.dependency_tracker.bounce(unwrap) 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.
76 77 78 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 76 def raw_content 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.
71 72 73 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 71 def reference unwrap.reference 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/base/views/mixins/document_view_mixin.rb', line 13 def unwrap @document end |