Esempio n. 1
0
func (templating *Templating) GenerateRenderer(path string) Renderer {
	return func(ctx *Context, input Response) (resp Response) {
		template := templating.Load(path)
		buffer := &bytes.Buffer{}
		template.Execute(buffer, input)
		return buffer.String()
	}
}
Esempio n. 2
0
func DraftsServer(w http.ResponseWriter, req *http.Request) {
	draftsInfo, err := ioutil.ReadDir(DRAFTS_DIR)
	if err != nil {
		log.Fatal(err)
	}

	template, err := template.ParseFile("templates/drafts.html")
	if err != nil {
		log.Fatal(err)
	}

	err = template.Execute(w, draftsInfo)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 3
0
//  Given a filename and dictionary context, create a context dict+("file"=>filename),
//  and read a template specified by relpath. See GetTemplatePath().
func ParseTemplate(filename string, dict map[string]string, relpath []string) (string, os.Error) {
	var tpath = GetTemplatePath(relpath)
	if tpath == "" {
		return "", NoTemplateError
	}
	if DEBUG && DEBUG_LEVEL > 0 {
		log.Printf("scanning: %s", tpath)
		if DEBUG_LEVEL > 1 {
			log.Printf("context:\n%v", dict)
		}
	}
	var template = template.MustParseFile(tpath, nil)
	var buff = bytes.NewBuffer(make([]byte, 0, 1<<20))
	var errTExec = template.Execute(buff, combinedData(dict, extraData(filename)))
	return buff.String(), errTExec
	//return mustache.RenderFile(tpath, dict, map[string]string{"file":filename, "test":TestName(filename)}), nil
}
Esempio n. 4
0
func (templating *Templating) Execute(path string, data interface{}) []byte {
	template := templating.Load(path)
	buffer := &bytes.Buffer{}
	template.Execute(buffer, data)
	return buffer.Bytes()
}