From 6f693007bdc03924bcc3d4a599c44cf2b2aaf6e5 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Oct 2024 05:13:58 +0200 Subject: [PATCH] web content --- web/components/intro/render.v | 114 ++++++++ web/components/intro/templates/main.html | 85 ++++++ web/templates/index.html | 350 +---------------------- web/templates/partials/footer.html | 106 +++++++ web/templates/{ => partials}/header.html | 0 web/templates/partials/scripts.html | 22 ++ web/view.v | 19 ++ 7 files changed, 350 insertions(+), 346 deletions(-) create mode 100644 web/components/intro/render.v create mode 100644 web/components/intro/templates/main.html create mode 100644 web/templates/partials/footer.html rename web/templates/{ => partials}/header.html (100%) create mode 100644 web/templates/partials/scripts.html diff --git a/web/components/intro/render.v b/web/components/intro/render.v new file mode 100644 index 0000000..179bb8d --- /dev/null +++ b/web/components/intro/render.v @@ -0,0 +1,114 @@ +module intro + +import freeflowuniverse.crystallib.core.playbook + +pub struct Item { +pub mut: + title string + subtitle string + description string + background_image string + button_primary Button + button_secondary Button +} + +pub struct Button { +pub mut: + text string + url string +} + +pub struct Data { +pub mut: + items []Item +} + + +const example_heroscript=" + + !!intro1.new name:'myintro' + + !!intro1.myintro_add + title: 'Sepia' + description: ' + Made for photographers, photo studios, design agencies. + Create your own unique and beautiful photography website! + ' + subtitle: 'Photography Portfolio Theme' + background_image: 'assets/img/intro/intro-10.jpg' + button_primary_text: 'Buy It Now!' + button_primary_url: 'https://example.com/learn-more' + button_secondary_text: 'Discover More' + button_secondary_url: 'albums-grid-fluid-2.html' + + !!intro1.myintro_add + title: 'Sepia 2' + description: 'Made for photographers 2, photo studios, design agencies.
Create your own unique and beautiful photography website!' + subtitle: 'Photography Portfolio Theme' + background_image: 'assets/img/intro/intro-10.jpg' + button_primary_text: 'Buy It Now!' + button_primary_url: 'https://example.com/learn-more' + button_secondary_text: 'Discover More' + button_secondary_url: 'albums-grid-fluid-2.html' +" + +@[params] +pub struct RenderArgs{ +pub mut: + text string + args map[string]string + defaults bool +} + +//will have all the results, key is in this case intro1.${name} +//this allows us to feed e.g. markdown to all renderers and then we get the data filled in what is found on page + +pub fn render(args_ RenderArgs) !map[string]string{ + mut args:=args_ + + mut result:=map[string]string{} + + if args.text =="" && args.defaults{ + args.text = example_heroscript + } + + mut plbook := playbook.new(text: args.text)! + mut data := Data{} + + actions0 := plbook.find(filter: 'intro1.new')! + for action0 in actions0{ + mut p0 := action0.params + name := p0.get_default('name','default')! + key:="intro1.${name}" + + // Process add_item actions + actions := plbook.find(filter: 'intro1.${name}_add')! + for action in actions { + mut p := action.params + + item := Item{ + title: p.get('title')! + subtitle: p.get('subtitle')! + description: p.get('description')!.replace("\n","
") + background_image: p.get('background_image')! + button_primary: Button{ + text: p.get('button_primary_text')! + url: p.get('button_primary_url')! + } + button_secondary: Button{ + text: p.get('button_secondary_text')! + url: p.get('button_secondary_url')! + } + } + + data.items << item + } + + result[key]=$tmpl("templates/main.html") + + } + + return result + + +} \ No newline at end of file diff --git a/web/components/intro/templates/main.html b/web/components/intro/templates/main.html new file mode 100644 index 0000000..38094c9 --- /dev/null +++ b/web/components/intro/templates/main.html @@ -0,0 +1,85 @@ + +
+
+ +
+
+ \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html index f89cf64..4f6d64f 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1,226 +1,10 @@ -@include 'header' +@include 'partials/header' -
- -
-
- -
-
- + @{content["intro1.myintro"]} - - - - + @include 'partials/footer'
+ @include 'partials/scripts' - - - - - - - - - - - - - - - - - - - - diff --git a/web/templates/partials/footer.html b/web/templates/partials/footer.html new file mode 100644 index 0000000..e7ed957 --- /dev/null +++ b/web/templates/partials/footer.html @@ -0,0 +1,106 @@ + + + + \ No newline at end of file diff --git a/web/templates/header.html b/web/templates/partials/header.html similarity index 100% rename from web/templates/header.html rename to web/templates/partials/header.html diff --git a/web/templates/partials/scripts.html b/web/templates/partials/scripts.html new file mode 100644 index 0000000..ddfc889 --- /dev/null +++ b/web/templates/partials/scripts.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/view.v b/web/view.v index d50124b..5315425 100644 --- a/web/view.v +++ b/web/view.v @@ -2,13 +2,32 @@ module web //import freeflowuniverse.crystallib.osal import veb +import web1.components.intro + // import rand // import os // import json // import freeflowuniverse.crystallib.webserver.auth.jwt // import time +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 +} + + pub fn (app &App) index(mut ctx Context) veb.Result { + content:=render(mut ctx) or { + ctx.res.set_status(.unknown) + return ctx.html('

ERROR!

${err}') + } return ctx.html($tmpl('./templates/index.html')) }