Exemplo n.º 1
0
func loadTemplate(name string, funcs template.FuncMap) (*template.Template, error) {
	src, err := web.Asset("templates/" + name)
	if err != nil {
		return nil, err
	}

	return template.New(name).Funcs(funcs).Parse(string(src))
}
Exemplo n.º 2
0
func loadTemplateWithoutPipeline(name string, funcs template.FuncMap) (*template.Template, error) {
	layout, err := loadTemplate("layouts/without_pipeline.html", funcs)
	if err != nil {
		return nil, err
	}

	templateSrc, err := web.Asset("templates/" + name)
	if err != nil {
		return nil, err
	}

	_, err = layout.New(name).Parse(string(templateSrc))
	if err != nil {
		return nil, err
	}

	return layout, nil
}
Exemplo n.º 3
0
func (funcs *templateFuncs) asset(asset string) (string, error) {
	funcs.assetsL.Lock()
	defer funcs.assetsL.Unlock()

	id, found := funcs.assetIDs[asset]
	if !found {
		hash := md5.New()

		contents, err := web.Asset("public/" + asset)
		if err != nil {
			return "", err
		}

		_, err = hash.Write(contents)
		if err != nil {
			return "", err
		}

		id = fmt.Sprintf("%x", hash.Sum(nil))
	}

	return funcs.url("Public", asset+"?id="+id)
}