mirror of
https://github.com/golang/go
synced 2024-11-21 15:44:44 -07:00
godoc: list examples in index
Fixes #2897. R=golang-dev, r CC=golang-dev https://golang.org/cl/5658047
This commit is contained in:
parent
e3f11b3f3c
commit
5ab935f68a
@ -23,7 +23,7 @@ bindEvent(window, 'load', godocs_onload);
|
|||||||
function godocs_onload() {
|
function godocs_onload() {
|
||||||
godocs_bindSearchEvents();
|
godocs_bindSearchEvents();
|
||||||
godocs_generateTOC();
|
godocs_generateTOC();
|
||||||
godocs_bindExampleToggles();
|
godocs_bindExamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
function godocs_bindSearchEvents() {
|
function godocs_bindSearchEvents() {
|
||||||
@ -158,11 +158,14 @@ function godocs_nodeToText(node) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function godocs_bindExampleToggles() {
|
function godocs_bindExamples() {
|
||||||
var examples = document.getElementsByClassName("example");
|
var examples = document.getElementsByClassName("example");
|
||||||
for (var i = 0; i < examples.length; i++) {
|
for (var i = 0; i < examples.length; i++) {
|
||||||
var eg = examples[i];
|
godocs_bindExampleToggle(examples[i]);
|
||||||
godocs_bindExampleToggle(eg);
|
}
|
||||||
|
var links = document.getElementsByClassName("exampleLink");
|
||||||
|
for (var i = 0; i < links.length; i++) {
|
||||||
|
godocs_bindExampleLink(links[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function godocs_bindExampleToggle(eg) {
|
function godocs_bindExampleToggle(eg) {
|
||||||
@ -177,3 +180,14 @@ function godocs_bindExampleToggle(eg) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function godocs_bindExampleLink(l) {
|
||||||
|
var prefix = "example_";
|
||||||
|
bindEvent(l, "click", function() {
|
||||||
|
var i = l.href.indexOf("#"+prefix);
|
||||||
|
if (i < 0)
|
||||||
|
return;
|
||||||
|
var id = prefix + l.href.slice(i+1+prefix.length);
|
||||||
|
var eg = document.getElementById(id);
|
||||||
|
eg.className = "exampleVisible";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<div class="example">
|
<div id="example_{{.Name}}" class="example">
|
||||||
<div class="collapsed">
|
<div class="collapsed">
|
||||||
<p class="exampleHeading">▹ Example</p>
|
<p class="exampleHeading">▹ Example</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,6 +52,15 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
{{if $.Examples}}
|
||||||
|
<h4>Examples</h4>
|
||||||
|
<dl>
|
||||||
|
{{range $.Examples}}
|
||||||
|
<dd><a class="exampleLink" href="#example_{{.Name}}">{{.Name}}</a></dd>
|
||||||
|
{{end}}
|
||||||
|
</dl>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{with .Filenames}}
|
{{with .Filenames}}
|
||||||
<h4>Package files</h4>
|
<h4>Package files</h4>
|
||||||
<p>
|
<p>
|
||||||
|
@ -522,8 +522,8 @@ func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.File
|
|||||||
code = code[2 : len(code)-2]
|
code = code[2 : len(code)-2]
|
||||||
|
|
||||||
err := exampleHTML.Execute(&buf, struct {
|
err := exampleHTML.Execute(&buf, struct {
|
||||||
Code, Output string
|
Name, Code, Output string
|
||||||
}{code, eg.Output})
|
}{name, code, eg.Output})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user