packages
The Louise packages, each released on its own
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#31 · main · 4 min 11 s
0Étoiles
0Forks
3Issues
| 1 | /// Requests and responses for the tests: what a browser or htmx sends, and |
| 2 | /// what came back. |
| 3 | |
| 4 | import reply.{type Shell, Notice, Shell} |
| 5 | import std/bytes |
| 6 | import std/html.{type Html} |
| 7 | import std/http.{type Request, type Response, Request} |
| 8 | import std/list |
| 9 | import std/option |
| 10 | |
| 11 | pub fn get :: path: String -> Request |
| 12 | { |
| 13 | Request("GET", path, [], bytes.empty ()) |
| 14 | } |
| 15 | |
| 16 | pub fn post :: path: String body: String -> Request |
| 17 | { |
| 18 | Request( "POST" |
| 19 | , path |
| 20 | , [("Content-Type", "application/x-www-form-urlencoded")] |
| 21 | , bytes.from_string body |
| 22 | ) |
| 23 | } |
| 24 | |
| 25 | pub fn htmx :: req: Request -> Request |
| 26 | { |
| 27 | with_header req "HX-Request" "true" |
| 28 | } |
| 29 | |
| 30 | pub fn with_header :: req: Request name: String value: String -> Request |
| 31 | { |
| 32 | Request(..req, headers: [(name, value), ..req.headers]) |
| 33 | } |
| 34 | |
| 35 | pub fn header :: resp: Response name: String -> String |
| 36 | { |
| 37 | list.find resp.headers fn h { h.0 == name } |
| 38 | |> option.map fn h { h.1 } |
| 39 | |> option.unwrap_or "" |
| 40 | } |
| 41 | |
| 42 | pub fn text :: resp: Response -> String |
| 43 | { |
| 44 | bytes.to_string_lossy |
| 45 | (option.unwrap_or (http.whole_body resp) (bytes.empty ())) |
| 46 | } |
| 47 | |
| 48 | /// A shell that frames a page in `main`, its title as an attribute. |
| 49 | pub fn shell :: -> Shell |
| 50 | { |
| 51 | Shell( framed |
| 52 | , Notice("Not found", <p>nothing here</p>) |
| 53 | , Notice("Bad request", <p>unreadable</p>) |
| 54 | ) |
| 55 | } |
| 56 | |
| 57 | fn framed :: title: String content: Html -> Html |
| 58 | { |
| 59 | <main data-title={title}>{content}</main> |
| 60 | } |