rightmpl

package module
v0.0.0-...-dd2796c Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2020 License: MIT Imports: 12 Imported by: 0

README

rightmpl

Go templating done right.

text/template is slow & not composable. QuickTemplate requires a generate step which means no live editing.

https://github.com/valyala/fasttemplate offers fast edits, but lets go further:

Today

Templates loaded, but auto-reload Instead of reading each time, lets keep them in memory.

_Variable Substitution works like fasttemplate allows

Coming Soon

New with funcs If all functions are known before parsing, then dynamic dispatch stacks can form.

Plan: #. Get subtemplate working as a function #. Get boolean expressions working #. "IF" functions eval a boolean expression and run a subtemplate #. reflect-less types? .I.count .F.floatexample .T.text .B.boolexample .S.Sliceexample .M.Mapexample .T.add("key", "value") <-- nah, still needs a map at runtime. or just make it easy with map[string]interface{} and do work in post?

Composition Really go crazy with functions which render their own template. Property passing would be important.

Frame-always If you always wrap your page with the same head, then just send it before any computation. That'll get the browser heading this thing out the door.

Useful Functions Local statics can be served with a hash if we know where the static folders live.

Possible

_Full text/template Compat It should be possible to reuse the parser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component func(w io.Writer, values map[string]interface{})

Component is the signature to add components

type Templates

type Templates struct {
	// contains filtered or unexported fields
}

Templates is returned from New to provide access to a renderer.

func New

func New(folderpath string, funcs map[string]Component) (*Templates, error)

New returns a templates

func (*Templates) AddComponent

func (t *Templates) AddComponent(name string, c Component)

AddComponent adds a composable function.

func (*Templates) Render

func (t *Templates) Render(w io.Writer, pathFrac string, values map[string]interface{}) error

Render a template with values to w. pathFrac is the full path after the path given to New(). values are for print only.

Jump to

Keyboard shortcuts

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