Example #1
0
// Takes a list of localization filenames and tries to load every one of them, first from the template, then from the modules.
func ReadFiles(f iface.FileSys, user_langs []string, locfiles map[string]struct{}) (map[string]interface{}, error) {
	ret := map[string]interface{}{}
	for i, _ := range locfiles {
		for _, lang := range user_langs {
			templ, err := f.SelectPlace("template")
			if err != nil {
				return nil, err
			}
			fi := templ.Directory("loc").File(i + "." + lang)
			ma, err := locReader(fi)
			if err == nil {
				ret[i] = ma
				break
			}
			mods, err := f.SelectPlace("modules")
			if err != nil {
				return nil, err
			}
			fi = mods.Directory("tpl", "loc").File(lang + ".json")
			ma, err = locReader(fi)
			if err == nil {
				ret[i] = ma
				break
			}
		}
	}
	return ret, nil
}
Example #2
0
// TODO: Implement file caching here.
// Reads the filepath relative filepath from either the current template, or the fallback module tpl folder if filepath has at least one slash in it.
// file_reader is optional, falls back to simple ioutil.ReadFile if not given. file_reader will be a custom file_reader with caching soon.
func GetFile(fs iface.FileSys, filepath string) ([]byte, error) {
	templ, err := fs.SelectPlace("template")
	if err != nil {
		return nil, err
	}
	b, err := templ.File(filepath).Read()
	if err == nil {
		return b, nil
	}
	if !PossibleModPath(filepath) {
		return nil, fmt.Errorf("Not found.")
	}
	mod, err := fs.SelectPlace("modules")
	if err != nil {
		return nil, err
	}
	mtp := getModTPath(filepath)
	return mod.Directory(mtp.modname, "tpl").File(mtp.fpath).Read()
}
Example #3
0
func existing(f iface.FileSys, s []string) string {
	if len(s) > 10 {
		panic("Ouch.")
	}
	templ, err := f.SelectPlace("template")
	if err != nil {
		panic(err)
	}
	for i, v := range s {
		if i == len(s)-1 {
			return v
		}
		ex, err := templ.File(v + ".tpl").Exists()
		if err != nil {
			panic(err)
		}
		if ex {
			return v
		}
	}
	return ""
}