2013-10-01 17:26:21 -04:00
|
|
|
package transform
|
|
|
|
|
|
|
|
import (
|
2013-11-01 01:14:11 -04:00
|
|
|
htmltran "code.google.com/p/go-html-transform/html/transform"
|
2013-10-01 22:59:35 -04:00
|
|
|
"io"
|
2013-10-01 17:26:21 -04:00
|
|
|
)
|
|
|
|
|
2013-11-01 01:14:11 -04:00
|
|
|
type chain []*htmltran.Transform
|
2013-10-01 17:26:21 -04:00
|
|
|
|
2013-11-01 01:14:11 -04:00
|
|
|
func NewChain(trs ...*htmltran.Transform) chain {
|
|
|
|
return trs
|
2013-10-01 17:26:21 -04:00
|
|
|
}
|
|
|
|
|
2013-10-01 17:42:08 -04:00
|
|
|
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
|
2013-11-01 01:14:11 -04:00
|
|
|
|
|
|
|
var tr *htmltran.Transformer
|
|
|
|
|
|
|
|
if tr, err = htmltran.NewFromReader(r); err != nil {
|
|
|
|
return
|
2013-10-01 17:26:21 -04:00
|
|
|
}
|
2013-10-01 22:59:35 -04:00
|
|
|
|
2013-11-01 01:14:11 -04:00
|
|
|
tr.ApplyAll(*c...)
|
|
|
|
|
|
|
|
return tr.Render(w)
|
2013-10-01 17:26:21 -04:00
|
|
|
}
|