Skip to content

Commit bb5e2ea

Browse files
update README to include recent additions
1 parent 21ca726 commit bb5e2ea

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Write HTML using Swift Macros.
33
<a href="https://swift.org"><img src="https://img.shields.io/badge/Swift-5.9+-orange" alt="Requires at least Swift 5.9"></a> <img src="https://img.shields.io/badge/Platforms-Any-gold"> <a href="https://github.com/RandomHashTags/swift-htmlkit/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue" alt="Apache 2.0 License">
44

55
- [Why](#why)
6-
- [Examples](#examples)
6+
- [Usage](#usage)
77
- [Basic](#basic)
88
- [Advanced](#advanced)
99
- [Benchmarks](#benchmarks)
@@ -17,7 +17,7 @@ Write HTML using Swift Macros.
1717
- Alternative libraries may not fit all situations and may restrict how the html is generated, manipulated, prone to human error, or cost a constant performance overhead (middleware, rendering, result builders, etc)
1818
- HTML macros enforce safety, can be used anywhere, and compile directly to strings
1919
- The output is minified at no performance cost
20-
## Examples
20+
## Usage
2121
### Basic
2222
<details>
2323
<summary>How do I use this library?</summary>
@@ -83,6 +83,9 @@ If you know the data **at compile time** (and not working with HTML macros):
8383
- `#escapeHTML()` macro
8484

8585
If you're working with **runtime** data:
86+
87+
> \>\>\> !! You need to `import HTMLKitUtilities` to use these functions !! <<<
88+
8689
- `<string>.escapeHTML(escapeAttributes:)`
8790
- mutates `self` escaping HTML and, optionally, attribute characters
8891
- `<string>.escapeHTMLAttributes()`
@@ -172,6 +175,19 @@ Use the `HTMLElementAttribute.event(<type>, "<value>")`.
172175
```
173176
</details>
174177

178+
<details>
179+
<summary>I need the output as a different type!</summary>
180+
181+
Use a different html macro. Currently supported types (more to come with new language features):
182+
- `#html()` -> `String`/`StaticString`
183+
- `#htmlUTF8Bytes()` -> `[UInt8]`
184+
- `#htmlUTF16Bytes()` -> `[UInt16]`
185+
- `#htmlUTF8CString()` -> `ContiguousArray<CChar>`
186+
- `#htmlData()` -> `Foundation.Data`
187+
- `#htmlByteBuffer()` -> `NIOCore.ByteBuffer`
188+
189+
</details>
190+
175191
## Benchmarks
176192
- Libraries tested
177193
- [BinaryBuilds/swift-html](https://github.com/BinaryBirds/swift-html) v1.7.0 (patched version [here](https://github.com/RandomHashTags/fork-bb-swift-html))

Tests/HTMLKitTests/HTMLKitTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import struct Foundation.Data
1616
import struct NIOCore.ByteBuffer
1717
#endif
1818

19+
// MARK: Escaping HTML
1920
struct HTMLKitTests {
2021
@Test func escape_html() {
2122
let unescaped:String = "<!DOCTYPE html><html>Test</html>"
@@ -46,6 +47,7 @@ struct HTMLKitTests {
4647
}
4748
}
4849

50+
// MARK: Representations
4951
extension HTMLKitTests {
5052
func representations() {
5153
let _:StaticString = #html()
@@ -90,6 +92,7 @@ extension HTMLKitTests {
9092
#endif
9193
}
9294

95+
// MARK: Element tests
9396
extension HTMLKitTests {
9497
@Test func element_html() {
9598
var string:StaticString = #html()
@@ -238,6 +241,7 @@ extension HTMLKitTests {
238241
}
239242
}
240243

244+
// MARK: Misc element tests
241245
extension HTMLKitTests {
242246
@Test func recursive_elements() {
243247
let string:StaticString = #div(
@@ -303,6 +307,7 @@ extension HTMLKitTests {
303307
}*/
304308
}
305309

310+
// MARK: Attribute tests
306311
extension HTMLKitTests {
307312
@Test func attribute_data() {
308313
let string:StaticString = #div(attributes: [.data("id", "5")])
@@ -328,6 +333,7 @@ extension HTMLKitTests {
328333
}
329334
}
330335

336+
// MARK: 3rd party tests
331337
extension HTMLKitTests {
332338
enum Shrek : String {
333339
case isLove, isLife
@@ -371,6 +377,7 @@ extension HTMLKitTests {
371377
}
372378
}
373379

380+
// MARK: StaticString Example
374381
extension HTMLKitTests {
375382
@Test func example_1() {
376383
let test:StaticString = #html(
@@ -401,6 +408,7 @@ extension HTMLKitTests {
401408
}
402409
}
403410

411+
// MARK: Dynamic test
404412
extension HTMLKitTests {
405413
@Test func dynamic() {
406414
let charset:String = "utf-8", title:String = "Dynamic"
@@ -429,6 +437,7 @@ extension HTMLKitTests {
429437
}
430438
}
431439

440+
// MARK: Example2
432441
extension HTMLKitTests {
433442
@Test func example2() {
434443
var test:TestStruct = TestStruct(name: "one", array: ["1", "2", "3"])

0 commit comments

Comments
 (0)