Class: Hobix::Page
- Inherits:
-
Object
- Object
- Hobix::Page
- Defined in:
- lib/hobix/weblog.rb
Overview
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.
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 %>
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#link ⇒ Object
Returns the value of attribute link.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#updated ⇒ Object
Returns the value of attribute updated.
Instance Method Summary collapse
-
#add_ext(ext) ⇒ Object
:nodoc:.
-
#dirj(dir, link) ⇒ Object
:nodoc:.
-
#initialize(id, dir = '.') ⇒ Page
constructor
A new instance of Page.
- #next_link ⇒ Object
- #prev_link ⇒ Object
- #reference_fields ⇒ Object
- #references ⇒ Object
Constructor Details
#initialize(id, dir = '.') ⇒ Page
Returns a new instance of Page.
97 98 99 |
# File 'lib/hobix/weblog.rb', line 97 def initialize( id, dir='.' ) @id, @dir = id, dir end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
95 96 97 |
# File 'lib/hobix/weblog.rb', line 95 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
96 97 98 |
# File 'lib/hobix/weblog.rb', line 96 def link @link end |
#next ⇒ Object
Returns the value of attribute next.
96 97 98 |
# File 'lib/hobix/weblog.rb', line 96 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
96 97 98 |
# File 'lib/hobix/weblog.rb', line 96 def prev @prev end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
96 97 98 |
# File 'lib/hobix/weblog.rb', line 96 def @timestamp end |
#updated ⇒ Object
Returns the value of attribute updated.
96 97 98 |
# File 'lib/hobix/weblog.rb', line 96 def updated @updated end |
Instance Method Details
#add_ext(ext) ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/hobix/weblog.rb', line 110 def add_ext( ext ) #:nodoc: @ext = ext end |
#dirj(dir, link) ⇒ Object
:nodoc:
104 105 106 107 108 109 |
# File 'lib/hobix/weblog.rb', line 104 def dirj( dir, link ) #:nodoc: if link[0] != ?/ and link != '.' link = File.join( dir == '.' ? "/" : dir, link ) end link end |
#next_link ⇒ Object
102 |
# File 'lib/hobix/weblog.rb', line 102 def next_link; dirj( @dir, @next ) + @ext if @next; end |
#prev_link ⇒ Object
103 |
# File 'lib/hobix/weblog.rb', line 103 def prev_link; dirj( @dir, @prev ) + @ext if @prev; end |
#reference_fields ⇒ Object
113 |
# File 'lib/hobix/weblog.rb', line 113 def reference_fields; [:next, :prev]; end |
#references ⇒ Object
114 |
# File 'lib/hobix/weblog.rb', line 114 def references; reference_fields.map { |f| self.send f }.compact; end |