Set the name of the Nav attribute to select

This commit is contained in:
Noah Campbell 2013-10-01 12:51:00 -07:00
parent 5e14af957a
commit 03d1a57fea
2 changed files with 10 additions and 5 deletions

View file

@ -8,6 +8,7 @@ import (
type NavActive struct { type NavActive struct {
Section string Section string
AttrName string
} }
func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) { func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
@ -22,7 +23,11 @@ func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
return return
} }
tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[data-nav=%s]", n.Section)) if n.AttrName == "" {
n.AttrName = "hugo-nav"
}
tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[%s=%s]", n.AttrName, n.Section))
return tr.Render(w) return tr.Render(w)
} }

View file

@ -12,8 +12,8 @@ const HTML_WITH_NAV = `<!DOCTYPE html>
<body> <body>
<nav> <nav>
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li data-nav="section_1"><a href="#">Section 1</a></li> <li hugo-nav="section_1"><a href="#">Section 1</a></li>
<li data-nav="section_2"><a href="#">Section 2</a></li> <li hugo-nav="section_2"><a href="#">Section 2</a></li>
</ul> </ul>
</nav> </nav>
</body> </body>
@ -23,8 +23,8 @@ const EXPECTED_HTML_WITH_NAV_1 = `<!DOCTYPE html><html><head></head>
<body> <body>
<nav> <nav>
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li data-nav="section_1"><a href="#">Section 1</a></li> <li hugo-nav="section_1"><a href="#">Section 1</a></li>
<li data-nav="section_2" class="active"><a href="#">Section 2</a></li> <li hugo-nav="section_2" class="active"><a href="#">Section 2</a></li>
</ul> </ul>
</nav> </nav>