Class Hobix::Page
In: lib/hobix/weblog.rb
Parent: Object

The Page class is very simple class which contains information specific to a template.

Introduction

The id, next and prev accessors provide ids for the current page and its neighbors (for example, in the case of monthly archives, which may have surrounding months.)

To get complete URLs for each of the above, use: link, next_link, and prev_link.

The timestamp accessor contains the earliest date pertinent to the page. For example, in the case of a monthly archive, it will contain a Time object for the first day of the month. In the case of the `index’ page, you‘ll get a Time object for the earliest entry on the page.

The updated accessor contains the latest date pertinent to the page. Usually this would be the most recent modification time among entries on the page. This accessor is used by the regeneration system to determine if a page needs regeneration. See +Hobix::Weblog#regenerate+ for more.

Context in Hobix

There are only two places you‘ll encounter this class in Hobix.

If you are writing an output plugin, a Page class is passed in the vars hash to the +BaseOutput#load+ method. You‘ll find the class in vars[:page].

If you are writing ERB or RedRum templates, these vars are passed into the templates. The Page class is accessible as a variable called `page’.

Examples

Example 1: Pagination in a Template

Let‘s say we want every entry in our site to contain links to the entries which are chronologically nearby.

If we‘re using RedRum templates, we could do the following in entry.html.redrum:

  <% if page.prev %>"last":<%= page.prev_link %><% end %>
  <% if page.next %>"next":<%= page.next_link %><% end %>

Methods

id   link   new   next_link   prev_link   reference_fields   references  

Attributes

id  [R] 
link  [RW] 
next  [RW] 
prev  [RW] 
timestamp  [RW] 
updated  [RW] 

Public Class methods

[Source]

    # File lib/hobix/weblog.rb, line 97
97:     def initialize( id, dir='.' )
98:         @id, @dir = id, dir
99:     end

Public Instance methods

[Source]

     # File lib/hobix/weblog.rb, line 100
100:     def id; dirj( @dir, @id ).gsub( /^\/+/, '' ); end

[Source]

     # File lib/hobix/weblog.rb, line 101
101:     def link; dirj( @dir, @id ) + @ext; end

[Source]

     # File lib/hobix/weblog.rb, line 102
102:     def next_link; dirj( @dir, @next ) + @ext if @next; end

[Source]

     # File lib/hobix/weblog.rb, line 103
103:     def prev_link; dirj( @dir, @prev ) + @ext if @prev; end

[Source]

     # File lib/hobix/weblog.rb, line 113
113:     def reference_fields; [:next, :prev]; end

[Source]

     # File lib/hobix/weblog.rb, line 114
114:     def references; reference_fields.map { |f| self.send f }.compact; end

[Validate]