-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #25.
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import SwiftSoup | ||
|
||
/// A view that defines the document's metadata container. | ||
/// | ||
/// Every web page starts with an HTML view. | ||
/// | ||
/// ```swift | ||
/// struct MySiteMetadata: View { | ||
/// var body: some View { | ||
/// Head { | ||
/// // Add document metadata here. | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [`head`](https://www.w3.org/TR/2012/WD-html-markup-20121025/head.html#head) specification. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public struct Head<Content>: View where Content: View { | ||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
self.content = content | ||
} | ||
|
||
@_documentation(visibility: private) | ||
public func render(_ container: Element, environment: EnvironmentValues) throws { | ||
let head = Element(.init("head"), "") | ||
try self.content().render(head, environment: environment) | ||
try container.addChildren(head) | ||
} | ||
|
||
private let content: () -> Content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct HeadTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(Head {}) == "<head></head>") | ||
} | ||
|
||
@Test func withText() throws { | ||
try #expect(renderHTML(HTML { | ||
Head { | ||
} | ||
}) == """ | ||
<html> | ||
<head></head> | ||
</html> | ||
""") | ||
} | ||
} |