Exemplo n.º 1
0
func Exists(filename string) bool {
	_, err := sigil.LookPath(filename)
	if err != nil {
		return false
	}
	return true
}
Exemplo n.º 2
0
func Exists(in interface{}) (bool, error) {
	filename, _, ok := sigil.String(in)
	if !ok {
		return false, fmt.Errorf("exists must be given a string")
	}
	_, err := sigil.LookPath(filename)
	if err != nil {
		return false, nil
	}
	return true, nil
}
Exemplo n.º 3
0
func Include(filename string, args ...interface{}) (string, error) {
	path, err := sigil.LookPath(filename)
	if err != nil {
		return "", err
	}
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return "", err
	}
	sigil.PushPath(filepath.Dir(path))
	defer sigil.PopPath()
	render, err := render(data, args, filepath.Base(path))
	return render.String(), err
}
Exemplo n.º 4
0
func read(file interface{}) ([]byte, error) {
	stdin, ok := file.(stdinStr)
	if ok {
		return []byte(stdin), nil
	}
	path, ok := file.(string)
	if !ok {
		return []byte{}, fmt.Errorf("file must be path string or stdin")
	}
	filepath, err := sigil.LookPath(path)
	if err != nil {
		return []byte{}, err
	}
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return []byte{}, err
	}
	return data, nil
}
Exemplo n.º 5
0
func read(file interface{}) ([]byte, error) {
	reader, ok := file.(sigil.NamedReader)
	if ok {
		return ioutil.ReadAll(reader)
	}
	path, _, ok := sigil.String(file)
	if !ok {
		return []byte{}, fmt.Errorf("file must be stream or path string")
	}
	filepath, err := sigil.LookPath(path)
	if err != nil {
		return []byte{}, err
	}
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return []byte{}, err
	}
	return data, nil
}