https://github.com/NicholasBellucci/Mongrel
Build declarative HTML in Swift.
https://github.com/NicholasBellucci/Mongrel
Last synced: about 1 month ago
JSON representation
Build declarative HTML in Swift.
- Host: GitHub
- URL: https://github.com/NicholasBellucci/Mongrel
- Owner: NicholasBellucci
- License: mit
- Created: 2021-07-17T21:37:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-10T00:39:57.000Z (almost 4 years ago)
- Last Synced: 2025-03-18T15:12:52.792Z (about 2 months ago)
- Language: Swift
- Size: 667 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-result-builders - Mongrel - Build declarative HTML in Swift. (HTML)
README
# Mongrel
Mongrel is a Swift and HTML hybrid with a bit of support for CSS and Javascript. Using a declaritive style of programming, Mongrel makes writing HTML feel natural and easy. Mongrel also uses a SwiftUI like body structure allowing structs to be completely dedicated as an HTML page or element.
## Requirements
Xcode 12.x or a Swift 5.3x toolchain with Swift Package Manager.## Installation
### Swift Package Manager
In order to add Mongrel to your project, simply add `.package(url: "https://github.com/NicholasBellucci/mongrel.git", from: "0.1.0")` to your `Package.swift` file's `dependencies` and `.product(name: "Mongrel", package: "mongrel")` to the target `dependencies`.## Usage
Mongrel documentation is currently in the works but the project as a whole is complete, excluding future updates. To provide a very robust idea of how to use Mongrel, here is an example:
```swift
import Mongrelstruct IndexPage: HTML {
var title: String = "Welcome to Mongrel!"
var subtitle: String = "A Swift and HTML hybrid supporting:"var body: some HTMLConvertible {
Root(language: .en) {
Head {
Metadata(name: .applicationName, content: "Mongrel")
}Body {
Group {
Text(title)
.heading(.h1)Text(subtitle)
List(.unordered) {
Text("CSS")
.paragraph()Text("Javascript")
.paragraph()
}
.class("list")
}
}
.id("main-body")
.class("wrapper")
}
}
}/// The HTML protocol conforms to HTMLConvertible which conforms to
/// CustomStringConvertible and CustomDebugStringConvertible. This
/// means that to get the resulting HTML simply use String(describing: IndexPage()).print(IndexPage())
```
## LicenseMongrel is, and always will be, MIT licensed. See [LICENSE](LICENSE) for details.