{"id":15010143,"url":"https://github.com/stephenmoloney/scrivener_list","last_synced_at":"2025-04-04T20:14:45.668Z","repository":{"id":57546414,"uuid":"53698173","full_name":"stephenmoloney/scrivener_list","owner":"stephenmoloney","description":"A Scrivener compatible extension that allows pagination of a list of elements.","archived":false,"fork":false,"pushed_at":"2025-02-24T18:33:18.000Z","size":66,"stargazers_count":29,"open_issues_count":0,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T19:11:24.417Z","etag":null,"topics":["elixir","paginate","pagination","scrivener","scrivener-ecto"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/scrivener_list","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephenmoloney.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-03-11T21:37:00.000Z","updated_at":"2025-02-24T14:02:16.000Z","dependencies_parsed_at":"2025-03-28T19:11:16.607Z","dependency_job_id":"b66b3f5a-fc91-457f-b339-fb8a7060e95e","html_url":"https://github.com/stephenmoloney/scrivener_list","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fscrivener_list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fscrivener_list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fscrivener_list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fscrivener_list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenmoloney","download_url":"https://codeload.github.com/stephenmoloney/scrivener_list/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242680,"owners_count":20907134,"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":["elixir","paginate","pagination","scrivener","scrivener-ecto"],"created_at":"2024-09-24T19:30:45.169Z","updated_at":"2025-04-04T20:14:45.643Z","avatar_url":"https://github.com/stephenmoloney.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scrivener.List\n[![Hex Version](http://img.shields.io/hexpm/v/scrivener_list.svg?style=flat)](https://hex.pm/packages/scrivener_list)\n[![Hex docs](http://img.shields.io/badge/hex.pm-docs-green.svg?style=flat)](https://hexdocs.pm/scrivener_list)\n\n[Scrivener.List](https://hex.pm/packages/scrivener_list) is a Scrivener compatible extension that\nallows the pagination of a list of elements.\n\n## Features\n\n1.  Scrivener.List extends the protocol `Scrivener.Paginater.paginate/2` from the [scrivener](https://github.com/drewolson/scrivener) library.\n1.  Scrivener.List also extends the function `MyApp.Repo.paginate/2` from the [scrivener_ecto](https://github.com/drewolson/scrivener_ecto) library.\n\nUsing the second feature is entirely optional. It's provided as a convenience where the [scrivener_ecto](https://github.com/drewolson/scrivener_ecto)\nlibrary is also being used in the project and gives access to the\npre-configured `MyApp.Repo` module.\n\n## Usage\n\n## 1. Usage without a Repo module\n\n```elixir\nScrivener.paginate(list, config)\n```\n\n### Arguments (without a repo)\n\n-   ```list```: A list of elements to be paginated\n\n-   ```config```: A configuration object with the pagination details.\n    Can be in any of the following formats:\n    -   ```%{page: page_number, page_size: page_size}``` (map)\n    -   ```[page: page_number, page_size: page_size]``` (Keyword.t)\n    -   ```%Scrivener.Config{page_number: page_number, page_size: page_size}``` (Scrivener.Config.t)\n\n`max_page_size` **cannot** be configured with method 1.\n\n### Examples\n\n```elixir\ndef index(conn, params) do\n  config = maybe_put_default_config(params)\n\n  page =\n    [\"C#\", \"C++\", \"Clojure\", \"Elixir\", \"Erlang\", \"Go\", \"JAVA\", \"JavaScript\", \"Lisp\",\n      \"PHP\", \"Perl\", \"Python\", \"Ruby\", \"Rust\", \"SQL\"]\n    |\u003e Enum.map(\u0026(\u00261 \u003c\u003e \"  \" \u003c\u003e \"language\"))\n    |\u003e Scrivener.paginate(config)\n\n  render conn, :index,\n    people: page.entries,\n    page_number: page.page_number,\n    page_size: page.page_size,\n    total_pages: page.total_pages,\n    total_entries: page.total_entries\nend\n\ndefp maybe_put_default_config(%{page: page_number, page_size: page_size} = params), do: params\ndefp maybe_put_default_config(_params), do: %Scrivener.Config{page_number: 1, page_size: 10}\n```\n\n```elixir\nlist = [\"C#\", \"C++\", \"Clojure\", \"Elixir\", \"Erlang\", \"Go\", \"JAVA\", \"JavaScript\", \"Lisp\",\n        \"PHP\", \"Perl\", \"Python\", \"Ruby\", \"Rust\", \"SQL\"]\n\nScrivener.paginate(list, %Scrivener.Config{page_number: 1, page_size: 4}) # %Scrivener.Config{}\nScrivener.paginate(list, page: 1, page_size: 4) # keyword list\nScrivener.paginate(list, %{page: 1, page_size: 4}) # map\nScrivener.paginate(list, %{page: 1}) # map with only page number (page_size defaults to 10)\n```\n\n## 2. Usage with a Repo module\n\nUsage without a Repo is entirely optional and is added to `Scrivener.List` for convenience.\nFirstly, see [Scrivener.Ecto](https://github.com/drewolson/scrivener_ecto) and configure the `MyApp.Repo` module.\n\n### Example Repo configuration\n\n```elixir\ndefmodule MyApp.Repo do\n  use Ecto.Repo,\n    otp_app: :my_app,\n    adapter: Ecto.Adapters.Postgres\n  use Scrivener,\n    page_size: 10,\n    max_page_size: 100\nend\n```\n\n```elixir\nMyApp.Repo.paginate(list, config)\n```\n\n### Arguments (with a repo)\n\n-   ```list```: A list of elements to be paginated\n\n-   ```config```: A configuration object with the pagination details.\n    Can be in any of the following formats:\n    -   ```%{page: page_number, page_size: page_size}``` (map)\n    -   ```[page: page_number, page_size: page_size]``` (Keyword.t)\n\n`max_page_size` **can** be configured with method 1. See [Scrivener.Ecto](https://github.com/drewolson/scrivener_ecto).\n\n### Example\n\nExample based on [scrivener_ecto](https://github.com/drewolson/scrivener_ecto) readme.\n\n```elixir\ndef index(conn, params) do\n  %{age: age, name: name} = params[\"search\"]\n\n  page = MyApp.Person\n  |\u003e where([p], p.age \u003e ^age)\n  |\u003e order_by([p], desc: p.age)\n  |\u003e preload(:friends)\n  |\u003e MyApp.Repo.all()\n  |\u003e Enum.filter(fn(person) -\u003e person.data.friend.name = name end)\n  |\u003e MyApp.Repo.paginate(params)\n\n  render conn, :index,\n    people: page.entries,\n    page_number: page.page_number,\n    page_size: page.page_size,\n    total_pages: page.total_pages,\n    total_entries: page.total_entries\nend\n```\n\n## Installation\n\nAdd [scrivener_list](https://hex.pm/packages/scrivener_list) to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:scrivener_list, \"~\u003e 2.1\"}\n  ]\nend\n```\n\n## Tests\n\n```shell\nMIX_ENV=test mix test\n```\n\n## Acknowledgements\n\nThe introduction of the [protocol](http://blog.drewolson.org/extensible-design-with-protocols/)\nfor scrivener enabled the separation of this package into it's own\nrepository.\n\n## Licence\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmoloney%2Fscrivener_list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenmoloney%2Fscrivener_list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmoloney%2Fscrivener_list/lists"}