tpl

package
v0.0.0-...-fe173bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package tpl parses and bundles templates related by `/templates/bundles.json` and stores them into a map `cache`; i.e. bundles of master-layouts with content-templates; http requests dont need clones for specific template funcs; function executeTemplate(...dynamicName...) replaces {{template constantName}}. Parsing and bundling is done at application init time, avoiding mutexing the `cache` map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(w io.Writer, r *http.Request, mp map[string]interface{}, tName string)

Exec template with map of contents into writer w; cnt as io.Writer would be more efficient?

Automatically created keys

Req
Sess
L
LangCode
Site

CSSSite

HTMLTitle
LogoTitle

Keys expected to be supplied by caller

Content

func ExecContent

func ExecContent(w io.Writer, r *http.Request, cnt, tName string)

ExecContent is a simplified version of Exec() with only one content element

func Get

func Get(tName string, forceFreshParsing bool) (*template.Template, error)

Get returns a parsed bundle of templates by name either pre-parsed from cache, or freshly parsed; called for every template at app *init* time; thus no sync mutex is required; TemplatesPreparse() calls this func with param forceFreshParsing true Exec() calls this func with param forceFreshParsing false

func NewDocServer

func NewDocServer(docPrefix string)

NewDocServer maps docPrefix to ./app-bucket/content; for instance

          /doc/
/urlprefix/doc/

serves files from

./app-bucket/content

Markdown files are converted to HTML; needs session to differentiate files by language setting

the actual handler is ServeDoc() below

func RenderStack

func RenderStack(req *http.Request, w io.Writer, chain []string, binding map[string]interface{})

RenderStack renders a chain of templates

func RenderStaticContent

func RenderStaticContent(w io.Writer, subPth, site, lang string) error

RenderStaticContent writes the content of subPth into w; *.md files are rendered to HTML; *.html files only get URLs rewriting; static files reside in ./app-bucket/content; files may be differentiated by /[site]/[lang]/subPth subPth is a partial path plus filename

func ServeDoc

func ServeDoc(w http.ResponseWriter, r *http.Request)

ServeDoc serves markdown and other content in app-prefix/doc/

func ServeDynCSS

func ServeDynCSS(w http.ResponseWriter, r *http.Request)

ServeDynCSS can serve CSS files for different sites; the url path specifies the key to a CSSVarsSite entry; i.e. /css/site-1/design.css

Currently all CSS vars are set in the main template layout.html; therefore CSS files can be aggressively cached.

Access from CSS would be

{{ cfg.CSSVarsSite.site-1.HTML }}
{{  (.ByKey "sec-drk2" ).RGBA    }}

Thus currently we dont need to serve CSS files as golang templates, but it costs nothing since templates are preparsed at application init, and we retain the possibility to use templating dynamics in future.

func SiteCore

func SiteCore(site string) (string, string)

SiteCore returns only the non-numerical part of the site name; for instance 'pat' from 'pat0'; used for sharing the same CSS files and CSS settings among multiple questionnaires

func StaticDownloadH

func StaticDownloadH(w http.ResponseWriter, r *http.Request)

StaticDownloadH serves static files. It guesses the Content-Type header. It writes a Content-Length header. It serves the file chunk-wise without consuming only a buffer of memory.

func Struct2Map

func Struct2Map(source interface{}) map[string]interface{}

Struct2Map converts any struct instance into map[string]interface{}; previously we used extensions of struct type BaseTemplateData to guarantee certain keys in templates; recently we add these minimum keys in Exec(); this func now allows usage of tpl.RenderStack() or tpl.Exec() with a struct instead of a map[string]interface{}

func TemplatesPreparse

func TemplatesPreparse(w http.ResponseWriter, req *http.Request)

TemplatesPreparse - parsing templates is expensive; concurrent access is expensive; we parse all templates in this http handler which is also used for initialization at app start in bootstrap.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL