ksr-express

This commit is contained in:
2023-01-22 19:00:18 -07:00
parent 09250767a4
commit d89d79d258
6 changed files with 1279 additions and 0 deletions

4
projects/ksr-express/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
node_modules/
.haxelib/
libs/
index.js

View File

@@ -0,0 +1,8 @@
-lib kiss
-lib express
-lib kiss-express
-lib kiss-spaced-rep
-cp src
--main kiss_spaced_rep.Main
--js index.js
--cmd node index.js

1196
projects/ksr-express/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
{
"main": "index.js",
"name": "ksr_express",
"description": "An ExpressJS website made with Kisslang",
"title": "ksr-express",
"dependencies": {
"express": "^4.18.1",
"@types/express": "^4.17.13"
},
"devDependencies": {
"dts2hx": "^0.19.0"
},
"version": "0.0.0",
"scripts": {
"postinstall": "dts2hx --all"
}
}

View File

@@ -0,0 +1,47 @@
(import kiss_spaced_rep.StudyEngine)
(implements StudyEngine)
(prop &mut :String content "")
(defNew []
[&mut :String image ""
&mut :Continuation cc null
&mut :String->Void resolve null]
(let [app (Express.call)
port 3000]
(app.use (Express.static_.call (Sys.getCwd)))
(app.get "/" ->[req :Dynamic res next]
(res.send content))
(app.get "/image/:path" ->[:Dynamic req :Dynamic res next]
(res.sendFile req.params.path (object root (Sys.getCwd))))
(app.get "/continue" ->[req res next] {
(whenLet [_cc cc] (set cc null) (_cc))
(res.redirect "/")
})
(app.get "/submit" ->[:Dynamic req :Dynamic res next] {
(whenLet [_resolve resolve] (set resolve null) (_resolve req.query.value))
(res.redirect "/")
})
(#unless test
(app.listen port ->(print "kiss-express listening at http://localhost:$port")))))
(method :Void clear []
(set content ""))
(method :Void print [text]
(+= content text))
(method :Void println [text]
(+= content text "<br />"))
(method :Void showImage [path]
(+= content "<img src=\"/image/${path}\" /><br />"))
(method :Void delayForUserInput [cc]
(set this.cc cc)
(+= content "<br /><a href=\"/continue\">Next</a><br />"))
(method :Void getUserInput [resolve]
(set this.resolve resolve)
(+= content "<br /><input type=\"text\" id=\"value\"><br /><a href=\"#\" onclick=\"window.open('/submit?value=' + document.getElementById('value').value);\">Submit</a><br />"))

View File

@@ -0,0 +1,7 @@
#! /bin/bash
if [ ! -d node_modules ]; then
$(haxelib libpath kiss)/build-scripts/dts2hx-externs/regenerate.sh
fi
haxe -D cards="$(pwd)/$1" -D engine="ksr_express.Engine" build.hxml