2017-07-03 09:37:14 -04:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
2017-08-22 10:47:34 -04:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2017-07-10 13:23:51 -04:00
|
|
|
"io"
|
2017-07-03 09:37:14 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/osteele/gojekyll/config"
|
2017-08-18 11:07:01 -04:00
|
|
|
"github.com/osteele/gojekyll/renderers"
|
2017-08-10 10:44:04 -04:00
|
|
|
"github.com/osteele/liquid"
|
2017-07-03 09:37:14 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-07-10 13:23:51 -04:00
|
|
|
type siteFake struct {
|
|
|
|
t *testing.T
|
|
|
|
cfg config.Config
|
2017-07-03 09:37:14 -04:00
|
|
|
}
|
|
|
|
|
2017-08-18 11:07:01 -04:00
|
|
|
func (s siteFake) Config() *config.Config { return &s.cfg }
|
|
|
|
func (s siteFake) RelativePath(p string) string { return p }
|
|
|
|
func (s siteFake) RendererManager() renderers.Renderers { return &renderManagerFake{s.t} }
|
2017-07-03 09:37:14 -04:00
|
|
|
|
2017-08-18 11:07:01 -04:00
|
|
|
type renderManagerFake struct{ t *testing.T }
|
2017-07-10 13:23:51 -04:00
|
|
|
|
2017-08-22 10:47:34 -04:00
|
|
|
func (rm renderManagerFake) ApplyLayout(layout string, content []byte, vars liquid.Bindings) ([]byte, error) {
|
2017-08-20 15:12:13 -04:00
|
|
|
require.Equal(rm.t, "layout1", layout)
|
2017-08-22 10:47:34 -04:00
|
|
|
return content, nil
|
2017-07-10 13:23:51 -04:00
|
|
|
}
|
2017-08-22 10:47:34 -04:00
|
|
|
|
2017-08-20 15:12:13 -04:00
|
|
|
func (rm renderManagerFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
|
2017-08-22 10:47:34 -04:00
|
|
|
if bytes.Contains(src, []byte("{% error %}")) {
|
|
|
|
return fmt.Errorf("render error")
|
|
|
|
}
|
2017-08-10 10:44:04 -04:00
|
|
|
_, err := io.WriteString(w, "rendered: ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = w.Write(src)
|
2017-08-10 09:06:53 -04:00
|
|
|
return err
|
2017-07-10 13:23:51 -04:00
|
|
|
}
|
2017-08-10 10:44:04 -04:00
|
|
|
|
2017-08-20 15:12:13 -04:00
|
|
|
func (rm renderManagerFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
|
2017-08-10 10:44:04 -04:00
|
|
|
return append([]byte("rendered: "), src...), nil
|
|
|
|
}
|