Class: Webby::Resources::Layout

Inherits:
Resource
  • Object
show all
Defined in:
lib/webby/resources/layout.rb

Overview

A Layout is any file that is found in the layout folder of the webiste directory. Layouts container the common elements of all the pages in a website, and pages from the content folder are rendered into the layout.

Instance Attribute Summary

Attributes inherited from Resource

#_meta_data, #dir, #ext, #mtime, #name, #path

Instance Method Summary collapse

Methods inherited from Resource

#<=>, #[], #[]=, #_read, #_reset, #directory, #dirty?, #equal?, #filename, #method_missing

Constructor Details

#initialize(fn) ⇒ Layout

call-seq:

Layout.new( path )

Creates a new Layout object given the full path to the layout file.



16
17
18
19
20
21
22
# File 'lib/webby/resources/layout.rb', line 16

def initialize( fn )
  super

  @_meta_data = MetaFile.(@path)
  @_meta_data ||= {}
  @_meta_data.sanitize!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Webby::Resources::Resource

Instance Method Details

#destinationObject

The output file destination for the layout. This is the “.cairn” file in the output folder. It is used to determine if the layout is newer than the build products.



41
42
43
# File 'lib/webby/resources/layout.rb', line 41

def destination
  ::Webby.cairn
end

#extensionObject

Returns the extension to be applied to output files rendered by the layotut. This will either be a string or nil if the layout does not specify an extension to use.



28
29
30
31
32
33
34
35
# File 'lib/webby/resources/layout.rb', line 28

def extension
  return ['extension'] if .has_key? 'extension'

  if .has_key? 'layout'
    lyt = ::Webby::Resources.find_layout(['layout'])
    lyt ? lyt.extension : nil
  end
end

#urlObject

Layouts do not have a URL. This method will alwasy return nil.



47
48
49
# File 'lib/webby/resources/layout.rb', line 47

def url
  nil
end