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