web content
This commit is contained in:
parent
6f693007bd
commit
d478890623
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
start
|
start
|
||||||
start_notcc
|
start_notcc
|
||||||
|
start_notcc.dSYM/
|
||||||
|
*.dSYM/*
|
||||||
|
*.dSYM*
|
@ -1,5 +1,5 @@
|
|||||||
module web
|
module web
|
||||||
|
import x.templating.dtm
|
||||||
//import freeflowuniverse.crystallib.osal
|
//import freeflowuniverse.crystallib.osal
|
||||||
import veb
|
import veb
|
||||||
import os
|
import os
|
||||||
@ -13,8 +13,9 @@ pub struct Context {
|
|||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
veb.StaticHandler
|
veb.StaticHandler
|
||||||
pub:
|
pub mut:
|
||||||
adminkey string
|
adminkey string
|
||||||
|
dtm &dtm.DynamicTemplateManager = dtm.initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main entry point
|
// Main entry point
|
||||||
|
45
web/view.v
45
web/view.v
@ -3,12 +3,13 @@ module web
|
|||||||
//import freeflowuniverse.crystallib.osal
|
//import freeflowuniverse.crystallib.osal
|
||||||
import veb
|
import veb
|
||||||
import web1.components.intro
|
import web1.components.intro
|
||||||
|
import freeflowuniverse.crystallib.ui.console
|
||||||
// import rand
|
// import rand
|
||||||
// import os
|
import os
|
||||||
// import json
|
// import json
|
||||||
// import freeflowuniverse.crystallib.webserver.auth.jwt
|
// import freeflowuniverse.crystallib.webserver.auth.jwt
|
||||||
// import time
|
// import time
|
||||||
|
//import x.templating.dtm
|
||||||
|
|
||||||
pub fn render(mut ctx Context) !map[string]string {
|
pub fn render(mut ctx Context) !map[string]string {
|
||||||
mut res:=map[string]string{}
|
mut res:=map[string]string{}
|
||||||
@ -22,13 +23,49 @@ pub fn render(mut ctx Context) !map[string]string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ,"")
|
||||||
|
}
|
||||||
|
|
||||||
|
@['/: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}'")
|
||||||
|
|
||||||
pub fn (app &App) index(mut ctx Context) veb.Result {
|
|
||||||
content:=render(mut ctx) or {
|
content:=render(mut ctx) or {
|
||||||
ctx.res.set_status(.unknown)
|
ctx.res.set_status(.unknown)
|
||||||
return ctx.html('<h1>ERROR!</h1>${err}')
|
return ctx.html('<h1>ERROR!</h1>${err}')
|
||||||
}
|
}
|
||||||
return ctx.html($tmpl('./templates/index.html'))
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @['/api/connection-details'; get]
|
// @['/api/connection-details'; get]
|
||||||
|
Loading…
Reference in New Issue
Block a user