1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-23 04:51:15 +01:00
gojekyll/pages/file_test.go

43 lines
1.3 KiB
Go
Raw Normal View History

2017-07-03 09:37:14 -04:00
package pages
import (
2017-07-10 13:23:51 -04:00
"io"
2017-07-03 09:37:14 -04:00
"path/filepath"
"testing"
"github.com/osteele/gojekyll/config"
2017-07-10 13:23:51 -04:00
"github.com/osteele/gojekyll/pipelines"
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-07-10 13:23:51 -04:00
func (s siteFake) Config() *config.Config { return &s.cfg }
2017-07-24 09:32:57 -04:00
func (s siteFake) RelativePath(p string) string { return p }
2017-07-10 13:23:51 -04:00
func (s siteFake) RenderingPipeline() pipelines.PipelineInterface { return &pipelineFake{s.t} }
func (s siteFake) OutputExt(p string) string { return filepath.Ext(p) }
2017-07-03 09:37:14 -04:00
2017-07-10 13:23:51 -04:00
type pipelineFake struct{ t *testing.T }
func (p pipelineFake) OutputExt(string) string { return ".html" }
2017-08-10 10:44:04 -04:00
func (p pipelineFake) ApplyLayout(layout string, src []byte, vars liquid.Bindings) ([]byte, error) {
2017-07-10 13:23:51 -04:00
require.Equal(p.t, "layout1", layout)
return nil, nil
}
2017-08-10 10:44:04 -04:00
func (p pipelineFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
_, 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
func (p pipelineFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
return append([]byte("rendered: "), src...), nil
}