Git Product home page Git Product logo

leaf-paginator's Introduction

GFPaginator

Vapor 3. Leaf Bootstrap paginator. This package comes as an extension of the Pagination package.

Paginator with previous + current + next alt text

Paginator style hidden: alt text

Paginator style disable: alt text

Requirements

  1. Vapor 3. Documentation
  2. Bootstrap 4. Documentation
  3. Pagination 1. Documentation

Usage

Once set up, you can use it in your Leaf template files like any other tag:

#paginator(paginatorArgBox)

#paginator has one parameter, an object instantiate from struct GFPaginator.ArgumentBox.

You can configure the paging style by setting one of the two options (GFPaginator.StyleType):

  1. disabled: buttons (previous & next) will be disabled if previous & next are nil
  2. hidden: buttons (previous & next) will be hidden if previous & next are nil

Example how to use

controller.swift:

import Pagination
import GFPaginator

class UserController: RouteCollection {
...
  func indexHandler(_ req: Request) throws -> Future<View> {
    return try User.query(on: req).paginate(for: req).flatMap({ (users) in
      let paginatorArgBox = GFPaginator.ArgumentBox(users.page)
      let context = IndexContext(users: users, paginatorArgBox: paginatorArgBox)
      return try req.view().render("User/index", context)      
    })
  }
}

extension UserController {
  struct IndexContext: Encodable {
    let users: Paginated<User>
    let paginatorArgBox: GFPaginator.ArgumentBox
  }
}

index.leaf:

#paginator(paginatorArgBox)

Setup

Add as dependency

Add Leaf Markdown as a dependency in your Package.swift file:

dependencies: [
    ...,
    .package(url: "https://github.com/lupuandrei/leaf-paginator", from: "0.0.6")
]

Register with Leaf

To add the tag to Leaf, add it to your LeafTagConfig:

  var tags = LeafTagConfig.default()
  tags.use(GFPaginator(), as: GFPaginator.name)
  services.register(tags)

Note: it's important that you register the LeafProvider first otherwise this will override your LeafTagConfig.

Don't forget to import GFPaginator in the file you register the tag with import GFPaginator.

leaf-paginator's People

Watchers

James Cloos avatar Andrei Lupu 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.