2024-10-07 01:21:48 +00:00
|
|
|
module web
|
|
|
|
|
2024-10-07 01:51:32 +00:00
|
|
|
//import freeflowuniverse.crystallib.osal
|
2024-10-07 01:21:48 +00:00
|
|
|
import veb
|
2024-10-07 03:13:58 +00:00
|
|
|
import web1.components.intro
|
2024-10-07 03:54:23 +00:00
|
|
|
import freeflowuniverse.crystallib.ui.console
|
2024-10-07 01:51:32 +00:00
|
|
|
// import rand
|
2024-10-07 03:54:23 +00:00
|
|
|
import os
|
2024-10-07 01:51:32 +00:00
|
|
|
// import json
|
|
|
|
// import freeflowuniverse.crystallib.webserver.auth.jwt
|
|
|
|
// import time
|
2024-10-07 03:54:23 +00:00
|
|
|
//import x.templating.dtm
|
2024-10-07 01:21:48 +00:00
|
|
|
|
2024-10-07 03:13:58 +00:00
|
|
|
pub fn render(mut ctx Context) !map[string]string {
|
|
|
|
mut res:=map[string]string{}
|
|
|
|
res=intro.render(defaults:true)!
|
|
|
|
//todo: here we need to add all renders we support
|
|
|
|
// if true{
|
|
|
|
// println(res)
|
|
|
|
// exit(1)
|
|
|
|
// }
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2024-10-07 03:54:23 +00:00
|
|
|
pub fn template_render(path string, content map[string]string)!string {
|
|
|
|
mut name:=os.base(path).to_lower()
|
|
|
|
name=name.all_before_last(".html")
|
|
|
|
c := match name{
|
|
|
|
"index"{
|
|
|
|
$tmpl('./templates/index.html')
|
|
|
|
}"blog-list-classic"{
|
|
|
|
$tmpl('./templates/blog-list-classic.html')
|
|
|
|
}else{
|
|
|
|
return error("can't find template with name: ${name}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//TODO: NEED to add the other templates, its a pitty we can't do this dynamic
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (mut app App) index(mut ctx Context) veb.Result {
|
|
|
|
return app.index2(mut ctx ,"")
|
|
|
|
}
|
2024-10-07 03:13:58 +00:00
|
|
|
|
2024-10-07 03:54:23 +00:00
|
|
|
@['/:path']
|
|
|
|
pub fn (mut app App) index2(mut ctx Context,path string) veb.Result {
|
|
|
|
mut templpath:="${path}"
|
|
|
|
if templpath==""{
|
|
|
|
templpath="index"
|
|
|
|
}
|
|
|
|
println(templpath)
|
|
|
|
console.print_debug("templpath : '${templpath}'")
|
|
|
|
|
2024-10-07 03:13:58 +00:00
|
|
|
content:=render(mut ctx) or {
|
|
|
|
ctx.res.set_status(.unknown)
|
|
|
|
return ctx.html('<h1>ERROR!</h1>${err}')
|
|
|
|
}
|
2024-10-07 03:54:23 +00:00
|
|
|
// mut tmp_var := map[string]dtm.DtmMultiTypeMap{}
|
|
|
|
// for key,val in content{
|
|
|
|
// tmp_var[key] = val
|
|
|
|
// }
|
|
|
|
//t:=app.dtm.expand(templpath,placeholders:&tmp_var)
|
|
|
|
t:= template_render(templpath,content)or {
|
|
|
|
ctx.res.set_status(.unknown)
|
|
|
|
return ctx.html('<h1>ERROR TEMPLATE!</h1>${err}')
|
|
|
|
}
|
|
|
|
return ctx.html(t)
|
2024-10-07 01:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @['/api/connection-details'; get]
|
|
|
|
// pub fn (app &App) participant_endpoint(mut ctx Context) veb.Result {
|
|
|
|
|
|
|
|
// @['/blogs/']
|
|
|
|
// pub fn (app &App) room(mut ctx Context) veb.Result {
|
|
|
|
// return ctx.html($tmpl('./templates/room.html'))
|
|
|
|
// }
|
|
|
|
|
|
|
|
// pub fn (app &App) custom(mut ctx Context) veb.Result {
|
|
|
|
// dollar := '$'
|
|
|
|
// return ctx.html($tmpl('./templates/blog-list-grid.html'))
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Custom 404 handler
|
|
|
|
pub fn (mut ctx Context) not_found() veb.Result {
|
|
|
|
ctx.res.set_status(.not_found)
|
|
|
|
return ctx.html('<h1>Page not found!</h1>')
|
|
|
|
}
|