Class: Webby::Resources::Partial

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

Overview

A Partial is a file in the content folder whose filename starts with an underscore “_” character. Partials contain text that can be included into other pages. Partials are not standalone pages, and they will never correspond directly to an output file.

Partials can contain YAML meta-data at the top of the file. This information is only used to determine the filters to apply to the partial. If there is no meta-data, then the partial text is used “as is” without any processing by the Webby rendering engine.

Instance Attribute Summary

Attributes inherited from Resource

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

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

#initialize(fn) ⇒ Partial

call-seq:

Partial.new( path )

Creates a new Partial object given the full path to the partial file. Partial filenames start with an underscore (this is an enforced convention).



24
25
26
27
28
29
30
# File 'lib/webby/resources/partial.rb', line 24

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

#_readObject

:stopdoc:



77
78
79
# File 'lib/webby/resources/partial.rb', line 77

def _read
  MetaFile.read(@path)
end

#destinationObject

call-seq:

destination    => string

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



61
62
63
# File 'lib/webby/resources/partial.rb', line 61

def destination
  ::Webby.cairn
end

#dirty?Boolean

call-seq:

dirty?    => true or false

Returns true if this resource is newer than its corresponding output product. The resource needs to be rendered (if a page or layout) or copied (if a static file) to the output directory.

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webby/resources/partial.rb', line 39

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

  # if the destination file does not exist, then we are dirty
  return true unless test(?e, destination)

  # if this file's mtime is larger than the destination file's
  # mtime, then we are dirty
  dirty = @mtime > ::File.mtime(destination)
  return dirty if dirty

  # if we got here, then we are not dirty
  false
end

#urlObject

call-seq:

url    => nil

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



72
73
74
# File 'lib/webby/resources/partial.rb', line 72

def url
  nil
end