Module: Nanoc::MutableDocumentViewMixin

Included in:
MutableItemView, MutableLayoutView
Defined in:
lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb

Instance Method Summary collapse

Instance Method Details

#[]=(key, value) ⇒ Object

Sets the value for the given attribute.

Parameters:

  • key (Symbol)

See Also:

  • Hash#[]=


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb', line 31

def []=(key, value)
  # FIXME: clearing checksum data should be done in the document
  unwrap.checksum_data = nil
  unwrap.attributes_checksum_data = nil

  disallowed_value_classes = Set.new([
    Nanoc::Int::Item,
    Nanoc::Int::Layout,
    Nanoc::CompilationItemView,
    Nanoc::LayoutView,
  ])
  if disallowed_value_classes.include?(value.class)
    raise DisallowedAttributeValueError.new(value)
  end

  unwrap.attributes[key] = value
end

#identifier=(arg) ⇒ Object

Sets the identifier to the given argument.

Parameters:



52
53
54
# File 'lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb', line 52

def identifier=(arg)
  unwrap.identifier = Nanoc::Identifier.from(arg)
end

#raw_content=(arg) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb', line 18

def raw_content=(arg)
  # FIXME: clearing checksum data should be done in the document
  unwrap.checksum_data = nil
  unwrap.content_checksum_data = nil

  unwrap.content = Nanoc::Int::Content.create(arg)
end

#update_attributes(hash) ⇒ self

Updates the attributes based on the given hash.

Parameters:

  • hash (Hash)

Returns:

  • (self)


61
62
63
64
65
66
67
68
# File 'lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb', line 61

def update_attributes(hash)
  # FIXME: clearing checksum data should be done in the document
  unwrap.checksum_data = nil
  unwrap.attributes_checksum_data = nil

  hash.each { |k, v| unwrap.attributes[k] = v }
  self
end