mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
5a66fa3954
Transformers can now be chained together, working on the output of the previous run.
29 lines
451 B
Go
29 lines
451 B
Go
package transform
|
|
|
|
import (
|
|
"io"
|
|
"bytes"
|
|
)
|
|
|
|
type chain struct {
|
|
transformers []Transformer
|
|
}
|
|
|
|
func NewChain(trs ...Transformer) Transformer {
|
|
return &chain{transformers: trs}
|
|
}
|
|
|
|
func (c *chain) Apply(r io.Reader, w io.Writer) (err error) {
|
|
in := r
|
|
for _, tr := range c.transformers {
|
|
out := new(bytes.Buffer)
|
|
err = tr.Apply(in, out)
|
|
if err != nil {
|
|
return
|
|
}
|
|
in = bytes.NewBuffer(out.Bytes())
|
|
}
|
|
|
|
_, err = io.Copy(w, in)
|
|
return
|
|
}
|