Swiftpack.co - finestructure/fs-html as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by finestructure.
finestructure/fs-html 0.0.1
A Swift DSL to generate HTML for use in server side swift projects - or anywhere you want to write type checked HTML.
⭐️ 1
🕓 5 years ago
.package(url: "https://github.com/finestructure/fs-html.git", from: "0.0.1")

FSHtml

FSHtml is a Swift DSL to generate HTML for use in server side swift projects - or anywhere you want to write type checked HTML.

This package is inspired by Brandon Williams' series on type-safe HTML in Swift.

With FSHtml you can write the following swift code, closely resembling HTML:

func homePage(title: String) -> Node {
    return
        .html([.lang => "en"], [
            .head([
                .meta([.charset => "utf-8"]),
                .meta([.name => "viewport",
                    .content => "width=device-width, initial-scale=1, shrink-to-fit=no"]),
                .link([.rel => "stylesheet",
                    .href => "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css",
                    .integrity => "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO",
                    .crossorigin => "anonymous"]),
                .title(title)
            ]),
            .body([
                .h1([.text(title)]),
                .p("FS HTML is a Swift DSL to generate HTML for use in server side swift projects - or anywhere you want to write type checked HTML.")
            ])
    ])
}

and the render it into actual HTML:

let node = homePage(title: "Hello World 🌍")
let html = render(node)    // -> "<!DOCTYPE HTML> ..."
let size = CGSize(width: 800, height: 600)
let webView = WKWebView(frame: .init(origin: .zero, size: size))
webView.loadHTMLString(html, baseURL: nil)

producing the following rendered screenshot:

Rendered HML

This snapshot is generated as part of the package tests.

GitHub

link
Stars: 1
Last commit: 5 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

initial release
5 years ago

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