docs: Add doc and a test for readDir
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 31 Mar 2016 21:16:42 +0000 (23:16 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 31 Mar 2016 21:16:42 +0000 (23:16 +0200)
Fixes #2009

docs/content/templates/functions.md
tpl/template_funcs_test.go

index fe0f2e2514dd611554ba2550adce74fc56d5e815..0573978de181e9a9bf8339b7c729dc840d8f48f3 100644 (file)
@@ -337,6 +337,15 @@ e.g.
     {{ end }}
 
 ## Files    
+
+### readDir
+
+Gets a directory listing from a directory relative to the current project working dir. 
+
+So, If the project working dir has a single file named `README.txt`:
+
+`{{ range (readDir ".") }}{{ .Name }}{{ end }}` → "README.txt"
+
 ### readFile
 Reads a file from disk and converts it into a string. Note that the filename must be relative to the current project working dir.
  So, if you have a file with the name `README.txt` in the root of your project with the content `Hugo Rocks!`:
index efb583867ce0d4048e52d7bb230f0ab283acbd16..a36629afdd3bd9519e66dc4dd0d1e3b0eb870e8b 100644 (file)
@@ -121,6 +121,7 @@ safeURL: {{ "http://gohugo.io" | safeURL | safeURL }}
 safeJS: {{ "(1*2)" | safeJS | safeJS }}
 plainify: {{ plainify  "Hello <strong>world</strong>, gophers!" }}
 readFile: {{ readFile "README.txt" }}
+readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }}
 `
        expected := `chomp: <p>Blockhead</p>
 dateFormat: Wednesday, Jan 21, 2015
@@ -166,6 +167,7 @@ safeURL: http://gohugo.io
 safeJS: (1*2)
 plainify: Hello world, gophers!
 readFile: Hugo Rocks!
+readDir: README.txt
 `
 
        var b bytes.Buffer