started doing framing

This commit is contained in:
2025-09-13 21:21:02 -06:00
parent ee2a8a7d2b
commit 5a437a0c64
6 changed files with 164 additions and 110 deletions
+2 -21
View File
@@ -9,34 +9,15 @@
package main
import (
"io"
"git.erbosoft.com/amy/amsterdam/ui"
"github.com/CloudyKit/jet/v6"
"github.com/labstack/echo/v4"
)
var views = jet.NewSet(
jet.NewOSFileSystemLoader("./views"),
jet.DevelopmentMode(true),
)
type TemplateRenderer struct {
}
func (r *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
view, err := views.GetTemplate(name)
if err != nil {
return err
}
return view.Execute(w, nil, nil)
}
func setupEcho() *echo.Echo {
e := echo.New()
e.Renderer = &TemplateRenderer{}
e.Renderer = &ui.TemplateRenderer{}
e.GET("/", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) {
return "template", "frame.jet", nil
return "framed_template", "top.jet", nil
}))
return e
}
+36 -4
View File
@@ -9,33 +9,65 @@
package ui
import (
"bytes"
"net/http"
"github.com/CloudyKit/jet/v6"
"github.com/labstack/echo/v4"
)
type AmContext interface {
Render(string) error
SubRender(string) ([]byte, error)
SetRC(int)
VarMap() jet.VarMap
}
type amContext struct {
echoContext echo.Context
httprc int
}
func (c *amContext) SetRC(rc int) {
c.httprc = rc
rendervars jet.VarMap
}
func (c *amContext) Render(name string) error {
return c.echoContext.Render(c.httprc, name, c)
}
func (c *amContext) SubRender(name string) ([]byte, error) {
view, err := views.GetTemplate(name)
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
err = view.Execute(buf, c.VarMap(), c)
return buf.Bytes(), err
}
func (c *amContext) SetRC(rc int) {
c.httprc = rc
}
func (c *amContext) VarMap() jet.VarMap {
return c.rendervars
}
func NewAmContext(ctxt echo.Context) AmContext {
rc := amContext{
echoContext: ctxt,
httprc: http.StatusOK,
rendervars: make(jet.VarMap),
}
ctxt.Set("amsterdam_context", &rc)
return &rc
}
func AmContextFromEchoContext(ctxt echo.Context) AmContext {
myctxt := ctxt.Get("amsterdam_context")
if myctxt != nil {
rc, ok := myctxt.(AmContext)
if ok {
return rc
}
}
return nil
}
+3
View File
@@ -22,6 +22,9 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
switch what {
case "template":
err = amctxt.Render(fmt.Sprintf("%v", rc))
case "framed_template":
amctxt.VarMap().Set("amsterdam_innerPage", rc)
err = amctxt.Render("frame.jet")
default:
err = fmt.Errorf("unknown rendering type: %s", what)
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ui
import (
"io"
"github.com/CloudyKit/jet/v6"
"github.com/labstack/echo/v4"
)
var views = jet.NewSet(
jet.NewOSFileSystemLoader("./views"),
jet.DevelopmentMode(true),
)
type TemplateRenderer struct {
}
func (r *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
view, err := views.GetTemplate(name)
if err != nil {
return err
}
var vmap jet.VarMap = nil
amctxt := AmContextFromEchoContext(c)
if amctxt != nil {
vmap = amctxt.VarMap()
}
return view.Execute(w, vmap, data)
}
+1 -85
View File
@@ -84,91 +84,7 @@
<!-- MAIN CONTENT -->
<div class="flex-1 bg-white">
<div class="flex">
<!-- Content Area -->
<div class="flex-1 p-4">
<!-- Welcome Section -->
<div class="mb-8">
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Venice</h1>
<hr class="border-2 border-gray-400 w-4/5 mb-4">
<p class="text-black text-sm mb-4">
Welcome to the <strong>Venice Web Communities System</strong>. To get the most out of this site, you should log in or create an account, using one of the links above.
</p>
</div>
<!-- Venice Currents Section -->
<div>
<h2 class="text-blue-800 text-4xl font-bold mb-2">Venice Currents</h2>
<hr class="border-2 border-gray-400 w-4/5 mb-4">
<div class="text-black text-sm">
<div class="mb-2">
<strong>Amy, formerly Eric</strong>
(<em>
<a href="http://necrovenice:8080/venice/user/Administrator"
target="_blank"
class="text-blue-700 hover:text-blue-900">Administrator</a>,
Sep 8, 2025 5:17:02 PM
</em>)
</div>
<pre class="mb-4 whitespace-pre-wrap">This is a test.
This is only a test.
If this had been an <em>actual</em> emergency, we would all be
dead by now.</pre>
<div class="text-xs italic">
(From the topic: <a href="http://necrovenice:8080/venice/go/Piazza!General.1"
class="text-blue-700 hover:text-blue-900">It Works Again!</a>)
</div>
</div>
</div>
</div>
<!-- RIGHT SIDEBAR -->
<div class="w-52 p-4">
<!-- Featured Communities -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Featured Communities:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="flex items-center">
<span class="mr-2">🟣</span>
<a href="http://necrovenice:8080/venice/community/Piazza"
class="text-blue-700 hover:text-blue-900 font-bold text-sm">La Piazza</a>
</div>
</div>
</div>
<!-- Featured Conferences -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Featured Conferences:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="flex items-center">
<span class="mr-2">🟣</span>
<div class="text-sm">
<a href="http://necrovenice:8080/venice/conf/topics.js.vs?sig=2&conf=2"
class="text-blue-700 hover:text-blue-900 font-bold">General Discussion</a>
<span class="text-black"> (La Piazza)</span>
</div>
</div>
</div>
</div>
<!-- Users Online -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Users Online:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="text-black text-sm font-bold mb-2">1 total (max 1)</div>
<div class="flex items-center">
<span class="mr-2">🟣</span>
<span class="text-black text-sm">Not logged in (1)</span>
</div>
</div>
</div>
</div>
{{ .SubRender(amsterdam_innerPage) | raw }}
</div>
</div>
</div>
+85
View File
@@ -0,0 +1,85 @@
<!-- Content Area -->
<div class="flex-1 p-4">
<!-- Welcome Section -->
<div class="mb-8">
<h1 class="text-blue-800 text-4xl font-bold mb-2">Welcome to Venice</h1>
<hr class="border-2 border-gray-400 w-4/5 mb-4">
<p class="text-black text-sm mb-4">
Welcome to the <strong>Venice Web Communities System</strong>. To get the most out of this site, you should log in or create an account, using one of the links above.
</p>
</div>
<!-- Venice Currents Section -->
<div>
<h2 class="text-blue-800 text-4xl font-bold mb-2">Venice Currents</h2>
<hr class="border-2 border-gray-400 w-4/5 mb-4">
<div class="text-black text-sm">
<div class="mb-2">
<strong>Amy, formerly Eric</strong>
(<em>
<a href="http://necrovenice:8080/venice/user/Administrator"
target="_blank"
class="text-blue-700 hover:text-blue-900">Administrator</a>,
Sep 8, 2025 5:17:02 PM
</em>)
</div>
<pre class="mb-4 whitespace-pre-wrap">This is a test.
This is only a test.
If this had been an <em>actual</em> emergency, we would all be
dead by now.</pre>
<div class="text-xs italic">
(From the topic: <a href="http://necrovenice:8080/venice/go/Piazza!General.1"
class="text-blue-700 hover:text-blue-900">It Works Again!</a>)
</div>
</div>
</div>
</div>
<!-- RIGHT SIDEBAR -->
<div class="w-52 p-4">
<!-- Featured Communities -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Featured Communities:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="flex items-center">
<span class="mr-2">🟣</span>
<a href="http://necrovenice:8080/venice/community/Piazza"
class="text-blue-700 hover:text-blue-900 font-bold text-sm">La Piazza</a>
</div>
</div>
</div>
<!-- Featured Conferences -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Featured Conferences:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="flex items-center">
<span class="mr-2">🟣</span>
<div class="text-sm">
<a href="http://necrovenice:8080/venice/conf/topics.js.vs?sig=2&conf=2"
class="text-blue-700 hover:text-blue-900 font-bold">General Discussion</a>
<span class="text-black"> (La Piazza)</span>
</div>
</div>
</div>
</div>
<!-- Users Online -->
<div class="mb-4">
<div class="bg-blue-600 px-2 py-1 rounded-t">
<h3 class="text-white font-bold text-base">Users Online:</h3>
</div>
<div class="bg-blue-400 px-2 py-2 rounded-b">
<div class="text-black text-sm font-bold mb-2">1 total (max 1)</div>
<div class="flex items-center">
<span class="mr-2">🟣</span>
<span class="text-black text-sm">Not logged in (1)</span>
</div>
</div>
</div>
</div>