Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sahandnayebaziz/Hypertext
Any-way-you-want-it, type-safe HTML in Swift.
https://github.com/sahandnayebaziz/Hypertext
dsl html markup server server-side-swift swift type-safe
Last synced: 25 days ago
JSON representation
Any-way-you-want-it, type-safe HTML in Swift.
- Host: GitHub
- URL: https://github.com/sahandnayebaziz/Hypertext
- Owner: sahandnayebaziz
- License: mit
- Archived: true
- Created: 2016-10-29T20:46:20.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-23T03:01:06.000Z (about 7 years ago)
- Last Synced: 2024-10-31T15:44:05.282Z (about 1 month ago)
- Topics: dsl, html, markup, server, server-side-swift, swift, type-safe
- Language: Swift
- Homepage:
- Size: 2.03 MB
- Stars: 232
- Watchers: 9
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- TheList - Hypertext - Any-way-you-want-it, type-safe HTML in Swift (Utility / Strings)
README
![header](header.jpg)
Compose valid HTML in Swift any way you want to.
### Usage
````swift
import Hypertext
title { "hello world." }.render()
// hello world.head { title { "hello world." } }.render()
// hello world.head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
//
//
// hello world.
//
//````
### Requirements
- Swift 3.0+### Full usage
1. Rendering a tag
```swift
div().render()
//```
2. Rendering a tag with child text```swift
div { "hello world." }.render()
//hello world.
```
3. Rendering a tag with a child tag```swift
div { img() }.render()
//
```
4. Rendering a tag with multiple child tags```swift
div { [img(), img(), img()] }.render()
//
```
5. Rendering a tag with attributes```swift
link(["rel": "stylesheet", "type":"text/css", "href":"./style.css"]).render()
//
```
6. Rendering a tag with attributes and children```swift
div(["class": "container"]) { "hello world." }
//hello world.
```7. Rendering a doctype declaration
```swift
doctype(.html5).render()
//
```8. Rendering unminified, with newlines and indentation
```swift
head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
//
//
// hello world.
//
//
```
9. Rendering a tag in a novel way, any way you want to```swift
func createTitleTag(forPageNamed pageName: String) -> title {
return title { "Hypertext - \(pageName)" }
}
head { createTitleTag(forPageNamed: "Documentation") }.render()
// Hypertext - Documentation
```
10. Rendering a custom tag```swift
public class myNewTag: tag {
override public var isSelfClosing: Bool {
return true
}
}myNewTag().render()
//```
11. Rendering a custom type by adopting the protocol `Renderable````swift
extension MyType: Renderable {
public func render() -> String { ... }
public func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String { ... }
}```