Giter Site home page Giter Site logo

kerosene's Introduction

Kerosene

Pagination for Ecto and Phoenix.

Installation

The package is available in Hex, the package can be installed as:

Add kerosene to your list of dependencies in mix.exs:

def deps do
  [{:kerosene, "~> 0.5.0"}]
end

Add Kerosene to your repo.ex:

defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :testapp
  use Kerosene, per_page: 2
end

Usage

Start paginating your queries

def index(conn, params) do
  {products, kerosene} = 
  Product
  |> Product.with_lowest_price
  |> Repo.paginate(params)

  render(conn, "index.html", products: products, kerosene: kerosene)
end

Add view helpers to your view

defmodule MyApp.ProductView do
  use MyApp.Web, :view
  import Kerosene.HTML
end

Generate the links using the view helpers

<%= paginate @conn, @kerosene %>

Building apis or SPA's, no problem Kerosene has support for Json.

defmodule MyApp.ProductView do
  use MyApp.Web, :view
  import Kerosene.JSON

  def render("index.json", %{products: products, kerosene: kerosene, conn: conn}) do
    %{data: render_many(products, MyApp.ProductView, "product.json"),
      pagination: paginate(conn, kerosene)}
  end

  def render("product.json", %{product: product}) do
    %{id: product.id,
      name: product.name,
      description: product.description,
      price: product.price}
  end
end

You can also send in options to paginate helper look at the docs for more details.

Contributing

Please do send pull requests and bug reports, positive feedback is always welcome.

Acknowledgement

I would like to Thank

  • Matt (@mgwidmann)
  • Drew Olson (@drewolson)
  • Akira Matsuda (@amatsuda)

License

Please take a look at LICENSE.md

kerosene's People

Contributors

allyraza avatar kovpack avatar abdulsattar avatar justinaiken avatar

Watchers

Stanislav Mekhonoshin avatar James Cloos avatar

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.