File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Documentation.docc/Guides
W3C/Elements/DocumentMetadata
Tests/SlipstreamTests/W3C Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips
55
55
[ ` <link rel="stylesheet"> ` ] ( https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet ) | `` Stylesheet ``
56
56
[ ` <link rel="tag"> ` ] ( https://html.spec.whatwg.org/multipage/links.html#link-type-tag ) | [ Not implemented yet] ( https://github.com/jverkoey/slipstream/issues/25 )
57
57
[ ` <link rel="terms-of-service"> ` ] ( https://html.spec.whatwg.org/multipage/links.html#link-type-terms-of-service ) | [ Not implemented yet] ( https://github.com/jverkoey/slipstream/issues/25 )
58
- [ ` <meta> ` ] ( https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element ) | `` Meta ``
58
+ [ ` <meta> ` ] ( https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element ) | `` Meta ``
59
+ [ ` <meta http-equiv="refresh"> ` ] ( https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh ) | `` Redirect ``
59
60
[ ` <meta charset=""> ` ] ( https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-charset ) | `` Charset ``
60
61
[ ` <style=""> ` ] ( https://html.spec.whatwg.org/multipage/semantics.html#the-style-element ) | `` Stylesheet ``
61
62
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+
3
+ import SwiftSoup
4
+
5
+ /// A view that causes a page to redirect to another URL after a delay.
6
+ ///
7
+ /// - SeeAlso: W3C [http-equiv refresh](https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh) specification.
8
+ @available ( iOS 17 . 0 , macOS 14 . 0 , * )
9
+ public struct Redirect : View {
10
+ /// Creates a Redirect view.
11
+ public init ( _ url: URL ? , delay: TimeInterval = 0 ) {
12
+ self . url = url
13
+ self . delay = delay
14
+ }
15
+
16
+ @_documentation ( visibility: private)
17
+ public func render( _ container: Element , environment: EnvironmentValues ) throws {
18
+ guard let url else {
19
+ return
20
+ }
21
+ let element = try container. appendElement ( " meta " )
22
+ try element. attr ( " http-equiv " , " refresh " )
23
+ try element. attr ( " content " , " \( delay) ; url=' \( url. absoluteString) ' " )
24
+ }
25
+
26
+ private let url : URL ?
27
+ private let delay : TimeInterval
28
+ }
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+ import Testing
3
+
4
+ import Slipstream
5
+
6
+ struct RedirectTests {
7
+ @Test func nilURL( ) throws {
8
+ try #expect( renderHTML ( Redirect ( nil ) ) == " " )
9
+ }
10
+
11
+ @Test func withDelay( ) throws {
12
+ try #expect( renderHTML ( Redirect ( URL ( string: " /home.html " ) , delay: 1 ) ) == #"<meta http-equiv="refresh" content="1.0; url='/home.html'" />"# )
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments