示例#1
0
文件: display.go 项目: Laller/hypecms
// Tries to dislay a template file.
func DisplayTemplate(uni *context.Uni, filep string) error {
	_, src := uni.Req.Form["src"]
	file, err := require.R("", filep+".tpl",
		func(root, fi string) ([]byte, error) {
			return GetFileAndConvert(uni.Root, fi, uni.Opt, uni.Req.Host, nil)
		})
	if err != nil {
		return fmt.Errorf("Cant find template file %v.", filep)
	}
	if src {
		uni.Put(string(file))
		return nil
	}
	uni.Dat["_tpl"] = "/templates/" + scut.TemplateType(uni.Opt) + "/" + scut.TemplateName(uni.Opt) + "/"
	prepareAndExec(uni, string(file))
	return nil
}
示例#2
0
文件: display.go 项目: Laller/nocrud
// Tries to dislay a template file.
func (d *Display) file(filepath string) error {
	src := false
	fileContents, err := require.R("", filepath+".tpl",
		func(root, fi string) ([]byte, error) {
			return getFileAndConvert(d.ctx.FileSys(), fi)
		})
	if err != nil {
		return fmt.Errorf("Cant find template file %v.", filepath)
	}
	if src {
		displ := d.ctx.Display()
		displ.Type("html").Write([]byte(fileContents))
	}
	err = d.prepareAndExec(fileContents)
	if err != nil {
		panic(err)
	}
	return nil
}
示例#3
0
文件: display.go 项目: Laller/hypecms
// Tries to display a module file.
func DisplayFallback(uni *context.Uni, filep string) error {
	_, src := uni.Req.Form["src"]
	if strings.Index(filep, "/") != -1 {
		return fmt.Errorf("Nothing to fall back to.") // No slash in fallback path means no modulename to fall back to.
	}
	if scut.PossibleModPath(filep) {
		return fmt.Errorf("Not a possible fallback path.")
	}
	file, err := require.R("", filep+".tpl", // Tricky, care.
		func(root, fi string) ([]byte, error) {
			return GetFileAndConvert(uni.Root, fi, uni.Opt, uni.Req.Host, nil)
		})
	if err != nil {
		fmt.Errorf("Cant find fallback file %v.", filep)
	}
	if src {
		uni.Put(string(file))
		return nil
	}
	uni.Dat["_tpl"] = "/modules/" + strings.Split(filep, "/")[0] + "/tpl/"
	prepareAndExec(uni, string(file))
	return nil
}
示例#4
0
文件: display.go 项目: crufter/nocrud
// Tries to dislay a template file.
func (d *Display) getFile(filepath string) (string, error) {
	return require.R("", filepath+".tpl",
		func(root, fi string) ([]byte, error) {
			return getFileAndConvert(d.ctx.FileSys(), fi)
		})
}