summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-02-10 10:13:58 -0500
committerDave Henderson <dhenderson@gmail.com>2018-03-03 10:58:05 -0500
commit96ab610f904c48fa4e85bb42e212f49eb3a4ff1c (patch)
tree81caae2b83298694798eea978a2e28380e29ef62 /docs
parent5f47dac2c1273e189f4b70b74a6dfea68cf788ff (diff)
Adding file namespace
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/content/functions/file.md116
1 files changed, 116 insertions, 0 deletions
diff --git a/docs/content/functions/file.md b/docs/content/functions/file.md
new file mode 100644
index 00000000..cff6af2c
--- /dev/null
+++ b/docs/content/functions/file.md
@@ -0,0 +1,116 @@
+---
+title: file functions
+menu:
+ main:
+ parent: functions
+---
+
+## `file.Exists`
+
+Reports whether a file or directory exists at the given path.
+
+### Usage
+```go
+file.Exists path
+```
+
+### Example
+
+_`input.tmpl`:_
+```
+{{ if (file.Exists "/tmp/foo") }}yes{{else}}no{{end}}
+```
+
+```console
+$ gomplate -f input.tmpl
+no
+$ touch /tmp/foo
+$ gomplate -f input.tmpl
+yes
+```
+
+## `file.IsDir`
+
+Reports whether a given path is a directory.
+
+### Usage
+```go
+file.IsDir path
+```
+
+### Example
+
+_`input.tmpl`:_
+```
+{{ if (file.IsDir "/tmp/foo") }}yes{{else}}no{{end}}
+```
+
+```console
+$ gomplate -f input.tmpl
+no
+$ touch /tmp/foo
+$ gomplate -f input.tmpl
+no
+$ rm /tmp/foo && mkdir /tmp/foo
+$ gomplate -f input.tmpl
+yes
+```
+
+## `file.Read`
+
+Reads a given file _as text_. Note that this will succeed if the given file
+is binary, but
+
+### Usage
+```go
+file.Read path
+```
+
+### Examples
+
+```console
+$ echo "hello world" > /tmp/hi
+$ gomplate -i '{{file.Read "/tmp/hi"}}'
+hello world
+```
+
+## `file.ReadDir`
+
+Reads a directory and lists the files and directories contained within.
+
+### Usage
+```go
+file.ReadDir path
+```
+
+### Examples
+
+```console
+$ mkdir /tmp/foo
+$ touch /tmp/foo/a; touch /tmp/foo/b; touch /tmp/foo/c
+$ mkdir /tmp/foo/d
+$ gomplate -i '{{ range (file.ReadDir "/tmp/foo") }}{{.}}{{"\n"}}{{end}}'
+a
+b
+c
+d
+```
+
+## `file.Stat`
+
+Returns a [`os.FileInfo`](https://golang.org/pkg/os/#FileInfo) describing
+the named path.
+Essentially a wrapper for Go's [`os.Stat`](https://golang.org/pkg/os/#Stat) function.
+
+### Usage
+```go
+file.Stat path
+```
+
+### Examples
+
+```console
+$ echo "hello world" > /tmp/foo
+$ gomplate -i '{{ $s := file.Stat "/tmp/foo" }}{{ $s.Mode }} {{ $s.Size }} {{ $s.Name }}'
+-rw-r--r-- 12 foo
+```