hugo/transform/nav.go
Noah Campbell 5a66fa3954 Chain transformers and test cases
Transformers can now be chained together, working on the output of the
previous run.
2013-10-08 18:37:50 +02:00

36 lines
605 B
Go

package transform
import (
htmltran "code.google.com/p/go-html-transform/html/transform"
"fmt"
"io"
)
type NavActive struct {
Section string
AttrName string
}
func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
var tr *htmltran.Transformer
if n.Section == "" {
_, err = io.Copy(w, r)
return
}
if tr, err = htmltran.NewFromReader(r); err != nil {
return
}
if n.AttrName == "" {
n.AttrName = "hugo-nav"
}
err = tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[%s=%s]", n.AttrName, n.Section))
if err != nil {
return
}
return tr.Render(w)
}