Swiftpack.co - Package - BinaryBirds/viper-kit

ViperKit

VIPER module protocols for Vapor applications.

Install

Add the repository as a dependency:

.package(url: "https://github.com/binarybirds/viper-kit.git", from: "1.3.0"),

Add ViperKit to the target dependencies:

.product(name: "ViperKit", package: "viper-kit"),

Update the packages and you are ready.

Configuration

You can enable modular view directories for the Leaf template engine through ViperKit by calling useViperViews().

The #extend("Example/MyView") or render("Example/MyView") snippets will look for views under the following places:

  • Resources/Views/Example/MyView.leaf
  • Sources/App/Modules/Example/Views/MyView.leaf

You can override the modulesDirectory if you are using a custom structure, default value is "Sources/App/Modules".

Here's an example configuration:

import ViperKit

public func configure(_ app: Application) throws {
    //...

    app.views.use(.leaf)
    app.leaf.useViperViews()

    //app.leaf.useViperViews(modulesDirectory: "Sources/App/Modules")

    let modules: [ViperModule] = [
        ExampleModule(),
    ]

    try app.viper.use(modules)
}

You'll have to configure all the modules that you'd like to use.

Modules

A module can return:

  • a router
  • migrations
  • a command group
  • a lifecycle handler
  • middlewares
  • leaf tags

Basic example:

import ViperKit

final class ExampleModule: ViperModule {

    static var name: String = "example"

    var router: ViperRouter? = ExampleRouter()
}

Router:

import ViperKit

struct ExampleRouter: ViperRouter {
    
    func boot(routes: RoutesBuilder, app: Application) throws {
        routes.get { _ in "Hello ViperKit!" }
    }
}

License

WTFPL - Do what the fuck you want to.

Github

link
Stars: 5

Used By

Total: 0

Releases

- 2020-08-29 13:19:38

  • views url
  • SPM tools v5.3

- 2020-08-29 12:24:56

  • Request is optional for sync hooks

- 2020-08-23 11:51:31

  • required init for the viper builder protocol
  • updated Makefile
  • updated SPM dependencies

- 2020-07-18 12:03:41

  • module priority
  • sync hooks

- 2020-07-11 08:48:18

  • added boot function

- 2020-06-20 12:30:01

  • Updated dependency: Vapor 4.10.0
  • Updated dependency: Fluent 4.0.0
  • Updated dependency: Leaf 4.0.0-rc.1.3
  • ViperViewFiles support for the new LeafSource protocol

- 2020-06-17 20:39:10

  • path components on modules & models
  • content filters
  • default boot implementation on routers

- 2020-06-09 11:45:24

  • better viper view files

- 2020-05-02 22:07:47

  • removed dynamic library

- 2020-05-02 20:24:56

  • removed unnecessary imports

- 2020-05-01 09:27:38

  • New router API with hook support
  • ViperMigration with version and priority support
  • Example module for upcoming test cases

- 2020-04-26 13:19:45

  • removed unused properties

- 2020-04-26 11:36:11

  • removed view related files, check: https://github.com/BinaryBirds/view-kit

- 2020-04-23 08:09:45

  • Application storage for VIPER
  • ArrayFormField support

First version - 2020-04-22 21:28:59