Skip to content

Commit e4e05f7

Browse files
Merge pull request #1 from sliemeobn/update-elementary-benchmark
More idiomatic elmentary benchmark code
2 parents 3cc427f + 1ecf031 commit e4e05f7

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Benchmarks/Benchmarks/Elementary/Elementary.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,31 @@ package struct ElementaryTests : HTMLGenerator {
1414
package func staticHTML() -> String {
1515
StaticView().render()
1616
}
17+
1718
package func dynamicHTML(_ context: HTMLContext) -> String {
18-
DynamicView(context: context).rawHTML.render()
19+
DynamicView(context: context).render()
1920
}
2021
}
2122

22-
struct StaticView : HTMLDocument {
23-
var title:String = "StaticView"
24-
25-
var head : some HTML {
26-
""
27-
}
28-
var body : some HTML {
29-
h1 { "Swift HTML Benchmarks" }
23+
struct StaticView: HTML {
24+
var content: some HTML {
25+
HTMLRaw("<!DOCTYPE html>")
26+
html {
27+
head {
28+
title { "StaticView" }
29+
}
30+
body {
31+
h1 { "Swift HTML Benchmarks" }
32+
}
33+
}
3034
}
3135
}
3236

33-
struct DynamicView {
37+
struct DynamicView: HTML {
3438
let context:HTMLContext
3539

3640
// Elementary puts the title element first in the head, which is wrong; it needs to be charset | this is a workaround
37-
@HTMLBuilder var rawHTML : some HTML {
41+
var content : some HTML {
3842
HTMLRaw("<!DOCTYPE html>")
3943
html {
4044
head {
@@ -45,12 +49,12 @@ struct DynamicView {
4549
}
4650
body {
4751
h1 { context.heading }
48-
div(attributes: [.id(context.desc_id)]) {
52+
div(.id(context.desc_id)) {
4953
p { context.string }
5054
}
5155
h2 { context.user.details_heading }
5256
h3 { context.user.qualities_heading }
53-
ul(attributes: [.id(context.user.qualities_id)]) {
57+
ul(.id(context.user.qualities_id)) {
5458
for quality in context.user.qualities {
5559
li { quality }
5660
}

0 commit comments

Comments
 (0)