Skip to content

Commit

Permalink
content/static/html/doc: group type and sub-items
Browse files Browse the repository at this point in the history
Rewrite body.tmpl so that if a type is deprecated, its methods and
functions are hidden along with the type itself.

For golang/go#17056

Change-Id: I7ba11f0902414e25c6267747d1a68aa26751e95a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/315509
Trust: Jonathan Amsterdam <[email protected]>
Run-TryBot: Jonathan Amsterdam <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Julie Qiu <[email protected]>
  • Loading branch information
jba committed May 4, 2021
1 parent 66d09ef commit 4225b09
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 37 deletions.
54 changes: 27 additions & 27 deletions content/static/html/doc/body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,6 @@
{{- range .Types -}}
<div class="Documentation-type">
{{template "item" .}}
{{- range .Consts -}}
<div class="Documentation-typeConstant">
{{- template "declaration" . -}}
</div>
{{- end -}}

{{- range .Vars -}}
<div class="Documentation-typeVariable">
{{- template "declaration" . -}}
</div>
{{- end -}}

{{- range .Funcs -}}
<div class="Documentation-typeFunc">
{{template "item" .}}
</div>
{{- end -}}

{{- range .Methods -}}
<div class="Documentation-typeMethod">
{{template "item" .}}
</div>
{{- end -}}
</div>
{{- end -}}
{{- else -}}
Expand Down Expand Up @@ -178,15 +155,38 @@
{{- template "since_version" .FullName -}}
</h4>{{"\n"}}
</summary>
{{- template "declaration" . -}}
{{- template "example" .Examples -}}
{{template "item_body" .}}
</details>
{{else}}
<h4 tabindex="-1" id="{{$id}}" data-kind="{{.Kind}}" class="{{.HeaderClass}}">
<span>{{.HeaderStart}} {{source_link .Name .Decl}} <a class="Documentation-idLink" href="#{{$id}}">¶</a></span>
{{- template "since_version" .FullName -}}
</h4>{{"\n"}}
{{- template "declaration" . -}}
{{- template "example" .Examples -}}
{{template "item_body" .}}
{{end}}
{{end}}

{{define "item_body"}}
{{- template "declaration" . -}}
{{- template "example" .Examples -}}
{{- range .Consts -}}
<div class="Documentation-typeConstant">
{{- template "declaration" . -}}
</div>
{{- end -}}
{{- range .Vars -}}
<div class="Documentation-typeVariable">
{{- template "declaration" . -}}
</div>
{{- end -}}
{{- range .Funcs -}}
<div class="Documentation-typeFunc">
{{template "item" .}}
</div>
{{- end -}}
{{- range .Methods -}}
<div class="Documentation-typeMethod">
{{template "item" .}}
</div>
{{- end -}}
{{end}}
89 changes: 87 additions & 2 deletions internal/godoc/dochtml/testdata/deprecated-off.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<li class="Documentation-indexFunction">
<a href="#GoodF">func GoodF()</a></li>
<li class="Documentation-indexType"><a href="#BadT">type BadT</a></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewBadTBad">func NewBadTBad() BadT</a></li>
<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
</ul></li>
<li><ul class="Documentation-indexTypeMethods">
<li><a href="#BadT.BadM">func (BadT) BadM()</a></li>
<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
</ul></li>
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a></li>
Expand Down Expand Up @@ -96,6 +104,51 @@ Deprecated: use GoodF.
Deprecated: use GoodT.
Don&#39;t use this.
</p>
<div class="Documentation-typeFunc">
<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
<span>func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
</div>
<div role="navigation" aria-label="Table of Contents">
<ul class="Documentation-toc"></ul>
</div><p>Deprecated: use NewBadTGood.
</p>
</div><div class="Documentation-typeFunc">
<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
</div>
</div><div class="Documentation-typeMethod">
<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
<span>func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
</div>
<div role="navigation" aria-label="Table of Contents">
<ul class="Documentation-toc"></ul>
</div><p>Deprecated: use GoodM.
</p>
</div><div class="Documentation-typeMethod">
<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
</div>
</div>
</div><div class="Documentation-type">
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
<span>type <a class="Documentation-source" href="src">GoodT</a> <a class="Documentation-idLink" href="#GoodT">¶</a></span>
Expand Down Expand Up @@ -151,7 +204,8 @@ Deprecated: use GoodM.
<div class="Documentation-declaration">
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
</div>
</div></div></section></div>
</div>
</div></section></div>
----
<ul role="group" id="doc-outline">
<li role="none">
Expand Down Expand Up @@ -203,10 +257,37 @@ Types
</a>
<ul role="group" id="nav-group-types">
<li role="none">
<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
data-aria-owns="nav.group.BadT" title="type BadT"
data-gtmc="doc outline link">
type BadT
</a>
<ul role="group" id="nav.group.BadT">
<li role="none">
<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
title="NewBadTBad()" data-gtmc="doc outline link">
NewBadTBad()
</a>
</li>
<li role="none">
<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
title="NewBadTGood()" data-gtmc="doc outline link">
NewBadTGood()
</a>
</li>
<li role="none">
<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
title="BadM()" data-gtmc="doc outline link">
BadM()
</a>
</li>
<li role="none">
<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
title="GoodM()" data-gtmc="doc outline link">
GoodM()
</a>
</li>
</ul>
</li>
<li role="none">
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
Expand Down Expand Up @@ -257,6 +338,10 @@ GoodM()
</optgroup>
<optgroup label="Types">
<option value="BadT">type BadT</option>
<option value="NewBadTBad">NewBadTBad()</option>
<option value="NewBadTGood">NewBadTGood()</option>
<option value="BadT.BadM">BadM()</option>
<option value="BadT.GoodM">GoodM()</option>
<option value="GoodT">type GoodT</option>
<option value="NewGoodTBad">NewGoodTBad()</option>
<option value="NewGoodTGood">NewGoodTGood()</option>
Expand Down
103 changes: 101 additions & 2 deletions internal/godoc/dochtml/testdata/deprecated-on.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<li class="Documentation-indexFunction">
<a href="#GoodF">func GoodF()</a></li>
<li class="Documentation-indexType"><a href="#BadT">type BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewBadTBad">func NewBadTBad() BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
</ul></li>
<li><ul class="Documentation-indexTypeMethods">
<li><a href="#BadT.BadM">func (BadT) BadM()</a><span class="Documentation-indexDeprecated">deprecated</span></li>
<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
</ul></li>
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
Expand Down Expand Up @@ -109,6 +117,65 @@ type <a class="Documentation-source" href="src">BadT</a> <a class="Documentation
Deprecated: use GoodT.
Don&#39;t use this.
</p>
<div class="Documentation-typeFunc">
<details class="Documentation-deprecatedDetails">
<summary>
<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
<span>
func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a>
<span class="Documentation-deprecatedBody">deprecated</span>
</span>
<span class="Documentation-sinceVersion">
</span>
</h4>
</summary>
<div class="Documentation-declaration">
<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
</div>
<div role="navigation" aria-label="Table of Contents">
<ul class="Documentation-toc"></ul>
</div><p>Deprecated: use NewBadTGood.
</p>
</details>
</div><div class="Documentation-typeFunc">
<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
</div>
</div><div class="Documentation-typeMethod">
<details class="Documentation-deprecatedDetails">
<summary>
<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
<span>
func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a>
<span class="Documentation-deprecatedBody">deprecated</span>
</span>
<span class="Documentation-sinceVersion">
</span>
</h4>
</summary>
<div class="Documentation-declaration">
<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
</div>
<div role="navigation" aria-label="Table of Contents">
<ul class="Documentation-toc"></ul>
</div><p>Deprecated: use GoodM.
</p>
</details>
</div><div class="Documentation-typeMethod">
<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
<div class="Documentation-declaration">
<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
</div>
</div>
</details>
</div><div class="Documentation-type">
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
Expand Down Expand Up @@ -179,7 +246,8 @@ Deprecated: use GoodM.
<div class="Documentation-declaration">
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
</div>
</div></div></section></div>
</div>
</div></section></div>
----
<ul role="group" id="doc-outline">
<li role="none">
Expand Down Expand Up @@ -231,10 +299,37 @@ Types
</a>
<ul role="group" id="nav-group-types">
<li role="none">
<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
data-aria-owns="nav.group.BadT" title="type BadT"
data-gtmc="doc outline link">
type BadT
</a>
<ul role="group" id="nav.group.BadT">
<li role="none">
<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
title="NewBadTBad()" data-gtmc="doc outline link">
NewBadTBad()
</a>
</li>
<li role="none">
<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
title="NewBadTGood()" data-gtmc="doc outline link">
NewBadTGood()
</a>
</li>
<li role="none">
<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
title="BadM()" data-gtmc="doc outline link">
BadM()
</a>
</li>
<li role="none">
<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
title="GoodM()" data-gtmc="doc outline link">
GoodM()
</a>
</li>
</ul>
</li>
<li role="none">
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
Expand Down Expand Up @@ -285,6 +380,10 @@ GoodM()
</optgroup>
<optgroup label="Types">
<option value="BadT">type BadT</option>
<option value="NewBadTBad">NewBadTBad()</option>
<option value="NewBadTGood">NewBadTGood()</option>
<option value="BadT.BadM">BadM()</option>
<option value="BadT.GoodM">GoodM()</option>
<option value="GoodT">type GoodT</option>
<option value="NewGoodTBad">NewGoodTBad()</option>
<option value="NewGoodTGood">NewGoodTGood()</option>
Expand Down
20 changes: 15 additions & 5 deletions internal/godoc/dochtml/testdata/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ func BadF() {}

type GoodT int

// BadT is bad.
// Deprecated: use GoodT.
// Don't use this.
type BadT int

func NewGoodTGood() GoodT {}

// NewGoodTBad is bad.
Expand All @@ -42,3 +37,18 @@ func (GoodT) GoodM() {}
// BadM is bad.
// Deprecated: use GoodM.
func (GoodT) BadM() {}

// BadT is bad.
// Deprecated: use GoodT.
// Don't use this.
type BadT int

func NewBadTGood() BadT {}

// Deprecated: use NewBadTGood.
func NewBadTBad() BadT {}

func (BadT) GoodM() {}

// Deprecated: use GoodM.
func (BadT) BadM() {}
3 changes: 2 additions & 1 deletion internal/godoc/dochtml/testdata/everydecl.golden
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ attributes.
</div><p>method
BUG(uid): this verifies that notes are rendered
</p>
</div></div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
</div>
</div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
<section class="Documentation-notes"><div class="Documentation-note">
<h3 tabindex="-1" id="pkg-note-BUG" class="Documentation-noteHeader">Bugs <a href="#pkg-note-BUG">¶</a></h3>
<ul class="Documentation-noteList" style="padding-left: 20px; list-style: initial;">
Expand Down

0 comments on commit 4225b09

Please sign in to comment.