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

Attributes inherited from Resource

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

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

#initialize(fn, meta_data = nil) ⇒ Page

call-seq:

Resource.new( path )

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



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

def initialize( fn,  = nil )
  super(fn)

  if .instance_of?(Hash)
    @_meta_data = 
  else
    @_meta_data = MetaFile.(@path)
    @_meta_data ||= {}
  end
  @_meta_data = ::Webby.site.page_defaults.merge(@_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

#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



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/webby/resources/page.rb', line 69

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

  if .has_key? 'layout'
    lyt = ::Webby::Resources.find_layout(['layout'])
    lyt_ext = lyt ? lyt.extension : nil
    return lyt_ext if lyt_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
55
56
57
# 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 %r/\/$/ =~ @url
  end
  @url
end