Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit be3cfab

Browse files
authored
Implement function builder interface (#1)
* Initial implementation of DOM builder interface * Rename name parameter to target in PI initializer * Fix document XPath searching with namespaces Add test for parsing and searching XSD * Implement builder interface with XHTML 1.1 tags * Add .gitattributes * Run builder tests only on Swift >= 5.3 * Add Brewfile.lock.json * Add example usage for builder interface * Test on Swift 5.1, 5.2, and 5.3
1 parent 2778043 commit be3cfab

22 files changed

+5030
-21
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Resources/* linguist-vendored

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on: [push]
44

55
jobs:
66
macos:
7-
runs-on: macOS-latest
7+
runs-on: macos-latest
88

99
strategy:
1010
matrix:
11-
xcode: ["11.4", "11.3"]
11+
xcode: ["12", "11.7", "11.3"]
1212

1313
steps:
1414
- name: Checkout
@@ -26,7 +26,7 @@ jobs:
2626

2727
strategy:
2828
matrix:
29-
swift: ["5.2", "5.1"]
29+
swift: ["5.3", "5.2", "5.1"]
3030

3131
container:
3232
image: swift:${{ matrix.swift }}

Brewfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
brew "libxml2", link: true
1+
tap 'nshipster/formulae'
2+
brew 'gyb'
3+
4+
brew 'libxml2', link: true

Brewfile.lock.json

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"entries": {
3+
"tap": {
4+
"nshipster/formulae": {
5+
"revision": "c780bc082b3f89580849ba6a457c242ec9158b4a"
6+
}
7+
},
8+
"brew": {
9+
"gyb": {
10+
"version": "2019-01-18",
11+
"bottle": false
12+
},
13+
"libxml2": {
14+
"version": "2.9.10_2",
15+
"bottle": {
16+
"rebuild": 0,
17+
"cellar": ":any",
18+
"prefix": "/usr/local",
19+
"root_url": "https://homebrew.bintray.com/bottles",
20+
"files": {
21+
"arm64_big_sur": {
22+
"url": "https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.arm64_big_sur.bottle.tar.gz",
23+
"sha256": "c2e1bb939465a54e70ac4a6a8c333d00bc01a3738037f77cfd2227e47053ff47"
24+
},
25+
"big_sur": {
26+
"url": "https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.big_sur.bottle.tar.gz",
27+
"sha256": "0170a16da823ce77d1aad7db927b23a1adb12285a174f36a918275d7952eaaae"
28+
},
29+
"catalina": {
30+
"url": "https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.catalina.bottle.tar.gz",
31+
"sha256": "2983d5a448504389888720bf951713114ed7f010d96cde9289fdc5c4b539d303"
32+
},
33+
"mojave": {
34+
"url": "https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.mojave.bottle.tar.gz",
35+
"sha256": "7bcd780db5693475c7711eefbbcf703507865e06483e7338ab61027ec375c4bc"
36+
},
37+
"high_sierra": {
38+
"url": "https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.high_sierra.bottle.tar.gz",
39+
"sha256": "34d84eaef7f80632a6547903d640be06c6d92b9ca2b815b64b74943b4cf73e63"
40+
}
41+
}
42+
},
43+
"options": {
44+
"link": true
45+
}
46+
}
47+
}
48+
},
49+
"system": {
50+
"macos": {
51+
"catalina": {
52+
"HOMEBREW_VERSION": "3.0.10-46-g958b2ec",
53+
"HOMEBREW_PREFIX": "/usr/local",
54+
"Homebrew/homebrew-core": "acc12fd244cdc4664a57469a4ee7d2471bfc3f52",
55+
"CLT": "12.4.0.0.1.1610135815",
56+
"Xcode": "12.4",
57+
"macOS": "10.15.7"
58+
}
59+
}
60+
}
61+
}

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sources/HTML/HTMLTags.swift: Resources/xhtml11.xsd
2+
3+
%.swift: %.swift.gyb
4+
@gyb --line-directive '' -o $@ $<
5+
6+
.PHONY:
7+
clean:
8+
@rm Sources/HTML/HTMLTags.swift

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ based on [libxml2][libxml2].
2020
- [ ] XInclude Support*
2121
- [ ] XSLT Support*
2222
- [ ] SAX Parser Interface*
23-
- [ ] HTML and XML Function Builder Interfaces*
23+
- [x] HTML and XML Function Builder Interfaces
2424

2525
> \* Coming soon!
2626
@@ -133,6 +133,49 @@ document.body?.description // =>
133133
*/
134134
```
135135

136+
#### Builder Interface
137+
138+
Available in Swift 5.3+.
139+
140+
```swift
141+
import HTML
142+
143+
let document = HTML.Document {
144+
html(["lang": "en"]) {
145+
head {
146+
meta(["charset": "UTF-8"])
147+
title { "Hello, world!" }
148+
}
149+
150+
body(["class": "beautiful"]) {
151+
div(["class": "wrapper"]) {
152+
span { "Hello," }
153+
tag("span") { "world!" }
154+
}
155+
}
156+
}
157+
}
158+
159+
document.description // =>
160+
/*
161+
<html lang="en">
162+
<head>
163+
<meta charset="UTF-8">
164+
<title>Hello, world!</title>
165+
</head>
166+
<body class="beautiful">
167+
<?greeter start>
168+
<div class="wrapper">
169+
<span>Hello,</span>
170+
<span>world!</span>
171+
</div>
172+
<?greeter end>
173+
</body>
174+
</html>
175+
176+
*/
177+
```
178+
136179
## Installation
137180

138181
### Swift Package Manager

0 commit comments

Comments
 (0)