hugo/hugolib/siteinfo_test.go
Phil Pennock 40d05f12a7 Truncated; .Site.Params; First function
* Add `.Truncated` bool to each page; will be set true if the
  `.Summary` is truncated and it's worth showing a "more" link of some
  kind.
* Add `Params` to the site config, defining `.Site.Params` accessible
  to each page; this lets the site maintainer associate arbitrary data
  with names, on a site-wide basis.
* Provide a `First` function to templates:
  * Use-case: `{{range First 5 .Site.Recent}}` or anything else which
    is a simple iterable provided by hugolib
* Tests by me for `.Truncated` and `First`

Also @noahcampbell contributed towards this:

* Add UnitTest for `.Site.Params`:
> Digging into this test case a bit more, I'm realizing that we need
> to create a param test case to ensure that for each type we render
> (page, index, homepage, rss, etc.) that the proper fields are
> represented.  This will help us refactor without fear in the
> future.

Sample config.yaml:

```yaml
title: "Test site"
params:
  Subtitle: "More tests always good"
  AuthorName: "John Doe"
  SidebarRecentLimit: 5
```

Signed-off-by: Noah Campbell <noahcampbell@gmail.com>
2013-11-12 22:49:54 +00:00

33 lines
698 B
Go

package hugolib
import (
"testing"
"bytes"
)
const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
func TestSiteInfoParams(t *testing.T) {
s := &Site{
Config: Config{Params: map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"}},
}
s.initialize()
if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" {
t.Errorf("Unable to set site.Info.Param")
}
s.prepTemplates()
s.addTemplate("template", SITE_INFO_PARAM_TEMPLATE)
buf := new(bytes.Buffer)
err := s.renderThing(s.NewNode(), "template", buf)
if err != nil {
t.Errorf("Unable to render template: %s", err)
}
if buf.String() != "FOOBAR_PARAM" {
t.Errorf("Expected FOOBAR_PARAM: got %s", buf.String())
}
}