class Nanoc::Int::Content

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.

@abstract

@api private

Attributes

filename[R]

@return [String, nil]

Public Class Methods

create(content, binary: false, filename: nil) click to toggle source

@param [String] content The uncompiled item content (if it is textual

content) or the path to the filename containing the content (if this
is binary content).

@param [Boolean] binary Whether or not this item is binary

@param [String] filename Absolute path to the file containing this

content (if any)
# File lib/nanoc/base/entities/content.rb, line 38
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
new(filename) click to toggle source

@param [String, nil] filename

# File lib/nanoc/base/entities/content.rb, line 17
def initialize(filename)
  if filename && Pathname.new(filename).relative?
    raise ArgumentError, 'Content filename is not absolute'
  end

  @filename = filename
end

Public Instance Methods

binary?() click to toggle source

@abstract

@return [Boolean]

# File lib/nanoc/base/entities/content.rb, line 53
def binary?
  raise NotImplementedError
end
freeze() click to toggle source
Calls superclass method
# File lib/nanoc/base/entities/content.rb, line 25
def freeze
  super
  @filename.freeze
end