Compose valid HTML in Swift any way you want to.
Usage
import Hypertext
title { "hello world." }.render()
// hello world.
head { title { "hello world." } }.render()
// hello world.
head { title { "hello world." } }.render(startingWithSpacesCount: 0)
//
//
// hello world.
//
//
Requirements
- Swift 3.0+
Full usage
Rendering a tag
div().render() //Rendering a tag with child text
div { "hello world." }.render() //hello world.Rendering a tag with a child tag
div { img() }.render() //Rendering a tag with multiple child tags
div { [img(), img(), img()] }.render() //Rendering a tag with attributes
link(attributes: ["rel": "stylesheet", "type":"text/css", "href":"./style.css"]).render() //Rendering unminified, with newlines and two-space indentation
head { title { "hello world." } }.render(startingWithSpacesCount: 0) // // // hello world. // //Rendering a tag in a novel way, any way you want to
func createTitleTag(forPageNamed pageName: String) -> title { return title { "Hypertext - \(pageName)" } } head { createTitleTag(forPageNamed: "Documentation") }.render() // Hypertext - DocumentationRendering a custom tag
public class myNewTag: tag { override public init(setChildren: (() -> Renderable?)) { super.init(setChildren: setChildren) name = "myNewTag" isSelfClosing = true } } myNewTag().render() //Rendering a custom type by adopting the protocol
Renderableextension MyType: Renderable { public func render() -> String { } public func render(startingWithSpacesCount: Int) -> String { } }