1
1
package main
2
2
3
- var pkgTemplate = `{{with .PDoc}}
3
+ var pkgTemplate = `{{define "examples_md"}}{{- range .}}
4
+ #### <a name="example_{{.Name}}">Example{{example_suffix .Name}}</a>
5
+ {{comment_md .Doc}}
6
+ Code:
7
+ {{pre .Code}}{{if .Output}}
8
+ Output:
9
+ {{output .Output}}
10
+ {{end}}
11
+ {{end}}{{end}}{{with .PDoc}}
4
12
{{if $.IsMain}}
5
13
> {{ base .ImportPath }}
6
14
{{comment_md .Doc}}
@@ -9,13 +17,13 @@ var pkgTemplate = `{{with .PDoc}}
9
17
` + "`" + `import "{{.ImportPath}}"` + "`" + `
10
18
11
19
* [Overview](#pkg-overview)
12
- * [Index](#pkg-index){{if $.Examples}}
20
+ * [Index](#pkg-index){{if and $.Examples show_examples }}
13
21
* [Examples](#pkg-examples){{- end}}{{if $.Dirs}}
14
22
* [Subdirectories](#pkg-subdirectories){{- end}}
15
23
16
24
## <a name="pkg-overview">Overview</a>
17
25
{{comment_md .Doc}}
18
- {{example_html $ ""}}
26
+ {{template "examples_md" (examples $ "") }}
19
27
20
28
## <a name="pkg-index">Index</a>{{if .Consts}}
21
29
* [Constants](#pkg-constants){{end}}{{if .Vars}}
@@ -25,8 +33,8 @@ var pkgTemplate = `{{with .PDoc}}
25
33
* [{{node_html $ .Decl false | sanitize}}](#{{$name_html}}){{- end}}{{- range .Methods}}{{$name_html := html .Name}}
26
34
* [{{node_html $ .Decl false | sanitize}}](#{{$tname_html}}.{{$name_html}}){{- end}}{{- end}}{{- if $.Notes}}{{- range $marker, $item := $.Notes}}
27
35
* [{{noteTitle $marker | html}}s](#pkg-note-{{$marker}}){{end}}{{end}}
28
- {{if $.Examples}}
29
- #### <a name="pkg-examples">Examples</a>{{- range $.Examples }}
36
+ {{if and $.Examples show_examples }}
37
+ #### <a name="pkg-examples">Examples</a>{{- range examples $ "*" }}
30
38
* [{{example_name .Name}}](#example_{{.Name}}){{- end}}{{- end}}
31
39
{{with .Filenames}}
32
40
#### <a name="pkg-files">Package files</a>
@@ -43,7 +51,7 @@ var pkgTemplate = `{{with .PDoc}}
43
51
{{range .Funcs}}{{$name_html := html .Name}}## <a name="{{$name_html}}">func</a> [{{$name_html}}]({{posLink_url $ .Decl}})
44
52
{{node $ .Decl | pre}}
45
53
{{comment_md .Doc}}
46
- {{example_html $ .Name}}
54
+ {{template "examples_md" (examples $ .Name) }}
47
55
{{callgraph_html $ "" .Name}}{{end}}
48
56
{{range .Types}}{{$tname := .Name}}{{$tname_html := html .Name}}## <a name="{{$tname_html}}">type</a> [{{$tname_html}}]({{posLink_url $ .Decl}})
49
57
{{node $ .Decl | pre}}
@@ -53,20 +61,20 @@ var pkgTemplate = `{{with .PDoc}}
53
61
{{node $ .Decl | pre }}
54
62
{{comment_md .Doc}}{{end}}
55
63
56
- {{example_html $ $tname}}
64
+ {{template "examples_md" (examples $ $tname) }}
57
65
{{implements_html $ $tname}}
58
66
{{methodset_html $ $tname}}
59
67
60
68
{{range .Funcs}}{{$name_html := html .Name}}### <a name="{{$name_html}}">func</a> [{{$name_html}}]({{posLink_url $ .Decl}})
61
69
{{node $ .Decl | pre}}
62
70
{{comment_md .Doc}}
63
- {{example_html $ .Name}}{{end}}
71
+ {{template "examples_md" (examples $ .Name) }}{{end}}
64
72
{{callgraph_html $ "" .Name}}
65
73
66
74
{{range .Methods}}{{$name_html := html .Name}}### <a name="{{$tname_html}}.{{$name_html}}">func</a> ({{md .Recv}}) [{{$name_html}}]({{posLink_url $ .Decl}})
67
75
{{node $ .Decl | pre}}
68
76
{{comment_md .Doc}}
69
- {{$name := printf "%s_%s" $tname .Name}}{{example_html $ $name}}
77
+ {{$name := printf "%s_%s" $tname .Name}}{{template "examples_md" (examples $ $name) }}
70
78
{{callgraph_html $ .Recv .Name}}
71
79
{{end}}{{end}}{{end}}
72
80
0 commit comments