Class: Nanoc::Core::Content

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

Direct Known Subclasses

BinaryContent, TextualContent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(filename) ⇒ Content

Returns a new instance of Content.



12
13
14
15
16
17
18
# File 'lib/nanoc/core/content.rb', line 12

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

  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



9
10
11
# File 'lib/nanoc/core/content.rb', line 9

def filename
  @filename
end

Class Method Details

.create(content, binary: false, filename: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nanoc/core/content.rb', line 28

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

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/nanoc/core/content.rb', line 41

def binary?
  raise NotImplementedError
end

#freezeObject



21
22
23
24
25
# File 'lib/nanoc/core/content.rb', line 21

def freeze
  super
  @filename.freeze
  self
end

#textual?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/nanoc/core/content.rb', line 46

def textual?
  !binary?
end