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 functions

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: 7

Dependencies

Used By

Total: 0

Releases

viper leaf scopes middleware -

Leaf data generator protocol -

Bundled Leaf source -

Bundle & sample support -

Routes hook fix -

Public invoke hooks for leaf -

Default boot for routers -

Brand new hook functions -

macOS 10_15 support... this time for real. -

macOS 10_15 support -

ViperInstaller, BundleFinder, LeafSources, removed unnecessary self -

Leaf Tau fixes -

  • macOS 11 platform
  • Fixed Leaf Tau version
  • Vapor version bump

Version bump -

-

Leaf dep update -

Leaf Tau updates -

-

  • views url
  • SPM tools v5.3

-

  • Request is optional for sync hooks

-

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

-

  • module priority
  • sync hooks

-

  • added boot function

-

  • 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

-

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

-

  • better viper view files

-

  • removed dynamic library

-

  • removed unnecessary imports

-

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

-

  • removed unused properties

-

-

  • Application storage for VIPER
  • ArrayFormField support