funcListFiles reads and returns a slice of names from the given directory relative to the root of c.
(name string)
| 391 | // funcListFiles reads and returns a slice of names from the given |
| 392 | // directory relative to the root of c. |
| 393 | func (c TemplateContext) funcListFiles(name string) ([]string, error) { |
| 394 | if c.Root == nil { |
| 395 | return nil, fmt.Errorf("root file system not specified") |
| 396 | } |
| 397 | |
| 398 | dir, err := c.Root.Open(path.Clean(name)) |
| 399 | if err != nil { |
| 400 | return nil, err |
| 401 | } |
| 402 | defer dir.Close() |
| 403 | |
| 404 | stat, err := dir.Stat() |
| 405 | if err != nil { |
| 406 | return nil, err |
| 407 | } |
| 408 | if !stat.IsDir() { |
| 409 | return nil, fmt.Errorf("%v is not a directory", name) |
| 410 | } |
| 411 | |
| 412 | dirInfo, err := dir.Readdir(0) |
| 413 | if err != nil { |
| 414 | return nil, err |
| 415 | } |
| 416 | |
| 417 | names := make([]string, len(dirInfo)) |
| 418 | for i, fileInfo := range dirInfo { |
| 419 | names[i] = fileInfo.Name() |
| 420 | } |
| 421 | |
| 422 | return names, nil |
| 423 | } |
| 424 | |
| 425 | // funcFileExists returns true if filename can be opened successfully. |
| 426 | func (c TemplateContext) funcFileExists(filename string) (bool, error) { |