Swiftpack.co - pointfreeco/swift-html-vapor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by pointfreeco.
pointfreeco/swift-html-vapor 0.4.0
💧 Vapor plugin for type-safe, transformable HTML views.
⭐️ 82
🕓 2 years ago
macOS linux macOS iOS
.package(url: "https://github.com/pointfreeco/swift-html-vapor.git", from: "0.4.0")

swift-html-vapor

CI

Vapor plugin for type-safe, transformable HTML views using swift-html.

Motivation

The most popular choice for rendering HTML in a Vapor web app is to use the Leaf templating language, but it exposes your application to runtime errors and invalid HTML. Our plugin prevents these runtime issues at compile-time by embedding HTML directly into Swift’s powerful type system. It uses the swift-html DSL for constructing HTML documents using plain Swift data structures.

Usage

To use the plugin all you have to do is return a Node value from your router callback:

import HtmlVaporSupport
import Vapor

var env = try Environment.detect()
let app = Application(env)
defer { app.shutdown() }

app.get { _ in
  Node.h1("Hello, type-safe HTML on Vapor!")
}

try app.run()

Take it for a spin

We've included a sample Vapor application in this repo to show off its usage. To run the app immediately, simply do:

  • swift run HtmlVaporSupportExample
  • Open your browser to http://localhost:8080

The HTML for that page is constructed and rendered with swift-html!

If you want to run the app in Xcode so that you can play around with the HTML, try this:

  • git clone https://github.com/pointfreeco/swift-html-vapor
  • cd swift-html-vapor
  • make xcodeproj
  • Select the HtmlVaporSupportExample target
  • Build and run cmd+R
  • Open your browser to http://localhost:8080

Installation

If you want to use swift-html-vapor in a project that uses SwiftPM, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
  .package(url: "https://github.com/pointfreeco/swift-html-vapor", from: "0.4.0")
]

License

All modules are released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 82
Last commit: 32 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.4.0
2 years ago
  • Updated: Vapor 4 support (thanks @JaapWijnen)
  • Updated: swift-html 0.4.0 support

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