Module: Nanoc::DocumentViewMixin

Included in:
ItemWithoutRepsView, LayoutView
Defined in:
lib/nanoc/base/views/mixins/document_view_mixin.rb

Constant Summary

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

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#[]


34
35
36
37
38
39
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 34

def [](key)
  Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
  Nanoc::Int::NotificationCenter.post(:visit_ended,   unwrap)

  unwrap.attributes[key]
end

#attributesHash

Returns:

  • (Hash)


42
43
44
45
46
47
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 42

def attributes
  Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
  Nanoc::Int::NotificationCenter.post(:visit_ended,   unwrap)

  unwrap.attributes
end

#fetch(key, fallback = NONE, &_block) ⇒ Object

See Also:

  • Hash#fetch


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 50

def fetch(key, fallback = NONE, &_block)
  Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
  Nanoc::Int::NotificationCenter.post(:visit_ended,   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


24
25
26
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 24

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

#identifierNanoc::Identifier

Returns:



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

def identifier
  unwrap.identifier
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


66
67
68
69
70
71
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 66

def key?(key)
  Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
  Nanoc::Int::NotificationCenter.post(:visit_ended,   unwrap)

  unwrap.attributes.key?(key)
end