@@ -27,7 +27,7 @@ public extension HTMLElementAttribute {
27
27
case prompt( String )
28
28
case put( String )
29
29
case replaceURL( URL )
30
- case request( js: Bool , timeout: Int = 0 , credentials: Bool = false , noHeaders: Bool = false )
30
+ case request( js: Bool , timeout: String ? , credentials: String ? , noHeaders: String ? )
31
31
case sync( String , strategy: SyncStrategy ? )
32
32
case validate( TrueOrFalse )
33
33
@@ -83,7 +83,40 @@ public extension HTMLElementAttribute {
83
83
case " prompt " : self = . prompt( string ( ) )
84
84
case " put " : self = . put( string ( ) )
85
85
case " replaceURL " : self = . replaceURL( URL ( rawValue: literal ( ) ) !)
86
- //case "request": self = .request(js: Bool, timeout: Int, credentials: Bool, noHeaders: Bool) // TODO: fix
86
+ case " request " :
87
+ let string : String = literal ( ) , values : [ Substring ] = string. split ( separator: " , " )
88
+ var timeout_string : Substring = values [ 1 ] [ values [ 1 ] . index ( after: values [ 1 ] . firstIndex ( of: " : " ) !) ... ]
89
+ while timeout_string. first? . isWhitespace ?? false {
90
+ timeout_string. removeFirst ( )
91
+ }
92
+ let javascript : Bool = values [ 0 ] . split ( separator: " : " ) [ 1 ] . hasSuffix ( " true " )
93
+ let timeout : String ?
94
+ if timeout_string. first == " \" " {
95
+ timeout_string. removeFirst ( )
96
+ timeout = String ( timeout_string [ timeout_string. startIndex..< timeout_string. index ( before: timeout_string. endIndex) ] )
97
+ } else {
98
+ timeout = nil
99
+ }
100
+ var credentials : String ? = nil
101
+ var credentials_string : Substring = values [ 2 ] [ values [ 2 ] . index ( after: values [ 2 ] . firstIndex ( of: " : " ) !) ... ]
102
+ if !credentials_string. hasSuffix ( " nil " ) {
103
+ while ( credentials_string. first? . isWhitespace ?? false ) || credentials_string. first == " \" " {
104
+ credentials_string. removeFirst ( )
105
+ }
106
+ credentials_string. removeLast ( )
107
+ credentials = String ( credentials_string)
108
+ }
109
+ var noHeaders : String ? = nil
110
+ if !string. hasSuffix ( " nil " ) {
111
+ var value : Substring = values [ 3 ] [ values [ 3 ] . index ( after: values [ 3 ] . firstIndex ( of: " : " ) !) ... ]
112
+ while ( value. first? . isWhitespace ?? false ) || value. first == " \" " {
113
+ value. removeFirst ( )
114
+ }
115
+ value. removeLast ( )
116
+ noHeaders = ( javascript ? " js: " : " " ) + value
117
+ }
118
+ self = . request( js: javascript, timeout: timeout, credentials: credentials, noHeaders: noHeaders)
119
+ break
87
120
//case "sync": self = .sync(String, strategy: SyncStrategy?) // TODO: fix
88
121
case " validate " : self = . validate( enumeration ( ) )
89
122
@@ -126,7 +159,7 @@ public extension HTMLElementAttribute {
126
159
case . confirm( _) : return " confirm "
127
160
case . delete( _) : return " delete "
128
161
case . disable( _) : return " disable "
129
- case . disabledElt( _) : return " disable -elt"
162
+ case . disabledElt( _) : return " disabled -elt"
130
163
case . disinherit( _) : return " disinherit "
131
164
case . encoding( _) : return " encoding "
132
165
case . ext( _) : return " ext "
@@ -173,8 +206,8 @@ public extension HTMLElementAttribute {
173
206
case . disinherit( let value) : return value
174
207
case . encoding( let value) : return value
175
208
case . ext( let value) : return value
176
- case . headers( let js, let headers) : // TODO: fix
177
- return js ? " " : " { " + headers. map ( { " \\ \" " + $0. key + " \\ \" : \\ \" " + $0. value + " \\ \" " } ) . joined ( separator: " , " ) + " } "
209
+ case . headers( let js, let headers) :
210
+ return ( js ? " js: " : " " ) + " { " + headers. map ( { " \\ \" " + $0. key + " \\ \" : \\ \" " + $0. value + " \\ \" " } ) . joined ( separator: " , " ) + " } "
178
211
case . history( let value) : return value. rawValue
179
212
case . historyElt( _) : return " "
180
213
case . include( let value) : return value
@@ -187,7 +220,15 @@ public extension HTMLElementAttribute {
187
220
case . put( let value) : return value
188
221
case . replaceURL( let url) : return url. htmlValue
189
222
case . request( let js, let timeout, let credentials, let noHeaders) :
190
- return " " // TODO: fix
223
+ if let timeout: String = timeout {
224
+ return js ? " js: timeout: \( timeout) " : " { \\ \" timeout \\ \" : \( timeout) } "
225
+ } else if let credentials: String = credentials {
226
+ return js ? " js: credentials: \( credentials) " : " { \\ \" credentials \\ \" : \( credentials) } "
227
+ } else if let noHeaders: String = noHeaders {
228
+ return js ? " js: noHeaders: \( noHeaders) " : " { \\ \" noHeaders \\ \" : \( noHeaders) } "
229
+ } else {
230
+ return " "
231
+ }
191
232
case . sync( let selector, let strategy) :
192
233
return selector + ( strategy == nil ? " " : " : " + strategy!. htmlValue)
193
234
case . validate( let value) : return value. rawValue
0 commit comments