warning: this library is a huge work in progress.
main TODOs:
(robusta encoding html)
can produce unsafe html(robusta encoding json)
does not follow the cited
standardgit grep TODO:
Exported values:
path->mime
ext->mime
Exported values:
bool->string
->string
object?
Exported values:
encode
decode-form-nosym
decode-form
decode
Exported values:
list->base64
base64->list
string->base64
base64->string
encode
decode
Examples:
(base64->string (string->base64 "abcd"))
=
"abcd"
this loosely implements the ECMA-404 standard for json encoding and decoding
it WILL accept broken json, and decode it correctly or incorrectly depending on the mood, but it should decode proper json correctly.
features, not bugs, include, but are not limited to:
[1,2,3 4]
→ (1 2 3 4)
[,,,,,]
→ ()
it can also encode
json, where objects are defined like
this: '((a . b) (c . d))
, so a list with key-value
pairs.
be warned that this implementation is really slow. like proper slow slow. i may fix that in the future, but for now it is what it is.
https://ecma-international.org/publications-and-standards/standards/ecma-404/
me me likey accumulators
Exported values:
decode
encode
this library was originally written for chai but development will continue here.
Exported values:
encode
Exported values:
static-dispatcher
static-index
redirect
dispatcher
file->lst
you probably shouldn't use this library by itself. it's nicely
packaged inside of (robusta dispatcher)
Exported values:
parse
parse-by-fd
schema for open
is:
list
(
(col-name type-pred-function thing->string-function string->thing-function)...)
for example:
define (self s) s)
(
`((uname ,string? ,self ,self)
(passwd ,string? ,self ,self) (secret-num ,number? ,number->string ,string->number))
this library uses the opened db in-memory (via
(owl variable)
), and saves it only on (save)
and (close)
calls.
Exported values:
open
insert-into
close
get-all
get-column
filter-by
delete-from
save
this library implements a basic http server
Exported values:
bind
(import (prefix (robusta server) robusta/))
(robusta/bind8080
lambda (r)
(
(print r)let ((send (cdr (assq 'send r))))
(200 '((Content-type . "text/html")) "hello!")))) (send
(import (prefix (robusta server) robusta/))
(import (prefix (robusta dispatcher) robusta/))
(import (only (robusta server) ->string))
define (index request)
(. 200)
'((code . ((Content-type . "text/html")))
(headers . "this is the index page")))
(content
define (about request)
(. 200)
`((code . ((Content-type . "text/html")))
(headers . ,(->string
(content list "this is an about page<br>"
("your request: " request)))))
define dispatcher (robusta/dispatcher
("/" . ,index)
`(("/about" . ,about))))
(
8080 dispatcher) (robusta/bind
(import (prefix (robusta encoding json) json/))
define json-string "[1, 2, [3], [[4]], [[[5]]], [[[[6]]]], 7]")
(define json-structure '((a . "10") (b . #f)))
(; → (1 2 (3) ((4)) (((5))) ((((6)))) 7)
(print (json/decode json-string)) ; → {"a":"10","b":false} (print (json/encode json-structure))
(import (prefix (robusta server) robusta/))
(import (prefix (robusta dispatcher) robusta/))
(import (prefix (robusta encoding html) html/))
define (idx request)
(. 200)
`((code . ((Content-type . "text/html")))
(headers . ,(html/encode '(html (head) (body (p "this the only page")))))))
(content
8080 (robusta/dispatcher `(("m/^.*$/" . ,idx)))) (robusta/bind
(import
(robusta server)
(robusta dispatcher)
(prefix (robusta encoding html) html/))
define index-html
(
(html/encode
`(html
(head)"see the static pages" ((a (href . "static/")) "here")))))
(body
define dis (dispatcher
("m/static(\\/.*)?/" . ,(λ (req) (static-dispatcher "static/" req)))
`(("m/\\/?/" . ,(λ (req) `((code . 200)
(. ((Content-type . "text/html")))
(headers . ,index-html)))))))
(content
_) (bind 8000 dis)) (λ (
(import
(robusta server)
(prefix (robusta dispatcher) D/)
(prefix (robusta encoding html) html/))
define dispatcher
(
(D/dispatcher"/" . ,(λ (req)
`((let* ((M (cdr (assq 'method req)))
(if (eqv? M 'GET)
(n (0
string->number (cdr (assq 'n (cdr (assq 'post-data req))))))))
(. 200)
`((code . ((Content-type . "text/html")))
(headers
(content. ,(html/encode
`(body"n: " ,n)
(p . "POST"))
((form (method . "hidden")
((input (type . "n")
(name . ,(number->string (+ n 1)))))
(value "+"))
(button . "POST"))
((form (method . "hidden")
((input (type . "n")
(name . ,(number->string (- n 1)))))
(value "-"))))))))))))
(button
_) (bind 6969 dispatcher)) (λ (
(import
(prefix (robusta db tsv) tsv/)
(prefix (owl sys) sys/))
define (self s) s)
(define dbname "db.tsv")
(
define schema
(;; col-name type-pred thing->string string->thing
`((uname ,string? ,self ,self)
(passwd ,string? ,self ,self)
(secret-num ,number? ,number->string ,string->number)))
(when (sys/file? dbname)
(sys/unlink dbname))
;; th = tsv handle
define th (tsv/open "db.tsv" schema))
(
"admin" "zaq1@WSX" 10))
(tsv/insert-into th '("user0" "helloworld" 120))
(tsv/insert-into th '(
= s 120))))
(print (tsv/filter-by th (λ (u p s) (
(print (tsv/get-column th 'passwd))string-ci=? u "USER0")))
(tsv/delete-from th (λ (u p s) (
(print (tsv/get-all th))
(tsv/close th)
(import (prefix (robusta encoding url) url/))
define al '((a . b) (c . d) (e . 10) (f . "1") (g . #false)))
(
;; everything str'd as types get stripped
string=? (str (url/decode-form (url/encode al))) (str al))) (print (