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 ¶
- func Exec(w io.Writer, r *http.Request, mp map[string]interface{}, tName string)
- func ExecContent(w io.Writer, r *http.Request, cnt, tName string)
- func Get(tName string, forceFreshParsing bool) (*template.Template, error)
- func NewDocServer(docPrefix string)
- func RenderStack(req *http.Request, w io.Writer, chain []string, binding map[string]interface{})
- func RenderStaticContent(w io.Writer, subPth, site, lang string) error
- func ServeDoc(w http.ResponseWriter, r *http.Request)
- func ServeDynCSS(w http.ResponseWriter, r *http.Request)
- func SiteCore(site string) (string, string)
- func StaticDownloadH(w http.ResponseWriter, r *http.Request)
- func Struct2Map(source interface{}) map[string]interface{}
- func TemplatesPreparse(w http.ResponseWriter, req *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
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 ¶
ExecContent is a simplified version of Exec() with only one content element
func Get ¶
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 ¶
RenderStack renders a chain of templates
func RenderStaticContent ¶
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 ¶
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.