Giter Site home page Giter Site logo

ceritium / will_paginate-liquidized Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tronfu/will_paginate-liquidized

0.0 3.0 1.0 597 KB

Rails plugin for using will_paginate with liquid templating

Home Page: http://matthewhutchinson.net

Ruby 100.00%

will_paginate-liquidized's Introduction

Will Paginate Liquidized

About

This fork updates the will_paginate-liquidized plugin to work with WillPaginate 3.0.

Caveats

Changes to the original:

  • the liquid method has been renamed to will_paginate from will_paginate_liquid.

Ongoing issues with this project include:

  • currently has only been tested within my own project running Rails 3.0.3. needs further testing on 2.2.x and 2.3.×.

Setup / Using

Requirements

What do you need?

Installing

Rails 2:

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

Rails 3:

rails plugin install https://github.com/tronfu/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 }}").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 : '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.

will_paginate-liquidized's People

Contributors

ceritium avatar matthutchinson avatar tronfu avatar

Watchers

 avatar  avatar  avatar

Forkers

storenvy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.