Class: Nanoc::Int::Content Abstract Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/base/entities/content.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Abstract content.

The filename is the full filename on the default filesystem. It can be nil. It is used by filters such as Sass, which look up items on the filesystem.

Direct Known Subclasses

BinaryContent, TextualContent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

included

Constructor Details

#initialize(filename) ⇒ Content

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.

Returns a new instance of Content.

Parameters:



20
21
22
23
24
25
26
# File 'lib/nanoc/base/entities/content.rb', line 20

def initialize(filename)
  if filename && Pathname.new(filename).relative?
    raise ArgumentError, 'Content filename is not absolute'
  end

  @filename = filename
end

Instance Attribute Details

#filenameString? (readonly)

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.

Returns:



16
17
18
# File 'lib/nanoc/base/entities/content.rb', line 16

def filename
  @filename
end

Class Method Details

.create(content, binary: false, filename: nil) ⇒ 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.

Parameters:

  • content (Nanoc::Int::Content, String, Proc)

    The uncompiled item content (if it is textual content) or the path to the filename containing the content (if this is binary content).

  • binary (Boolean) (defaults to: false)

    Whether or not this item is binary

  • filename (String) (defaults to: nil)

    Absolute path to the file containing this content (if any)



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nanoc/base/entities/content.rb', line 44

def self.create(content, binary: false, filename: nil)
  if content.nil?
    raise ArgumentError, 'Cannot create nil content'
  elsif content.is_a?(Nanoc::Int::Content)
    content
  elsif binary
    Nanoc::Int::BinaryContent.new(content)
  else
    Nanoc::Int::TextualContent.new(content, filename: filename)
  end
end

Instance Method Details

#binary?Boolean

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.

This method is abstract.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/nanoc/base/entities/content.rb', line 59

def binary?
  raise NotImplementedError
end

#freezeObject

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.



29
30
31
32
33
# File 'lib/nanoc/base/entities/content.rb', line 29

def freeze
  super
  @filename.freeze
  self
end