updated templater library
This commit is contained in:
@@ -2,15 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/angelbeltran/templater"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"ruben/inventory2/internal/domains/accounts"
|
||||
@@ -73,56 +68,6 @@ func Router(
|
||||
logger.WithGroup("templates"),
|
||||
r.Group("/ui"),
|
||||
contentDir,
|
||||
// TODO: move this constructor call up to main.go
|
||||
// TODO: clean up the references to the templates dir throughout as well (should only be referred to in the 'main' package
|
||||
new(templater.Templater).With(templater.Config{
|
||||
Funcs: func(name string, props map[string]any) template.FuncMap {
|
||||
return template.FuncMap{
|
||||
// params
|
||||
"addPathParam": func(k string, v any, args map[string]any) (map[string]any, error) {
|
||||
pathParams, ok := args["PathParams"].(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("PathParams not set as args: %v", args)
|
||||
}
|
||||
|
||||
pathParams[k] = fmt.Sprint(v)
|
||||
|
||||
return args, nil
|
||||
},
|
||||
|
||||
// parsing
|
||||
"parseInt": func(s string) (int, error) {
|
||||
return strconv.Atoi(s)
|
||||
},
|
||||
"parseInt64": func(s string) (int64, error) {
|
||||
return strconv.ParseInt(s, 10, 64)
|
||||
},
|
||||
"parsePlatform": func(s string) (accounts.Platform, error) {
|
||||
return accounts.NewPlatform(s)
|
||||
},
|
||||
|
||||
// arithmetic
|
||||
"addInt": func(a, b int) int {
|
||||
return a + b
|
||||
},
|
||||
"subInt": func(a, b int) int {
|
||||
return a - b
|
||||
},
|
||||
"multInt": func(a, b int) int {
|
||||
return a * b
|
||||
},
|
||||
|
||||
// json
|
||||
"prettyPrintJSON": func(j json.RawMessage) string {
|
||||
b, err := json.MarshalIndent(j, " ", "")
|
||||
if err != nil {
|
||||
return string(j)
|
||||
}
|
||||
return string(b)
|
||||
},
|
||||
}
|
||||
},
|
||||
}),
|
||||
rawEvents,
|
||||
accts,
|
||||
etsy,
|
||||
|
||||
Reference in New Issue
Block a user