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

Instance Method Details

#==(other) ⇒ Object

See Also:

  • 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

See Also:

  • Hash#[]


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

#attributesHash

Returns:



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

Returns:

  • (Boolean)

See Also:

  • Object#eql?


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

See Also:

  • Hash#fetch


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

#hashObject

See Also:

  • Object#hash


28
29
30
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 28

def hash
  self.class.hash ^ identifier.hash
end

#identifierNanoc::Identifier

Returns:



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

#inspectObject



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

Returns:

  • (Boolean)

See Also:

  • Hash#key?


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_contentObject

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

#referenceObject

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

#unwrapObject

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