This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added fieldset sugar and updated to tests to run
- Loading branch information
Showing
4 changed files
with
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import HTTP | ||
import Vapor | ||
|
||
public class FieldsetMiddleware: Middleware { | ||
let key = "_fieldset" | ||
public init() {} | ||
|
||
public func respond(to request: Request, chainingTo next: Responder) throws -> Response { | ||
// Add fieldset to next request | ||
request.storage[key] = try request.session().data[key] | ||
try request.session().data[key] = nil | ||
|
||
let respond = try next.respond(to: request) | ||
|
||
try request.session().data[key] = respond.storage[key] as? Node ?? nil | ||
|
||
return respond | ||
} | ||
} |
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,15 @@ | ||
import VaporForms | ||
import HTTP | ||
import Vapor | ||
|
||
extension Response { | ||
public func withFieldset(_ fieldset: Fieldset) -> Response { | ||
do { | ||
self.storage["_fieldset"] = try fieldset.makeNode() | ||
} catch { | ||
print("AdminPanel.withFieldset: " + error.localizedDescription) | ||
} | ||
|
||
return self | ||
} | ||
} |
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