Class: Usmu::Template::StaticFile
- Inherits:
-
Object
- Object
- Usmu::Template::StaticFile
- Includes:
- Helpers::Indexer
- Defined in:
- lib/usmu/template/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
Instance Attribute Summary collapse
-
#input_path ⇒ String
readonly
The full path to the file in the source directory.
-
#mtime ⇒ Fixnum
readonly
The modification time of this file.
-
#name ⇒ String
readonly
The name of the file in the source directory.
-
#output_filename ⇒ String
readonly
Returns the filename to use for the output directory with any modifications to the input filename required.
Instance Method Summary collapse
- #==(other) ⇒ void
-
#initialize(configuration, name, metadata, type = nil, content = nil) ⇒ StaticFile
constructor
A new instance of StaticFile.
- #inspect ⇒ void
- #metadata ⇒ void
-
#render(variables = {}) ⇒ String
Renders the file with any templating language required and returns the result.
Methods included from Helpers::Indexer
Constructor Details
#initialize(configuration, name, metadata, type = nil, content = nil) ⇒ StaticFile
Returns a new instance of StaticFile.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/usmu/template/static_file.rb', line 22 def initialize(configuration, name, , type = nil, content = nil) @log = Logging.logger[self] @log.debug("Creating <##{self.class.name} @name=\"#{name}\">") @configuration = configuration @name = name @metadata = @type = type @content = content end |
Instance Attribute Details
#input_path ⇒ String (readonly)
Returns the full path to the file in the source directory.
43 44 45 |
# File 'lib/usmu/template/static_file.rb', line 43 def input_path File.join(@configuration.source_path, @name) end |
#mtime ⇒ Fixnum (readonly)
Returns The modification time of this file.
61 62 63 |
# File 'lib/usmu/template/static_file.rb', line 61 def mtime input_path.nil? ? Time.now.to_i : File.stat(input_path).mtime end |
#name ⇒ String (readonly)
Returns the name of the file in the source directory.
12 13 14 |
# File 'lib/usmu/template/static_file.rb', line 12 def name @name end |
#output_filename ⇒ String (readonly)
Returns the filename to use for the output directory with any modifications to the input filename required.
55 56 57 |
# File 'lib/usmu/template/static_file.rb', line 55 def output_filename @name end |
Instance Method Details
#==(other) ⇒ void
69 70 71 72 73 |
# File 'lib/usmu/template/static_file.rb', line 69 def ==(other) return false unless self.class == other.class self.input_path == other.input_path && self.output_filename == other.output_filename end |
#inspect ⇒ void
65 66 67 |
# File 'lib/usmu/template/static_file.rb', line 65 def inspect "\#<#{self.class}:#{'0x%08x' % __id__} #{@name} => #{output_filename}>" end |
#metadata ⇒ void
47 48 49 |
# File 'lib/usmu/template/static_file.rb', line 47 def {} end |
#render(variables = {}) ⇒ String
Renders the file with any templating language required and returns the result
37 38 39 |
# File 'lib/usmu/template/static_file.rb', line 37 def render(variables = {}) @content || File.read(input_path, mode: 'rb') end |