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