Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robb/Swim
A DSL for writing HTML in Swift
https://github.com/robb/Swim
dsl html swift swift-5
Last synced: about 2 months ago
JSON representation
A DSL for writing HTML in Swift
- Host: GitHub
- URL: https://github.com/robb/Swim
- Owner: robb
- Created: 2019-06-08T20:29:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-07-12T12:05:12.000Z (over 2 years ago)
- Last Synced: 2024-08-06T12:07:59.179Z (5 months ago)
- Topics: dsl, html, swift, swift-5
- Language: Swift
- Homepage:
- Size: 218 KB
- Stars: 309
- Watchers: 4
- Forks: 9
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Swim – Swift Markup
A DSL for building HTML documents with Swift [function builders].
Currently in use on [my personal website].
```swift
import Swim
import HTMLlet myDocument = html(lang: "en-US") {
head {
meta(charset: "utf-8", content: "text/html", httpEquiv: "Content-Type")
}
body(customAttributes: [ "data-foo": "bar" ]) {
article(classes: "readme", "modern") {
header {
h1 {
"This is a great article."
}
}p {
"Hello World!"
br()
"How are you?"
}p {
"This is a"
a(href: "https://swift.org") { "link to the Swift website" }
"."
}
}
}
}
```By generating all words in the language according to the HTML specification, we can make sure that only valid HTML can be expressed.
For example, the above would generate this HTML:
```html
This is a great article.
Hello World!
How are you?
This is a
link to the Swift website
.
```
[function builders]: https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md
[my personal website]: http://github.com/robb/robb.swift