Reads data files inside data/ and makes data available in .Site.Data

Fixes #476.

Conflicts:
	hugolib/site.go
This commit is contained in:
Erlend Klakegg Bergheim
2015-01-20 23:08:01 +01:00
committed by bep
parent 4c7e119ca1
commit 773812de6f
4 changed files with 86 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"html/template"
"io"
"os"
"path/filepath"
"strings"
"testing"
@@ -745,3 +746,18 @@ func TestWeightedTaxonomies(t *testing.T) {
t.Errorf("Pages in unexpected order, 'bza' expected first, got '%v'", s.Taxonomies["categories"]["e"][0].Page.Title)
}
}
func TestDataDir(t *testing.T) {
sources := []source.ByteSource{
{filepath.FromSlash("test" + string(os.PathSeparator) + "foo.yaml"), []byte("bar: foofoo")},
{filepath.FromSlash("test.yaml"), []byte("hello:\n- world: foo")},
}
s := &Site{}
s.loadData(&source.InMemorySource{ByteSource: sources})
expected := "map[test:map[hello:[map[world:foo]] foo:map[bar:foofoo]]]"
if fmt.Sprint(s.Data) != expected {
t.Errorf("Expected structure '%s', got '%s'", expected, s.Data)
}
}