{"id":15405145,"url":"https://github.com/fnando/paginate","last_synced_at":"2025-04-16T22:50:35.298Z","repository":{"id":56887285,"uuid":"704211","full_name":"fnando/paginate","owner":"fnando","description":"Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.","archived":false,"fork":false,"pushed_at":"2016-04-05T14:37:46.000Z","size":69,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T05:41:40.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-06-05T00:38:04.000Z","updated_at":"2019-06-22T05:13:59.000Z","dependencies_parsed_at":"2022-08-20T16:00:07.352Z","dependency_job_id":null,"html_url":"https://github.com/fnando/paginate","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpaginate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpaginate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpaginate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpaginate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/paginate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249284471,"owners_count":21243966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T16:15:13.502Z","updated_at":"2025-04-16T22:50:35.281Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Paginate\n\n[![Build Status](https://travis-ci.org/fnando/paginate.png)](https://travis-ci.org/fnando/paginate)\n[![CodeClimate](https://codeclimate.com/github/fnando/paginate.png)](https://codeclimate.com/github/fnando/paginate/)\n[![Test Coverage](https://codeclimate.com/github/fnando/paginate/badges/coverage.svg)](https://codeclimate.com/github/fnando/paginate/coverage)\n[![Gem](https://img.shields.io/gem/v/paginate.svg)](https://rubygems.org/gems/paginate)\n[![Gem](https://img.shields.io/gem/dt/paginate.svg)](https://rubygems.org/gems/paginate)\n\nPaginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.\n\n## Install\n\n```bash\ngem install paginate\n```\n\n## Usage\n\nYou can use Paginate with or without ActiveRecord. Let's try a simple array pagination. Imagine that you have something like this in your controller.\n\n```ruby\n@things = Array.new(11) {|i| \"Item #{i}\"}\n```\n\nThen on your view:\n\n```erb\n\u003c%= paginate @things %\u003e\n```\n\nThat's it! This is all you have to do! In this case we're using the default page size (which is 10).\nThe url used on page links is taken from the current requested uri.\n\nYou can set default values globally:\n\n```ruby\nPaginate.configure do |config|\n  config.size = 20\n  config.param_name = :p\nend\n```\n\nMore examples:\n\n```ruby\nPost.paginate(1)                                # page 1 from Post model\nPost.paginate(page: 1)                          # page 1 from Post model\nPost.paginate(page: 1, size: 5)                 # page 1 from Post model with custom size\n@user.things.paginate(:page =\u003e params[:page])   # paginate association\n```\n\n```erb\n\u003c%= paginate @things, size: 5 %\u003e\n\u003c%= paginate @things, url: -\u003e page { things_path(:page =\u003e page) } %\u003e\n\u003c%= paginate @things, \"/some/path\" %\u003e\n\u003c%= paginate @things, param_name: :p %\u003e\n```\n\nTo render the collection, you must use the \u003ctt\u003erender\u003c/tt\u003e helper, providing the \u003ctt\u003e:paginate =\u003e true\u003c/tt\u003e option. This is required cause we're always considering SIZE + 1, so if you use the regular +each+ or don't pass this option, you end up rendering one additional item.\n\n```erb\n\u003c%= render @things, paginate: true %\u003e\n\u003c%= render @things, paginate: true, size: 5 %\u003e\n\u003c%= render \"thing\", collection: @things, paginate: true, size: 5 %\u003e\n```\n\n## I18n support\n\nIf you want to translate links, you have implement the following scopes:\n\n```yaml\nen:\n  paginate:\n    next: \"Older\"\n    previous: \"Newer\"\n    page: \"Page %{page}\"\n    more: \"Load more\"\n```\n\n## Styling\n\nIf you want something like Twitter Search use this CSS:\n\n```css\n.paginate { overflow: hidden; }\n.paginate li { float: left; }\n.paginate li.previous-page:after { content: \"«\"; padding: 0 5px; }\n.paginate li.next-page:before { content: \"»\"; padding: 0 5px; }\n.paginate .disabled { display: none; }\n```\n\nYou can create new renderers. Paginate comes with two renderers.\n\n* `Paginate::Renderer::List`: is the default renderer. Uses a `\u003cul\u003e` with previous and next page. Also displays the current page.\n* `Paginate::Renderer::More`: define a \"Load more\" page. This is useful for renderer pagination through AJAX.\n\nTo create a new renderer, just inherit from `Paginate::Renderer::Base` and define the `render` method. Here's the `Paginate::Renderer::More` code:\n\n```ruby\nmodule Paginate\n  module Renderer\n    class More \u003c Base\n      def more_label\n        I18n.t(\"paginate.more\")\n      end\n\n      def render\n        return unless processor.next_page?\n\n        \u003c\u003c-HTML.html_safe\n          \u003cp class=\"paginate\"\u003e\n            \u003ca class=\"more\" href=\"#{next_url}\" title=\"#{more_label}\"\u003e#{more_label}\u003c/a\u003e\n          \u003c/p\u003e\n        HTML\n      end\n    end\n  end\nend\n```\n\nYou can specify the default renderer by setting the `Pagination.configuration.renderer` option.\n\n```ruby\nPaginate.configure do |config|\n  config.renderer = Paginate::Renderer::More\nend\n```\n\nYou can also specify while calling the `paginate` helper.\n\n```erb\n\u003c%= paginate @items, renderer: Paginate::Renderer::More %\u003e\n```\n\n## License\n\n(The MIT License)\n\nCopyright - Nando Vieira • \u003chttp://nandovieira.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpaginate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fpaginate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpaginate/lists"}