mirror of
https://github.com/danog/gojekyll.git
synced 2025-01-23 05:01:14 +01:00
Collections holds a Container, not a RenderingPipeline
This commit is contained in:
parent
4426fb2c93
commit
61f92ecd96
@ -13,29 +13,24 @@ import (
|
||||
|
||||
// Collection is a Jekyll collection https://jekyllrb.com/docs/collections/.
|
||||
type Collection struct {
|
||||
Name string
|
||||
Metadata templates.VariableMap
|
||||
pages []pages.Page
|
||||
rp pages.RenderingPipeline
|
||||
Name string
|
||||
Metadata templates.VariableMap
|
||||
container pages.Container
|
||||
pages []pages.Page
|
||||
}
|
||||
|
||||
// NewCollection creates a new Collection
|
||||
func NewCollection(name string, metadata templates.VariableMap, rp pages.RenderingPipeline) *Collection {
|
||||
func NewCollection(name string, metadata templates.VariableMap, c pages.Container) *Collection {
|
||||
return &Collection{
|
||||
Name: name,
|
||||
Metadata: metadata,
|
||||
rp: rp,
|
||||
Name: name,
|
||||
Metadata: metadata,
|
||||
container: c,
|
||||
}
|
||||
}
|
||||
|
||||
// OutputExt returns the output extension.
|
||||
func (c *Collection) OutputExt(pathname string) string {
|
||||
return c.rp.OutputExt(pathname)
|
||||
}
|
||||
|
||||
// RenderingPipeline returns the rendering pipeline.
|
||||
func (c *Collection) RenderingPipeline() pages.RenderingPipeline {
|
||||
return c.rp
|
||||
return c.container.OutputExt(pathname)
|
||||
}
|
||||
|
||||
// IsPostsCollection returns true if the collection is the special "posts" collection.
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
package collections
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
@ -17,24 +14,23 @@ var tests = []struct{ in, out string }{
|
||||
{"post", ":insertion:post"},
|
||||
}
|
||||
|
||||
type MockContext struct{}
|
||||
type MockContainer struct{}
|
||||
|
||||
func (c MockContext) OutputExt(filename string) string {
|
||||
return path.Ext(filename)
|
||||
}
|
||||
func (c MockContainer) PathPrefix() string { return "" }
|
||||
func (c MockContainer) OutputExt(filename string) string { return path.Ext(filename) }
|
||||
|
||||
func (c MockContext) Render(_ io.Writer, _ []byte, _ string, _ templates.VariableMap) ([]byte, error) {
|
||||
return nil, fmt.Errorf("unimplemented")
|
||||
}
|
||||
// func (c MockPipeline) Render(_ io.Writer, _ []byte, _ string, _ templates.VariableMap) ([]byte, error) {
|
||||
// return nil, fmt.Errorf("unimplemented")
|
||||
// }
|
||||
|
||||
func (c MockContext) ApplyLayout(_ string, _ []byte, _ templates.VariableMap) ([]byte, error) {
|
||||
return nil, fmt.Errorf("unimplemented")
|
||||
}
|
||||
// func (c MockPipeline) ApplyLayout(_ string, _ []byte, _ templates.VariableMap) ([]byte, error) {
|
||||
// return nil, fmt.Errorf("unimplemented")
|
||||
// }
|
||||
|
||||
func (c MockContext) SiteVariables() templates.VariableMap { return templates.VariableMap{} }
|
||||
// func (c MockPipeline) SiteVariables() templates.VariableMap { return templates.VariableMap{} }
|
||||
|
||||
func TestNewCollection(t *testing.T) {
|
||||
ctx := MockContext{}
|
||||
ctx := MockContainer{}
|
||||
|
||||
c1 := NewCollection("c", templates.VariableMap{"output": true}, ctx)
|
||||
require.Equal(t, true, c1.Output())
|
||||
@ -45,7 +41,7 @@ func TestNewCollection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPermalinkPattern(t *testing.T) {
|
||||
ctx := MockContext{}
|
||||
ctx := MockContainer{}
|
||||
|
||||
c1 := NewCollection("c", templates.VariableMap{}, ctx)
|
||||
require.Contains(t, c1.PermalinkPattern(), ":collection")
|
||||
|
@ -31,6 +31,7 @@ type RenderingContext interface {
|
||||
SiteVariables() templates.VariableMap // value of the "site" template variable
|
||||
}
|
||||
|
||||
// RenderingPipeline applies transformations to a document.
|
||||
type RenderingPipeline interface {
|
||||
ApplyLayout(string, []byte, templates.VariableMap) ([]byte, error)
|
||||
OutputExt(pathname string) string
|
||||
|
Loading…
x
Reference in New Issue
Block a user