Skip to content
☁️ Kitura plugin for type-safe, transformable HTML views.
Branch: master
Clone or download
stephencelis Swift 5 (#3)
* Swift 5

* Tag 0.3.0

* Fix snippet

* Interpolate
Latest commit 63c20b8 Mar 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources Swift 5 (#3) Mar 26, 2019
Tests Type-safe Kitura HTML Sep 13, 2018
.gitignore Type-safe Kitura HTML Sep 13, 2018
.swift-version Swift 5 (#3) Mar 26, 2019
.travis.yml Type-safe Kitura HTML Sep 13, 2018
CODE_OF_CONDUCT.md Type-safe Kitura HTML Sep 13, 2018
Dockerfile Swift 5 (#3) Mar 26, 2019
LICENSE Swift 5 (#3) Mar 26, 2019
Makefile Type-safe Kitura HTML Sep 13, 2018
Package.resolved Swift 5 (#3) Mar 26, 2019
Package.swift Swift 5 (#3) Mar 26, 2019
README.md Swift 5 (#3) Mar 26, 2019

README.md

swift-html-kitura

Swift 5 Linux CI @pointfreeco

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

Motivation

The most popular choice for rendering HTML in a Kitura web app is to use the Stencil 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 HtmlKituraSupport
import Kitura

let router = Router()

router.get("/") { request, response, next in
  response.send(
    Node.h1("Hello, type-safe HTML on Kitura!")
  )
  next()
}

Kitura.addHTTPServer(onPort: 8080, with: router)
Kitura.run()

Take it for a spin

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

  • swift run HtmlKituraSupportExample
  • 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-kitura
  • cd swift-html-kitura
  • make xcodeproj
  • Select the HtmlKituraSupportExample target
  • Build and run cmd+R
  • Open your browser to http://localhost:8080

Installation

If you want to use swift-html-kitura 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-kitura.git", from: "0.3.0")
]

Xcode Sub-project

Submodule, clone, or download swift-html-kitura, and drag HtmlKituraSupport.xcodeproj into your project.

License

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

You can’t perform that action at this time.