示例#1
0
func newTemplate(app *App, fs vfs.VFS, manager *assets.Manager) *Template {
	t := &Template{tmpl: template.New(fs, manager), app: app}
	if app.cfg != nil {
		t.tmpl.Debug = app.cfg.TemplateDebug
	}
	t.tmpl.Funcs(templateFuncs).Funcs([]*template.Func{
		{Name: "reverse", Fn: t.reverse, Traits: template.FuncTraitPure},
	})
	return t
}
示例#2
0
func ReloadPlugin() *template.Plugin {
	reload := template.New(devassets.AssetsFS, nil)
	if err := reload.Parse("reload.html"); err != nil {
		panic(err)
	}
	return &template.Plugin{
		Template: reload,
		Position: assets.Bottom,
	}
}
示例#3
0
文件: app.go 项目: rainycape/gondola
// LoadTemplatePlugin loads the template from name, using the app templates VFS and
// assets manager, and then adds it as a plugin at the given position.
// See also App.AddTemplatePlugin.
func (app *App) LoadTemplatePlugin(name string, pos assets.Position) error {
	tmpl := template.New(app.templatesFS, app.assetsManager)
	// Functions defined by gnd.la/app.Template
	tmpl.RawFuncs(map[string]interface{}{
		"t":       nop,
		"tn":      nop,
		"tc":      nop,
		"tnc":     nop,
		"reverse": nop,
	})
	if err := tmpl.Parse(name); err != nil {
		return err
	}
	app.AddTemplatePlugin(&template.Plugin{Template: tmpl, Position: pos})
	return nil
}