From d478890623601f70189bfac2185eff6fd70f8591 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Oct 2024 05:54:23 +0200 Subject: [PATCH] web content --- .gitignore | 5 ++++- templates | 1 + web/factory.v | 5 +++-- web/view.v | 45 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 120000 templates diff --git a/.gitignore b/.gitignore index f018edd..6a5049f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ start -start_notcc \ No newline at end of file +start_notcc +start_notcc.dSYM/ +*.dSYM/* +*.dSYM* \ No newline at end of file diff --git a/templates b/templates new file mode 120000 index 0000000..5503549 --- /dev/null +++ b/templates @@ -0,0 +1 @@ +../www_veda2/web/templates \ No newline at end of file diff --git a/web/factory.v b/web/factory.v index 5949d31..febbf16 100644 --- a/web/factory.v +++ b/web/factory.v @@ -1,5 +1,5 @@ module web - +import x.templating.dtm //import freeflowuniverse.crystallib.osal import veb import os @@ -13,8 +13,9 @@ pub struct Context { pub struct App { veb.StaticHandler -pub: +pub mut: adminkey string + dtm &dtm.DynamicTemplateManager = dtm.initialize() } // Main entry point diff --git a/web/view.v b/web/view.v index 5315425..7d2eff5 100644 --- a/web/view.v +++ b/web/view.v @@ -3,12 +3,13 @@ module web //import freeflowuniverse.crystallib.osal import veb import web1.components.intro - +import freeflowuniverse.crystallib.ui.console // import rand -// import os +import os // import json // import freeflowuniverse.crystallib.webserver.auth.jwt // import time +//import x.templating.dtm pub fn render(mut ctx Context) !map[string]string { mut res:=map[string]string{} @@ -22,13 +23,49 @@ pub fn render(mut ctx Context) !map[string]string { 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 (app &App) index(mut ctx Context) veb.Result { +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}'") + content:=render(mut ctx) or { ctx.res.set_status(.unknown) return ctx.html('

ERROR!

${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('

ERROR TEMPLATE!

${err}') + } + return ctx.html(t) } // @['/api/connection-details'; get]