Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
5ab935f6
Commit
5ab935f6
authored
Feb 14, 2012
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: list examples in index
Fixes #2897. R=golang-dev, r CC=golang-dev
https://golang.org/cl/5658047
parent
e3f11b3f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
7 deletions
+30
-7
doc/godocs.js
doc/godocs.js
+18
-4
lib/godoc/example.html
lib/godoc/example.html
+1
-1
lib/godoc/package.html
lib/godoc/package.html
+9
-0
src/cmd/godoc/godoc.go
src/cmd/godoc/godoc.go
+2
-2
No files found.
doc/godocs.js
View file @
5ab935f6
...
...
@@ -23,7 +23,7 @@ bindEvent(window, 'load', godocs_onload);
function
godocs_onload
()
{
godocs_bindSearchEvents
();
godocs_generateTOC
();
godocs_bindExample
Toggle
s
();
godocs_bindExamples
();
}
function
godocs_bindSearchEvents
()
{
...
...
@@ -158,11 +158,14 @@ function godocs_nodeToText(node) {
return
text
;
}
function
godocs_bindExample
Toggle
s
()
{
function
godocs_bindExamples
()
{
var
examples
=
document
.
getElementsByClassName
(
"
example
"
);
for
(
var
i
=
0
;
i
<
examples
.
length
;
i
++
)
{
var
eg
=
examples
[
i
];
godocs_bindExampleToggle
(
eg
);
godocs_bindExampleToggle
(
examples
[
i
]);
}
var
links
=
document
.
getElementsByClassName
(
"
exampleLink
"
);
for
(
var
i
=
0
;
i
<
links
.
length
;
i
++
)
{
godocs_bindExampleLink
(
links
[
i
]);
}
}
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
"
;
});
}
lib/godoc/example.html
View file @
5ab935f6
<div
class=
"example"
>
<div
id=
"example_{{.Name}}"
class=
"example"
>
<div
class=
"collapsed"
>
<p
class=
"exampleHeading"
>
▹ Example
</p>
</div>
...
...
lib/godoc/package.html
View file @
5ab935f6
...
...
@@ -52,6 +52,15 @@
{{end}}
</dl>
{{if $.Examples}}
<h4>
Examples
</h4>
<dl>
{{range $.Examples}}
<dd><a
class=
"exampleLink"
href=
"#example_{{.Name}}"
>
{{.Name}}
</a></dd>
{{end}}
</dl>
{{end}}
{{with .Filenames}}
<h4>
Package files
</h4>
<p>
...
...
src/cmd/godoc/godoc.go
View file @
5ab935f6
...
...
@@ -522,8 +522,8 @@ func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.File
code
=
code
[
2
:
len
(
code
)
-
2
]
err
:=
exampleHTML
.
Execute
(
&
buf
,
struct
{
Code
,
Output
string
}{
code
,
eg
.
Output
})
Name
,
Code
,
Output
string
}{
name
,
code
,
eg
.
Output
})
if
err
!=
nil
{
log
.
Print
(
err
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment