{"id":22371288,"url":"https://github.com/dcalixto/cry_paginator","last_synced_at":"2025-07-30T05:32:51.636Z","repository":{"id":266326155,"uuid":"897999560","full_name":"dcalixto/cry_paginator","owner":"dcalixto","description":"A simple, flexible, and high-performance paginate pagination library for Crystal inspired by Ruby's Pagy gem.","archived":false,"fork":false,"pushed_at":"2024-12-22T00:55:37.000Z","size":398,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T16:53:01.637Z","etag":null,"topics":["crystal","crystal-lang","paginate","pagination"],"latest_commit_sha":null,"homepage":"https://github.com/dcalixto/cry_paginator","language":"Crystal","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/dcalixto.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-03T15:58:43.000Z","updated_at":"2024-12-22T00:55:41.000Z","dependencies_parsed_at":"2024-12-03T18:31:07.866Z","dependency_job_id":"3e76295d-c842-40be-82de-1bf2e75ed283","html_url":"https://github.com/dcalixto/cry_paginator","commit_stats":null,"previous_names":["dcalixto/cry_paginator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dcalixto/cry_paginator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcalixto%2Fcry_paginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcalixto%2Fcry_paginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcalixto%2Fcry_paginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcalixto%2Fcry_paginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcalixto","download_url":"https://codeload.github.com/dcalixto/cry_paginator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcalixto%2Fcry_paginator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267815187,"owners_count":24148356,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["crystal","crystal-lang","paginate","pagination"],"created_at":"2024-12-04T20:18:40.402Z","updated_at":"2025-07-30T05:32:51.607Z","avatar_url":"https://github.com/dcalixto.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cry_paginator\n\nA simple, flexible, and high-performance pagination library for Crystal inspired by Ruby's Pagy gem.\n\n[![Crystal Test](https://github.com/dcalixto/cry_paginator/actions/workflows/crystal-test.yml/badge.svg?branch=master)](https://github.com/dcalixto/cry_paginator/actions/workflows/crystal-test.yml)\n\n## Features\n\n- Lightweight and fast\n- Configurable pagination options\n- Support for SQL queries with `crystal-db`\n- Dynamic pagination window with gaps\n- Methods for checking first/last page and navigating between pages\n- Type-safe Crystal implementation\n\n## Installation\n\nAdd the shard to your `shard.yml`:\n\n```yaml\ndependencies:\n  cry_paginator:\n    github: dcalixto/cry_paginator\n```\n\nThen, run shards install.\n\n## Usage\n\n- Include Paginator in Your Model\n\n- To enable pagination on a model, include the Paginator module in your model class:\n\n```crystal\n# src/models/post.cr\nrequire \"cry_paginator\"\nclass Post\n\n  include DB::Serializable\n  include Paginator\n  include Paginator::Model\n\nend\n```\n\n## Paginate Your Data\n\nUse the paginate method to fetch paginated records:\n\n```crystal\n# Access pagination data\npaginator.items          # Current page items\npaginator.total          # Total number of items\npaginator.total_pages    # Total number of pages\npaginator.current_page   # Current page number\npaginator.next_page      # Next page number or nil\npaginator.prev_page      # Previous page number or nil\n\n# Custom Page Window\npaginator.page_window(7) # Example output: [1, :gap, 5, 6, 7, 8, :gap, 20]\n\n```\n\n## Configuration\n\nOverride the defaults globally in your app:\n\n```crystal\n\nPaginator.config = {\n  per_page: 20,\n  window_gap: true,\n  window_size: 2\n  order_by: \"created_at DESC\"\n}\n```\n\nOr override them for individual calls:\n\n```crystal\nPage.paginate(page: 2, per_page: 20, order_by: \"created_at DESC\")\n```\n\n## Dynamic Pagination Window\n\nYou can now use the pagination with or without window gaps:\n\n```crystal\n# Without window gap (default)\nposts = Post.paginate(db, page: 1)\n\n# With window gap\nposts = Post.paginate(db, page: 1, window_gap: true)\n\n# With custom window size\nposts = Post.paginate(db, page: 1, window_gap: true, window_size: 3)\n\n```\n\n## Controller Setup\n\nThe controller retrieves paginated data from the database using the Paginator shard.\n\n_Example: ArticlesController (Kemal Framework)_\n\n```crystal\n# src/controllers/posts_controller.cr\nclass PostsController\n  include Paginator::Backend\n  include Paginator::ViewHelper\n\n  def index\n    page = (env.params.query[\"page\"]? || \"1\").to_i\n    per_page = 12\n\n    paginator = Post.paginate(\n      page: page,\n      per_page: per_page,\n      order: \"created_at DESC\"\n    )\n\n    posts = paginator.items\n\n    render \"src/views/posts/index.ecr\"\n  end\nend\n\n```\n\n## Integration in Views\n\nUse the data provided by the controller to render paginated content and navigation links.\n\n_Example Usage in a Kemal View (index.ecr)_\n\n```crystal\n\u003cdiv class=\"posts\"\u003e\n  \u003c% posts.each do |post| %\u003e\n    \u003carticle\u003e\n      \u003ch2\u003e\u003c%= post.title %\u003e\u003c/h2\u003e\n      \u003cp\u003e\u003c%= post.content %\u003e\u003c/p\u003e\n    \u003c/article\u003e\n  \u003c% end %\u003e\n\u003c/div\u003e\n\n\u003c%= pagination_info(paginator, \"posts\") if paginator %\u003e\n\u003c%= pagination_nav(paginator) if posts %\u003e\n\n\n```\n\n_Example Output_\nNavigation Links\n\n```crystal\n#TODO\n```\n\n**Info**\n\n```crystal\n\u003cdiv class=\"pagination-info\"\u003e\n  Showing 11-20 of 100 articles.\n\u003c/div\u003e\n```\n\n## Styles for Pagination\n\nAdd some simple CSS to style the pagination links.\n\n```css\n/* public/css/pagination.css */\n.pagination-nav {\n  display: flex;\n  gap: 0.5rem;\n  list-style: none;\n  margin-bottom: 13rem;\n}\n.pagination ul li {\n  list-style: none;\n}\n.pagination ul \u003e li {\n  display: inline-block;\n  /* You can also add some margins here to make it look prettier */\n}\n.pagination-link {\n  text-decoration: none;\n}\n.pagination-link:hover {\n  text-decoration: underline;\n}\n.is-current {\n  font-weight: bold;\n}\n\n.is-disabled {\n  color: #aaa;\n  pointer-events: none;\n}\n\n.pagination-gap {\n  display: inline-block;\n  padding: 0.5rem;\n  color: #666;\n}\n\n.pagination {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 0.5rem;\n}\n\n.pagination-list {\n  display: flex;\n  list-style: none;\n  margin: 0;\n  padding: 0;\n  gap: 0.25rem;\n}\n\n.pagination-link.is-disabled {\n  opacity: 0.5;\n  pointer-events: none;\n}\n```\n\n## Testing\n\nUse spectator to write tests:\n\n_spec/paginator_spec.cr_\n\n```crystal\nrequire \"spec\"\nrequire \"../src/paginator\"\n\n\ndescribe Paginator do\n  it \"returns paginated data\" do\n    # Test logic here\n  end\nend\n```\n\nRun the tests:\n\n```crystal\ncrystal spec\n```\n\n## Contributing\n\n1. Fork it (https://github.com/dcalixto/cry_paginator/fork)\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## License\n\nThis shard is available as open source under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcalixto%2Fcry_paginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcalixto%2Fcry_paginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcalixto%2Fcry_paginator/lists"}