2017-07-03 15:37:14 +02:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
2017-07-10 19:23:51 +02:00
|
|
|
"io"
|
2017-07-03 15:37:14 +02:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/osteele/gojekyll/config"
|
2017-08-18 17:07:01 +02:00
|
|
|
"github.com/osteele/gojekyll/renderers"
|
2017-08-10 16:44:04 +02:00
|
|
|
"github.com/osteele/liquid"
|
2017-07-03 15:37:14 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-07-10 19:23:51 +02:00
|
|
|
type siteFake struct {
|
|
|
|
t *testing.T
|
|
|
|
cfg config.Config
|
2017-07-03 15:37:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 17:07:01 +02: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} }
|
|
|
|
func (s siteFake) OutputExt(p string) string { return filepath.Ext(p) }
|
2017-07-03 15:37:14 +02:00
|
|
|
|
2017-08-18 17:07:01 +02:00
|
|
|
type renderManagerFake struct{ t *testing.T }
|
2017-07-10 19:23:51 +02:00
|
|
|
|
2017-08-18 17:07:01 +02:00
|
|
|
func (p renderManagerFake) OutputExt(string) string { return ".html" }
|
|
|
|
func (p renderManagerFake) ApplyLayout(layout string, src []byte, vars liquid.Bindings) ([]byte, error) {
|
2017-07-10 19:23:51 +02:00
|
|
|
require.Equal(p.t, "layout1", layout)
|
|
|
|
return nil, nil
|
|
|
|
}
|
2017-08-18 17:07:01 +02:00
|
|
|
func (p renderManagerFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
|
2017-08-10 16:44:04 +02:00
|
|
|
_, err := io.WriteString(w, "rendered: ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = w.Write(src)
|
2017-08-10 15:06:53 +02:00
|
|
|
return err
|
2017-07-10 19:23:51 +02:00
|
|
|
}
|
2017-08-10 16:44:04 +02:00
|
|
|
|
2017-08-18 17:07:01 +02:00
|
|
|
func (p renderManagerFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
|
2017-08-10 16:44:04 +02:00
|
|
|
return append([]byte("rendered: "), src...), nil
|
|
|
|
}
|