Skip to content

Commit 4225b09

Browse files
committed
content/static/html/doc: group type and sub-items
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]>
1 parent 66d09ef commit 4225b09

File tree

5 files changed

+232
-37
lines changed

5 files changed

+232
-37
lines changed

content/static/html/doc/body.tmpl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,6 @@
117117
{{- range .Types -}}
118118
<div class="Documentation-type">
119119
{{template "item" .}}
120-
{{- range .Consts -}}
121-
<div class="Documentation-typeConstant">
122-
{{- template "declaration" . -}}
123-
</div>
124-
{{- end -}}
125-
126-
{{- range .Vars -}}
127-
<div class="Documentation-typeVariable">
128-
{{- template "declaration" . -}}
129-
</div>
130-
{{- end -}}
131-
132-
{{- range .Funcs -}}
133-
<div class="Documentation-typeFunc">
134-
{{template "item" .}}
135-
</div>
136-
{{- end -}}
137-
138-
{{- range .Methods -}}
139-
<div class="Documentation-typeMethod">
140-
{{template "item" .}}
141-
</div>
142-
{{- end -}}
143120
</div>
144121
{{- end -}}
145122
{{- else -}}
@@ -178,15 +155,38 @@
178155
{{- template "since_version" .FullName -}}
179156
</h4>{{"\n"}}
180157
</summary>
181-
{{- template "declaration" . -}}
182-
{{- template "example" .Examples -}}
158+
{{template "item_body" .}}
183159
</details>
184160
{{else}}
185161
<h4 tabindex="-1" id="{{$id}}" data-kind="{{.Kind}}" class="{{.HeaderClass}}">
186162
<span>{{.HeaderStart}} {{source_link .Name .Decl}} <a class="Documentation-idLink" href="#{{$id}}">¶</a></span>
187163
{{- template "since_version" .FullName -}}
188164
</h4>{{"\n"}}
189-
{{- template "declaration" . -}}
190-
{{- template "example" .Examples -}}
165+
{{template "item_body" .}}
191166
{{end}}
192167
{{end}}
168+
169+
{{define "item_body"}}
170+
{{- template "declaration" . -}}
171+
{{- template "example" .Examples -}}
172+
{{- range .Consts -}}
173+
<div class="Documentation-typeConstant">
174+
{{- template "declaration" . -}}
175+
</div>
176+
{{- end -}}
177+
{{- range .Vars -}}
178+
<div class="Documentation-typeVariable">
179+
{{- template "declaration" . -}}
180+
</div>
181+
{{- end -}}
182+
{{- range .Funcs -}}
183+
<div class="Documentation-typeFunc">
184+
{{template "item" .}}
185+
</div>
186+
{{- end -}}
187+
{{- range .Methods -}}
188+
<div class="Documentation-typeMethod">
189+
{{template "item" .}}
190+
</div>
191+
{{- end -}}
192+
{{end}}

internal/godoc/dochtml/testdata/deprecated-off.golden

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
<li class="Documentation-indexFunction">
1515
<a href="#GoodF">func GoodF()</a></li>
1616
<li class="Documentation-indexType"><a href="#BadT">type BadT</a></li>
17+
<li><ul class="Documentation-indexTypeFunctions">
18+
<li><a href="#NewBadTBad">func NewBadTBad() BadT</a></li>
19+
<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
20+
</ul></li>
21+
<li><ul class="Documentation-indexTypeMethods">
22+
<li><a href="#BadT.BadM">func (BadT) BadM()</a></li>
23+
<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
24+
</ul></li>
1725
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
1826
<li><ul class="Documentation-indexTypeFunctions">
1927
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a></li>
@@ -96,6 +104,51 @@ Deprecated: use GoodF.
96104
Deprecated: use GoodT.
97105
Don&#39;t use this.
98106
</p>
107+
<div class="Documentation-typeFunc">
108+
<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
109+
<span>func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a></span>
110+
<span class="Documentation-sinceVersion">
111+
</span>
112+
</h4>
113+
<div class="Documentation-declaration">
114+
<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
115+
</div>
116+
<div role="navigation" aria-label="Table of Contents">
117+
<ul class="Documentation-toc"></ul>
118+
</div><p>Deprecated: use NewBadTGood.
119+
</p>
120+
</div><div class="Documentation-typeFunc">
121+
<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
122+
<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
123+
<span class="Documentation-sinceVersion">
124+
</span>
125+
</h4>
126+
<div class="Documentation-declaration">
127+
<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
128+
</div>
129+
</div><div class="Documentation-typeMethod">
130+
<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
131+
<span>func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a></span>
132+
<span class="Documentation-sinceVersion">
133+
</span>
134+
</h4>
135+
<div class="Documentation-declaration">
136+
<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
137+
</div>
138+
<div role="navigation" aria-label="Table of Contents">
139+
<ul class="Documentation-toc"></ul>
140+
</div><p>Deprecated: use GoodM.
141+
</p>
142+
</div><div class="Documentation-typeMethod">
143+
<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
144+
<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
145+
<span class="Documentation-sinceVersion">
146+
</span>
147+
</h4>
148+
<div class="Documentation-declaration">
149+
<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
150+
</div>
151+
</div>
99152
</div><div class="Documentation-type">
100153
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
101154
<span>type <a class="Documentation-source" href="src">GoodT</a> <a class="Documentation-idLink" href="#GoodT">¶</a></span>
@@ -151,7 +204,8 @@ Deprecated: use GoodM.
151204
<div class="Documentation-declaration">
152205
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
153206
</div>
154-
</div></div></section></div>
207+
</div>
208+
</div></section></div>
155209
----
156210
<ul role="group" id="doc-outline">
157211
<li role="none">
@@ -203,10 +257,37 @@ Types
203257
</a>
204258
<ul role="group" id="nav-group-types">
205259
<li role="none">
206-
<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
260+
<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
261+
data-aria-owns="nav.group.BadT" title="type BadT"
207262
data-gtmc="doc outline link">
208263
type BadT
209264
</a>
265+
<ul role="group" id="nav.group.BadT">
266+
<li role="none">
267+
<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
268+
title="NewBadTBad()" data-gtmc="doc outline link">
269+
NewBadTBad()
270+
</a>
271+
</li>
272+
<li role="none">
273+
<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
274+
title="NewBadTGood()" data-gtmc="doc outline link">
275+
NewBadTGood()
276+
</a>
277+
</li>
278+
<li role="none">
279+
<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
280+
title="BadM()" data-gtmc="doc outline link">
281+
BadM()
282+
</a>
283+
</li>
284+
<li role="none">
285+
<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
286+
title="GoodM()" data-gtmc="doc outline link">
287+
GoodM()
288+
</a>
289+
</li>
290+
</ul>
210291
</li>
211292
<li role="none">
212293
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
@@ -257,6 +338,10 @@ GoodM()
257338
</optgroup>
258339
<optgroup label="Types">
259340
<option value="BadT">type BadT</option>
341+
<option value="NewBadTBad">NewBadTBad()</option>
342+
<option value="NewBadTGood">NewBadTGood()</option>
343+
<option value="BadT.BadM">BadM()</option>
344+
<option value="BadT.GoodM">GoodM()</option>
260345
<option value="GoodT">type GoodT</option>
261346
<option value="NewGoodTBad">NewGoodTBad()</option>
262347
<option value="NewGoodTGood">NewGoodTGood()</option>

internal/godoc/dochtml/testdata/deprecated-on.golden

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
<li class="Documentation-indexFunction">
1515
<a href="#GoodF">func GoodF()</a></li>
1616
<li class="Documentation-indexType"><a href="#BadT">type BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
17+
<li><ul class="Documentation-indexTypeFunctions">
18+
<li><a href="#NewBadTBad">func NewBadTBad() BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
19+
<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
20+
</ul></li>
21+
<li><ul class="Documentation-indexTypeMethods">
22+
<li><a href="#BadT.BadM">func (BadT) BadM()</a><span class="Documentation-indexDeprecated">deprecated</span></li>
23+
<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
24+
</ul></li>
1725
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
1826
<li><ul class="Documentation-indexTypeFunctions">
1927
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
@@ -109,6 +117,65 @@ type <a class="Documentation-source" href="src">BadT</a> <a class="Documentation
109117
Deprecated: use GoodT.
110118
Don&#39;t use this.
111119
</p>
120+
<div class="Documentation-typeFunc">
121+
<details class="Documentation-deprecatedDetails">
122+
<summary>
123+
<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
124+
<span>
125+
func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a>
126+
<span class="Documentation-deprecatedBody">deprecated</span>
127+
</span>
128+
<span class="Documentation-sinceVersion">
129+
</span>
130+
</h4>
131+
</summary>
132+
<div class="Documentation-declaration">
133+
<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
134+
</div>
135+
<div role="navigation" aria-label="Table of Contents">
136+
<ul class="Documentation-toc"></ul>
137+
</div><p>Deprecated: use NewBadTGood.
138+
</p>
139+
</details>
140+
</div><div class="Documentation-typeFunc">
141+
<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
142+
<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
143+
<span class="Documentation-sinceVersion">
144+
</span>
145+
</h4>
146+
<div class="Documentation-declaration">
147+
<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
148+
</div>
149+
</div><div class="Documentation-typeMethod">
150+
<details class="Documentation-deprecatedDetails">
151+
<summary>
152+
<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
153+
<span>
154+
func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a>
155+
<span class="Documentation-deprecatedBody">deprecated</span>
156+
</span>
157+
<span class="Documentation-sinceVersion">
158+
</span>
159+
</h4>
160+
</summary>
161+
<div class="Documentation-declaration">
162+
<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
163+
</div>
164+
<div role="navigation" aria-label="Table of Contents">
165+
<ul class="Documentation-toc"></ul>
166+
</div><p>Deprecated: use GoodM.
167+
</p>
168+
</details>
169+
</div><div class="Documentation-typeMethod">
170+
<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
171+
<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
172+
<span class="Documentation-sinceVersion">
173+
</span>
174+
</h4>
175+
<div class="Documentation-declaration">
176+
<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
177+
</div>
178+
</div>
112179
</details>
113180
</div><div class="Documentation-type">
114181
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
@@ -179,7 +246,8 @@ Deprecated: use GoodM.
179246
<div class="Documentation-declaration">
180247
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
181248
</div>
182-
</div></div></section></div>
249+
</div>
250+
</div></section></div>
183251
----
184252
<ul role="group" id="doc-outline">
185253
<li role="none">
@@ -231,10 +299,37 @@ Types
231299
</a>
232300
<ul role="group" id="nav-group-types">
233301
<li role="none">
234-
<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
302+
<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
303+
data-aria-owns="nav.group.BadT" title="type BadT"
235304
data-gtmc="doc outline link">
236305
type BadT
237306
</a>
307+
<ul role="group" id="nav.group.BadT">
308+
<li role="none">
309+
<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
310+
title="NewBadTBad()" data-gtmc="doc outline link">
311+
NewBadTBad()
312+
</a>
313+
</li>
314+
<li role="none">
315+
<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
316+
title="NewBadTGood()" data-gtmc="doc outline link">
317+
NewBadTGood()
318+
</a>
319+
</li>
320+
<li role="none">
321+
<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
322+
title="BadM()" data-gtmc="doc outline link">
323+
BadM()
324+
</a>
325+
</li>
326+
<li role="none">
327+
<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
328+
title="GoodM()" data-gtmc="doc outline link">
329+
GoodM()
330+
</a>
331+
</li>
332+
</ul>
238333
</li>
239334
<li role="none">
240335
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
@@ -285,6 +380,10 @@ GoodM()
285380
</optgroup>
286381
<optgroup label="Types">
287382
<option value="BadT">type BadT</option>
383+
<option value="NewBadTBad">NewBadTBad()</option>
384+
<option value="NewBadTGood">NewBadTGood()</option>
385+
<option value="BadT.BadM">BadM()</option>
386+
<option value="BadT.GoodM">GoodM()</option>
288387
<option value="GoodT">type GoodT</option>
289388
<option value="NewGoodTBad">NewGoodTBad()</option>
290389
<option value="NewGoodTGood">NewGoodTGood()</option>

internal/godoc/dochtml/testdata/deprecated.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ func BadF() {}
2626

2727
type GoodT int
2828

29-
// BadT is bad.
30-
// Deprecated: use GoodT.
31-
// Don't use this.
32-
type BadT int
33-
3429
func NewGoodTGood() GoodT {}
3530

3631
// NewGoodTBad is bad.
@@ -42,3 +37,18 @@ func (GoodT) GoodM() {}
4237
// BadM is bad.
4338
// Deprecated: use GoodM.
4439
func (GoodT) BadM() {}
40+
41+
// BadT is bad.
42+
// Deprecated: use GoodT.
43+
// Don't use this.
44+
type BadT int
45+
46+
func NewBadTGood() BadT {}
47+
48+
// Deprecated: use NewBadTGood.
49+
func NewBadTBad() BadT {}
50+
51+
func (BadT) GoodM() {}
52+
53+
// Deprecated: use GoodM.
54+
func (BadT) BadM() {}

internal/godoc/dochtml/testdata/everydecl.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ attributes.
185185
</div><p>method
186186
BUG(uid): this verifies that notes are rendered
187187
</p>
188-
</div></div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
188+
</div>
189+
</div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
189190
<section class="Documentation-notes"><div class="Documentation-note">
190191
<h3 tabindex="-1" id="pkg-note-BUG" class="Documentation-noteHeader">Bugs <a href="#pkg-note-BUG">¶</a></h3>
191192
<ul class="Documentation-noteList" style="padding-left: 20px; list-style: initial;">

0 commit comments

Comments
 (0)