Sha256: d39c9f5d8a18581b8390365ecb546cb4832088d6c48a03237f221c9f1662d374

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 KB

Contents

---
title:      Bad Meta-Data 1
created_at: 2007-08-29 08:57:11.000000 -06:00
filter:     textile
---
h2. Pagination

Pagination is the process of organizing information onto a page such that a fixed number of items appear on each page. Webby provides some methods for paginating information.

Let's assume that your website has a collection of articles in a folder called "articles" in the content directory. The goal is to display these articles ten at a time in reverse chronological order.

<pre>
---
title: Articles
filter:
- erb
- textile
---
h2. <%= h(@page.title) %>

<%
  articles = @pages.find(:all, :in_directory => "articles",
                         :sort_by => "mtime", :reverse => true)
  paginate(articles, 10) do |page|
%>
<%= page.render %>
<hr />
<% end %>

<%= link_to("Prev", @pager.prev) if @pager.prev? %>
<%= link_to("Next", @pager.next) if @pager.next? %>
</pre>

In the example page above, the first step is get the collection of articles we are interested in the paginating. This is done using the <code>@pages.find</code> method to retrieve all the pages from the articles folder sorted in reverse order by modification time. When we have the collection of articles, we pass them to the @paginate@ method along with the desired number of articles per page. The @paginate@ method will pass each page in the @articles@ collection to the supplied block of code, but for each ten pages passed to the block, a new webpage will be created.

Version data entries

17 entries across 17 versions & 8 rubygems

Version Path
TwP-webby-0.9.1 spec/data/hooligans/bad_meta_data_1.txt
TwP-webby-0.9.2 spec/data/hooligans/bad_meta_data_1.txt
TwP-webby-0.9.3 spec/data/hooligans/bad_meta_data_1.txt
TwP-webby-0.9.4.1 spec/data/hooligans/bad_meta_data_1.txt
TwP-webby-0.9.4 spec/data/hooligans/bad_meta_data_1.txt
blowmage-webby-0.9.4.1 spec/data/hooligans/bad_meta_data_1.txt
dysinger-webby-0.9.4 spec/data/hooligans/bad_meta_data_1.txt
francois-webby-0.9.4.1 spec/data/hooligans/bad_meta_data_1.txt
giraffesoft-webby-0.9.5 spec/data/hooligans/bad_meta_data_1.txt
mikker-webby-0.9.4 spec/data/hooligans/bad_meta_data_1.txt
jamesgolick-webby-0.9.5 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.2 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.3 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.3-x86-mswin32 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.1 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.4-x86-mswin32 spec/data/hooligans/bad_meta_data_1.txt
webby-0.9.4 spec/data/hooligans/bad_meta_data_1.txt