Class: Usmu::StaticFile

Inherits:
Object
  • Object
show all
Defined in:
lib/usmu/static_file.rb

Overview

Represents a static file which should be transferred to the destination unchanged. This also acts as the base class for all layouts and page types. The basic interface defined here is used to process all types of files.

Direct Known Subclasses

Layout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, name, type = nil, content = nil, metadata = nil) ⇒ StaticFile

Returns a new instance of StaticFile.

Parameters:

  • configuration (Usmu::Configuration)

    The configuration for the website we're generating.

  • name (String)

    The name of the file in the source directory.

  • type (String) (defaults to: nil)

    The type of template to use with the file. Not used for StaticFile. Used for testing purposes.

  • content (String) (defaults to: nil)

    The content of the file. Used for testing purposes.

  • metadata (String) (defaults to: nil)

    The metadata for the file. Used for testing purposes.



19
20
21
22
23
24
# File 'lib/usmu/static_file.rb', line 19

def initialize(configuration, name, type = nil, content = nil,  = nil)
  @configuration = configuration
  @name = name
  @type = type
  @content = content
end

Instance Attribute Details

#input_pathString (readonly)

Returns the full path to the file in the source directory.

Returns:

  • (String)

    the full path to the file in the source directory



36
37
38
# File 'lib/usmu/static_file.rb', line 36

def input_path
  File.join(@configuration.source_path, @name)
end

#nameString (readonly)

Returns the name of the file in the source directory.

Returns:

  • (String)

    the name of the file in the source directory



11
12
13
# File 'lib/usmu/static_file.rb', line 11

def name
  @name
end

#output_filenameString (readonly)

Returns the filename to use for the output directory with any modifications to the input filename required.

Returns:

  • (String)

    the filename to use in the output directory.



44
45
46
# File 'lib/usmu/static_file.rb', line 44

def output_filename
  @name
end

Instance Method Details

#render(variables = {}) ⇒ String

Renders the file with any templating language required and returns the result

Parameters:

  • variables (Hash) (defaults to: {})

    Variables to be used in the template.

Returns:

  • (String)

    The rendered file



30
31
32
# File 'lib/usmu/static_file.rb', line 30

def render(variables = {})
  @content || File.read(input_path)
end