move standalone projects into own directory
This commit is contained in:
57
projects/_standalone/ksr-express/src/ksr_express/Engine.kiss
Normal file
57
projects/_standalone/ksr-express/src/ksr_express/Engine.kiss
Normal file
@@ -0,0 +1,57 @@
|
||||
(import kiss_spaced_rep.StudyEngine)
|
||||
(implements StudyEngine)
|
||||
|
||||
(prop &mut :String content "")
|
||||
|
||||
(defNew []
|
||||
[&mut :String image ""
|
||||
&mut :Continuation cc null
|
||||
&mut :String->Void resolve null
|
||||
&mut :Dynamic connection null]
|
||||
(let [app (Express.call)
|
||||
port 3000
|
||||
staticDir (#if STATIC_DIR (#value "STATIC_DIR") (Sys.getCwd))]
|
||||
(print "Using $staticDir for static file directory")
|
||||
(app.use "/static" (Express.static_.call staticDir))
|
||||
(app.get "/" ->[req :Dynamic res next]
|
||||
(res.send content))
|
||||
(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 "/")
|
||||
})
|
||||
(app.get "/restart" ->[req :Dynamic res next] {
|
||||
(res.redirect "/")
|
||||
(connection.close)
|
||||
(kiss_spaced_rep.Main_.main)
|
||||
})
|
||||
(#unless test
|
||||
(set connection (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=\"/static/${path}\" /><br />"))
|
||||
|
||||
(method :Void delayForUserInput [cc &opt :String text]
|
||||
(set this.cc cc)
|
||||
(unless text
|
||||
(set text "Next"))
|
||||
(+= content "<br /><a href=\"/continue\">${text}</a><br />"))
|
||||
|
||||
(method :Void getUserInput [resolve]
|
||||
(set this.resolve resolve)
|
||||
(+= content "<br /><input type=\"text\" id=\"value\"><br /><button onclick=\"window.open('/submit?value=' + document.getElementById('value').value, '_self');\">Submit</a><br />"))
|
||||
|
||||
(method :Void promptForRefresh [refresh]
|
||||
(delayForUserInput refresh "Refresh"))
|
||||
Reference in New Issue
Block a user