class Webby::Resources::Page

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.

Public Instance Methods

extension → string click to toggle source

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

# File lib/webby/resources/page.rb, line 69
def extension
  return _meta_data['extension'] if _meta_data.has_key? 'extension'

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

  ext
end
render → string click to toggle source

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

# 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
url() click to toggle source

call-seq

url    => string or nil

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

# File lib/webby/resources/page.rb, line 48
def url
  return @url unless @url.nil?

  @url = super
  if filename == 'index'
    @url = File.dirname(@url)
    @url << '/' unless /\/$/ =~ @url
  end
  @url
end

Public Class Methods

new( path ) click to toggle source

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

# File lib/webby/resources/page.rb, line 17
def initialize( fn, meta_data = nil )
  super(fn)

  if meta_data.instance_of?(Hash)
    @_meta_data = meta_data
  else
    @_meta_data = MetaFile.meta_data(@path)
    @_meta_data ||= {}
  end
  @_meta_data = ::Webby.site.page_defaults.merge(@_meta_data)
  @_meta_data.sanitize!
end