func MustBuildTplInPathList(pathList []string) { for _, val := range pathList { ext := filepath.Ext(val) if ext == ".gotpl" { out, err := BuildTplOneFile(kmgFile.MustReadFile(val), false) if err != nil { panic(fmt.Sprintf("%s %s", val, err.Error())) } outFilePath := kmgFile.PathTrimExt(val) + ".go" kmgFile.MustWriteFile(outFilePath, out) } else if ext == ".gotplhtml" { out, err := BuildTplOneFile(kmgFile.MustReadFile(val), true) if err != nil { panic(fmt.Sprintf("%s %s", val, err.Error())) } outFilePath := kmgFile.PathTrimExt(val) + ".go" kmgFile.MustWriteFile(outFilePath, out) } } }
func MustBuildTplInDir(path string) { pathList, err := kmgFile.GetAllFiles(path) if err != nil { panic(err) } for _, val := range pathList { if filepath.Ext(val) != ".jst" { continue } out := MustBuildTplOneFile(kmgFile.MustReadFile(val)) outFilePath := kmgFile.PathTrimExt(val) + ".js" kmgFile.MustWriteFile(outFilePath, out) } }
// 此处返回所有需要进行缓存的文件 func cacheFileFilter(root string) []string { output := make([]string, 0, 2048) err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if info.IsDir() { return nil } ext := filepath.Ext(path) if ext == ".gotpl" || ext == ".gotplhtml" { output = append(output, path) output = append(output, kmgFile.PathTrimExt(path)+".go") } return nil }) if err != nil { panic(err) } return output }