public
Description: rails plugin for using will_paginate with liquid templating
Homepage: http://matthewhutchinson.net
Clone URL: git://github.com/hiddenloop/will_paginate-liquidized.git
hiddenloop (author)
Thu Apr 30 07:31:52 -0700 2009
commit  56307df21af9db78f5327875463663c6fc09e19b
tree    70b4555844275d2e468d28a61a4f313a4df21759
parent  28b789508caeb382bfb4e39ab0bba1297c1db500
name age message
file README.textile Loading commit data...
file init.rb
directory lib/
directory test/
README.textile

Will Paginate Liquidized

About

A small plugin allowing you to use pagination from will_paginate inside your Liquid templates. This is a new version of the older plugin at artweb-design. I’ve basically re-written parts of it to work with the very latest versions of Liquid and Will-Paginate (see below for the version information). I will try to keep this plugin up to date with ongoing changes in the Liquid and Will-Paginate projects. Check the latest commit logs and this doc for more information.

Caveats

Ongoing issues with this project include;

  • needs better tests, possibly switching to using RSpec
  • currently has only been tested within my own project – needs further testing

Setup / Using

Requirements

What do you need?

Installing

script/plugin install git://github.com/hiddenloop/will_paginate-liquidized.git

Using

In your controller you might have something like this;

  class MoviesController < ApplicationController
    # GET /movies
    # GET /movies.xml
    def index
      @movies = Movie.all.paginate(:page => params[:page], :per_page => 10)
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml => @movies }
      end
    end
  end

In your view put something like this in movies/index.html.erb;

  <%= Liquid::Template.parse("{{ movies | will_paginate_liquid }}").render({'movies' => @movies}, :registers => {:controller => @controller}) %>  

NOTE: you must remember to pass the current controller in rendering (:registers). If anyone can think of a way around this let me know.

You won’t get any pagination links until you exceed 10 (per_page setting defined in controller action). You can also pass the following other optional arguments to the will_paginate_liquid method.

  {{ movies | will_paginate_liquid : 'anchor', 'prev_label', 'next_label' }}
  
  anchor: apply a #anchor to all generated urls in the pagination
  prev_label: label for the previous page button
  next_label: label for the next page button

What does the code do?

Registers a new filter tag for Liquid to access will_paginate using a custom LinkRenderer so it can reference the @controller from the current liquid context[:registers]. Uses ActionView::Helpers::UrlHelper, ActionView::Helpers::TagHelper for constructing the pagination links.

Credits

Who’s who?

Get out clause

Right now this script is provided without warranty, or support from the author.

Creative Commons License

Creative Commons License

Will Paginate Liquidized by Matthew Hutchinson is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.