@@ -27,7 +27,7 @@ public extension HTMLElementAttribute {
2727 case prompt( String )
2828 case put( String )
2929 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 ? )
3131 case sync( String , strategy: SyncStrategy ? )
3232 case validate( TrueOrFalse )
3333
@@ -83,7 +83,40 @@ public extension HTMLElementAttribute {
8383 case " prompt " : self = . prompt( string ( ) )
8484 case " put " : self = . put( string ( ) )
8585 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
87120 //case "sync": self = .sync(String, strategy: SyncStrategy?) // TODO: fix
88121 case " validate " : self = . validate( enumeration ( ) )
89122
@@ -126,7 +159,7 @@ public extension HTMLElementAttribute {
126159 case . confirm( _) : return " confirm "
127160 case . delete( _) : return " delete "
128161 case . disable( _) : return " disable "
129- case . disabledElt( _) : return " disable -elt"
162+ case . disabledElt( _) : return " disabled -elt"
130163 case . disinherit( _) : return " disinherit "
131164 case . encoding( _) : return " encoding "
132165 case . ext( _) : return " ext "
@@ -173,8 +206,8 @@ public extension HTMLElementAttribute {
173206 case . disinherit( let value) : return value
174207 case . encoding( let value) : return value
175208 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: " , " ) + " } "
178211 case . history( let value) : return value. rawValue
179212 case . historyElt( _) : return " "
180213 case . include( let value) : return value
@@ -187,7 +220,15 @@ public extension HTMLElementAttribute {
187220 case . put( let value) : return value
188221 case . replaceURL( let url) : return url. htmlValue
189222 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+ }
191232 case . sync( let selector, let strategy) :
192233 return selector + ( strategy == nil ? " " : " : " + strategy!. htmlValue)
193234 case . validate( let value) : return value. rawValue
0 commit comments