Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding missing docs for file.Walk and strings.TrimPrefix #320

Merged
merged 1 commit into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/content/functions/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,40 @@ $ echo "hello world" > /tmp/foo
$ gomplate -i '{{ $s := file.Stat "/tmp/foo" }}{{ $s.Mode }} {{ $s.Size }} {{ $s.Name }}'
-rw-r--r-- 12 foo
```

## `file.Walk`

Like a recursive [`file.ReadDir`](#file-readdir), recursively walks the file tree rooted at `path`, and returns an array of all files and directories contained within.

The files are walked in lexical order, which makes the output deterministic but means that for very large directories can be inefficient.

Walk does not follow symbolic links.

Similar to Go's [`filepath.Walk`](https://golang.org/pkg/path/filepath/#Walk) function.

### Usage

```go
file.Walk path
```

### Examples

```console
$ tree /tmp/foo
/tmp/foo
├── one
├── sub
│   ├── one
│   └── two
├── three
└── two

1 directory, 5 files
$ gomplate -i '{{ range file.Walk "/tmp/foo" }}{{ if not (file.IsDir .) }}{{.}} is a file{{"\n"}}{{end}}{{end}}'
/tmp/foo/one is a file
/tmp/foo/sub/one is a file
/tmp/foo/sub/two is a file
/tmp/foo/three is a file
/tmp/foo/two is a file
```
21 changes: 21 additions & 0 deletions docs/content/functions/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,27 @@ $ gomplate -i '{{ "_-foo-_" | strings.Trim "_-" }}
foo
```

## `strings.TrimPrefix`

Returns a string without the provided leading prefix string, if the prefix is present.

This wraps Go's [`strings.TrimPrefix`](https://golang.org/pkg/strings/#TrimPrefix).

### Usage
```go
strings.TrimPrefix prefix input
```
```go
input | strings.TrimPrefix prefix
```

#### Example

```console
$ gomplate -i '{{ "hello, world" | strings.TrimPrefix "hello, " }}'
world
```

## `strings.TrimSpace`

**Alias:** `trimSpace`
Expand Down