tmpl

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

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

Go to latest
Published: Feb 8, 2017 License: Apache-2.0 Imports: 29 Imported by: 0

README

go-tmpl

Build Status GoDoc Go Report Card

Template Engine written in go.

Install

go get -v github.com/bryanjeal/go-tmpl

Help

cd <path>/github.com/bryanjeal/go-tmpl Make help

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoName       = errors.New("no template name supplied")
	ErrTmplNotFound = errors.New("template not found in store")
	ErrTmplExists   = errors.New("template with existing name found in store")
	ErrNoTmpl       = errors.New("no template data provided")
)

Errors

Functions

This section is empty.

Types

type Ctx

type Ctx struct {
	Flashes      []interface{}
	FlashesInfo  []interface{}
	FlashesWarn  []interface{}
	FlashesError []interface{}
	CsrfToken    string
	Data         map[string]interface{}
}

Ctx is a common context for other modules to embed/use

type EmailMessage

type EmailMessage struct {
	From      string
	Subject   string
	PlainText string
	TplName   string
}

EmailMessage represents the reusable core of an email

type TplSys

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

TplSys is the template helper system

func NewTplSys

func NewTplSys(basedir string) *TplSys

NewTplSys created a new template helper system

func (*TplSys) AddTemplate

func (t *TplSys) AddTemplate(name, baseTmpl, tmplSrc string, filenames ...string) (*template.Template, error)

AddTemplate will add a *template.Template to Tpl.store with "name". If baseTmpl is not empty then find baseTmpl in store and clone it. Proceed as usual. If store already has a template with "name" then an error will be returned

func (*TplSys) BaseDir

func (t *TplSys) BaseDir() string

BaseDir returns the template base directory

func (*TplSys) ExecuteTemplate

func (t *TplSys) ExecuteTemplate(name string, ctx interface{}) ([]byte, error)

ExecuteTemplate will find the template with "name" and execute it with the provided context If template with "name" doesn't exist then an error will be returned

func (*TplSys) InitializeStore

func (t *TplSys) InitializeStore()

InitializeStore resets template store and file watcher If you change Tpl.BaseDir then you MUST run InitializeStore()

func (*TplSys) Partial

func (t *TplSys) Partial(name string, ctxs ...interface{}) template.HTML

Partial is the handler for "partial" template function (FuncMap) It will add the template to the store if needed and execute it

func (*TplSys) PutTemplate

func (t *TplSys) PutTemplate(name, baseTmpl, tmplSrc string, filenames ...string) (*template.Template, error)

PutTemplate will put a *template.Template to Tpl.store with "name". Unlike AddTemplate this will override existing templates

Jump to

Keyboard shortcuts

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