func loadTemplatesDefault(templatesDir string) multitemplate.Render { r := multitemplate.New() layoutDir := templatesDir + "/layouts/" layouts, err := filepath.Glob(layoutDir + "*/*" + conf.TMPL_SUFFIX) if err != nil { panic(err.Error()) } includeDir := templatesDir + "/includes/" includes, err := filepath.Glob(includeDir + "*" + conf.TMPL_SUFFIX) if err != nil { panic(err.Error()) } // Generate our templates map from our layouts/ and includes/ directories for _, layout := range layouts { files := append(includes, layout) tmpl := template.Must(template.ParseFiles(files...)) tmplName := strings.TrimPrefix(layout, layoutDir) tmplName = strings.TrimSuffix(tmplName, conf.TMPL_SUFFIX) log.DebugPrint("Tmpl add " + tmplName) r.Add(tmplName, tmpl) } return r }
func loadTemplatesBindata(templatesDir string) multitemplate.Render { r := multitemplate.New() layoutDir := templatesDir + "/layouts" layoutDirs, err := templates.AssetDir(layoutDir) if err != nil { panic(err.Error()) } var layouts []string for _, dir := range layoutDirs { files, err := templates.AssetDir(layoutDir + "/" + dir) if err != nil { panic(err.Error()) } // 过滤非.tmpl后缀模板 layoutFiels, err := tmplsFilter(files, layoutDir+"/"+dir) if err != nil { panic(err.Error()) } layouts = append(layouts, layoutFiels...) } includeDir := templatesDir + "/includes" includeFiels, err := templates.AssetDir(includeDir) if err != nil { panic(err.Error()) } // 过滤非.tmpl后缀模板 includes, err := tmplsFilter(includeFiels, includeDir) if err != nil { panic(err.Error()) } // Generate our templates map from our layouts/ and includes/ directories for _, layout := range layouts { files := append(includes, layout) tmpl := template.Must(parseBindataFiles(files...)) tmplName := strings.TrimPrefix(layout, layoutDir+"/") tmplName = strings.TrimSuffix(tmplName, conf.TMPL_SUFFIX) log.DebugPrint("Tmpl add " + tmplName) r.Add(tmplName, tmpl) } return r }