WingedSwift is an innovative Domain-Specific Language (DSL) library for efficient HTML writing in Swift. Mirroring its Python counterpart, WingedSwift is based on the DSL concept, focusing on simplification and specificity in HTML generation. Using the Composite design pattern, the library enables developers to construct HTML structures in a logical, organized, and reusable manner.
This library is created to be fully independent, not requiring integration with specific server frameworks or front-end libraries. This offers developers the freedom to use WingedSwift across a variety of projects, from simple static pages to complex web applications, keeping the code clean, readable, and efficient.
To add WingedSwift to your project, add the following line to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/micheltlutz/Winged-Swift.git", from: "1.2.2")
]
And include WingedSwift
as a dependency in your target:
targets: [
.target(
name: "YourTarget",
dependencies: ["WingedSwift"]),
]
To include in Vapor project use this line code in executableTarget
.
.product(name: "WingedSwift", package: "Winged-Swift")
WingedSwift allows you to build HTML documents using a DSL syntax in Swift. Here are some examples of how to use the library.
import WingedSwift
let document = html {
Head(children: [
Meta(name: "description", content: "A description of the page"),
Link(href: "styles.css", rel: "stylesheet")
])
Body(children: [
Header(children: [
Nav(children: [
A(href: "#home", content: "Home"),
A(href: "#about", content: "About"),
A(href: "#contact", content: "Contact")
])
]),
Main(children: [
P(content: "Welcome to our website!")
]),
Footer(children: [
P(content: "© 2024 Company, Inc.")
])
])
}
print(document.render())
let form = Form(attributes: [Attribute(key: "action", value: "/submit")], children: [
Fieldset(children: [
Label(for: "name", content: "Name"),
Input(type: "text", name: "name")
]),
Fieldset(children: [
Label(for: "message", content: "Message"),
Textarea(name: "message")
]),
Input(type: "submit", name: "submit", value: "Send")
])
print(form.render())
let pre = Pre(content: """
This is preformatted text.
It preserves whitespace and line breaks.
""")
print(pre.render())
let code = Code(content: """
let x = 10
print(x)
""")
print(code.render())
let embed = Embed(src: "video.mp4", type: "video/mp4")
print(embed.render())
The complete documentation is available here soon.
To generate the DocC documentation, use the following command in the terminal:
swift package generate-documentation --target WingedSwift --output-path ./docs
open ./docs/index.html
swift package --disable-sandbox preview-documentation --target WingedSwift
Contributions are welcome! Please follow the steps below to contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature/new-feature
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/new-feature
) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for more details.