Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
7c9662f4
Commit
7c9662f4
authored
Feb 16, 2012
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: show example function doc comments in UI
R=gri CC=golang-dev
https://golang.org/cl/5677061
parent
11e113db
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
example.html
lib/godoc/example.html
+3
-2
godoc.go
src/cmd/godoc/godoc.go
+2
-2
example.go
src/pkg/go/ast/example.go
+6
-0
No files found.
lib/godoc/example.html
View file @
7c9662f4
...
...
@@ -4,11 +4,12 @@
</div>
<div
class=
"expanded"
>
<p
class=
"exampleHeading"
>
▾ Example{{example_suffix .Name}}
</p>
{{with .Doc}}
<p>
{{html .}}
</p>
{{end}}
<p>
Code:
</p>
<pre
class=
"code"
>
{{.Code}}
</pre>
{{
if
.Output}}
{{
with
.Output}}
<p>
Output:
</p>
<pre
class=
"output"
>
{{html .
Output
}}
</pre>
<pre
class=
"output"
>
{{html .}}
</pre>
{{end}}
</div>
</div>
src/cmd/godoc/godoc.go
View file @
7c9662f4
...
...
@@ -539,8 +539,8 @@ func example_htmlFunc(funcName string, examples []*ast.Example, fset *token.File
}
err
:=
exampleHTML
.
Execute
(
&
buf
,
struct
{
Name
,
Code
,
Output
string
}{
eg
.
Name
,
code
,
out
})
Name
,
Doc
,
Code
,
Output
string
}{
eg
.
Name
,
eg
.
Doc
,
code
,
out
})
if
err
!=
nil
{
log
.
Print
(
err
)
}
...
...
src/pkg/go/ast/example.go
View file @
7c9662f4
...
...
@@ -16,6 +16,7 @@ import (
type
Example
struct
{
Name
string
// name of the item being exemplified
Doc
string
// example function doc string
Code
Node
Comments
[]
*
CommentGroup
Output
string
// expected output
...
...
@@ -45,8 +46,13 @@ func Examples(files ...*File) []*Example {
if
!
isTest
(
name
,
"Example"
)
{
continue
}
var
doc
string
if
f
.
Doc
!=
nil
{
doc
=
f
.
Doc
.
Text
()
}
flist
=
append
(
flist
,
&
Example
{
Name
:
name
[
len
(
"Example"
)
:
],
Doc
:
doc
,
Code
:
f
.
Body
,
Comments
:
file
.
Comments
,
Output
:
exampleOutput
(
f
,
file
.
Comments
),
...
...
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