Class: Webby::Resources::Page

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

Overview

A Page is a file in the content folder that contains YAML meta-data at the top of the file. Pages are processed by the Webby rendering engine and then inserted into the desired layout. The string resulting from processing and layout is then written to the output directory.

Instance Attribute Summary collapse

Attributes inherited from Resource

#dir, #ext, #filename, #mtime, #path

Instance Method Summary collapse

Methods inherited from Resource

#<=>, #[], #[]=, #dirty?, #equal?, #method_missing

Constructor Details

#initialize(fn) ⇒ Page

call-seq:

Resource.new( path )

Creates a new page object from the full path to the page file.



20
21
22
23
24
25
26
27
28
# File 'lib/webby/resources/page.rb', line 20

def initialize( fn )
  super
  @number = nil

  @mdata = ::Webby::Resources::File.(@path)
  @mdata ||= {}
  @mdata = ::Webby.site.page_defaults.merge(@mdata)
  @mdata.sanitize!
end

Dynamic Method Handling

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

Instance Attribute Details

#numberObject

Resource page number (if needed)



13
14
15
# File 'lib/webby/resources/page.rb', line 13

def number
  @number
end

Instance Method Details

#destinationObject

call-seq:

destination    => string

Returns the path in the output directory where the rendered page should be stored. This path is used to determine if the page is dirty and in need of rendering.

The destination for a page can be overridden by explicitly setting the ‘destination’ property in the page’s meta-data.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/webby/resources/page.rb', line 78

def destination
  return @dest if defined? @dest and @dest

  @dest = if @mdata.has_key? 'destination' then @mdata['destination']
          else ::File.join(dir, filename) end

  @dest = ::File.join(::Webby.site.output_dir, @dest)
  @dest << @number.to_s if @number

  ext = extension
  unless ext.nil? or ext.empty?
    @dest << '.' << ext
  end
  @dest
end

#extensionObject

call-seq:

extension    => string

Returns the extension that will be appended to the output destination filename. The extension is determined by looking at the following:

  • this page’s meta-data for an ‘extension’ property

  • the meta-data of this page’s layout for an ‘extension’ property

  • the extension of this page file



104
105
106
107
108
109
110
111
112
113
# File 'lib/webby/resources/page.rb', line 104

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

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

#render(renderer = nil) ⇒ Object

call-seq:

render   => string

This method is being deprecated. Please use the Renderer#render method instead.



36
37
38
39
40
# File 'lib/webby/resources/page.rb', line 36

def render( renderer = nil )
  Webby.deprecated "render", "it is being replaced by the Renderer#render() method"
  renderer ||= ::Webby::Renderer.new(self)
  renderer._render_page
end

#urlObject

call-seq

url    => string or nil

Returns a string suitable for use as a URL linking to this page. Nil is returned for layouts.



48
49
50
51
52
53
54
# File 'lib/webby/resources/page.rb', line 48

def url
  return @url if defined? @url and @url

  @url = destination.sub(::Webby.site.output_dir, '')
  @url = File.dirname(@url) if filename == 'index' and number.nil?
  @url
end