hugo/transform/chain.go

30 lines
450 B
Go
Raw Normal View History

package transform
import (
"bytes"
2013-10-02 02:59:35 +00:00
"io"
)
type chain struct {
transformers []Transformer
}
func NewChain(trs ...Transformer) Transformer {
return &chain{transformers: trs}
}
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
in := r
for _, tr := range c.transformers {
out := new(bytes.Buffer)
err = tr.Apply(out, in)
if err != nil {
return
}
in = bytes.NewBuffer(out.Bytes())
}
2013-10-02 02:59:35 +00:00
_, err = io.Copy(w, in)
return
}