Swiftpack.co -  bdrelling/PlotVapor as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
bdrelling/PlotVapor
A library for easily bridging Plot-generated HTML into Vapor.
.package(url: "https://github.com/bdrelling/PlotVapor.git", from: "0.1.0")

PlotVapor

PlotVapor is a small package that allows easily rendering Plot-generated HTML within the Vapor server-side Swift web framework.

Usage

Fortunately, usage is straight-forward as this library only adds a few extension methods to keep things really simple.

Below, we add a new route for the /home path within the configureRoutes(_:) method and render a sample HTML object that doesn't do anything fancy.

func configureRoutes(_ app: Application) throws {
    app.get("home") { req -> EventLoopFuture<View> in
        let html = HTML(
            .head(
                .title("My website"),
                .stylesheet("styles.css")
            ),
            .body(
                .div(
                    .h1("My website"),
                    .p("Writing HTML in Swift is pretty great!")
                )
            )
        )
        
        return req.plot.render(html)
    }
}

Minification

By default, all HTML is minified before it is rendered. To modify this behavior, use the identedBy parameter to pass an Indentation.Kind.

func configureRoutes(_ app: Application) throws {
    app.get("home") { req -> EventLoopFuture<View> in
        let html = HTML(
            // elements, etc.
        )
        
        return req.plot.render(html, indentedBy: .spaces(2))
    }
}

GitHub

link
Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API