Skip to content

Commit 455fbc8

Browse files
committed
add params and returns to method bar
1 parent ae093b9 commit 455fbc8

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

assets/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,7 @@ code {
122122
font-size: 12px;
123123
padding-left: 5px;
124124
}
125+
126+
.return-separator {
127+
padding-left: 10px;
128+
}

comment.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ func (a *AllComments) findCommentFor(i int) CommentStruct {
5858
for _, comment := range comments.List {
5959
comment.Text = strings.Replace(comment.Text, "//", "", 1)
6060
if IsParamSpec(comment.Text) {
61-
methodComments.Params = append(methodComments.Params, ExtractParam(comment.Text))
61+
param := ExtractParam(comment.Text)
62+
if param.Name != "" && param.Class != "" {
63+
methodComments.Params = append(methodComments.Params, param)
64+
}
6265
} else if IsReturnSpec(comment.Text) {
63-
methodComments.Returns = append(methodComments.Returns, ExtractReturn(comment.Text))
66+
r := ExtractReturn(comment.Text)
67+
if r.Class != "" {
68+
methodComments.Returns = append(methodComments.Returns, r)
69+
}
6470
} else {
6571
result = append(result, comment.Text)
6672
}
@@ -75,20 +81,16 @@ func ExtractParam(line string) Param {
7581
param := Param{}
7682
words := strings.Split(line, " ")
7783
words = words[1:len(words)]
78-
// fmt.Println(words)
7984
if len(words) > 1 {
80-
// fmt.Println(words[1])
8185
param.Name = words[1]
8286
}
8387
if len(words) > 2 {
84-
// fmt.Println(words[2])
8588
class := words[2]
8689
class = strings.Replace(class, "[", "", 1)
8790
class = strings.Replace(class, "]", "", 1)
8891
param.Class = class
8992
}
9093
if len(words) > 3 {
91-
// fmt.Println(words[3:len(words)])
9294
theRest := strings.Join(words[3:len(words)], " ")
9395
param.Description = template.HTML(theRest)
9496
}

html.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import (
99
"strings"
1010
)
1111

12+
var fns = template.FuncMap{
13+
"last": func(index int, length int) bool {
14+
return index == length-1
15+
},
16+
}
17+
1218
func generateIndexFile(classes Classes) {
1319
indexFile, err := os.OpenFile("./docs/index.html", os.O_CREATE|os.O_WRONLY, 0777)
1420
panicIf(err)
@@ -32,7 +38,7 @@ func generateIndexFile(classes Classes) {
3238
func generateClassFile(classes Classes, class Class) {
3339
classFile, err := os.OpenFile("./docs/"+class.Filename+".html", os.O_CREATE|os.O_WRONLY, 0777)
3440
panicIf(err)
35-
classTemplate, err := template.New(class.Filename).ParseFiles(
41+
classTemplate, err := template.New(class.Filename).Funcs(fns).ParseFiles(
3642
"./templates/html/class.html",
3743
"./templates/html/layout.html",
3844
"./templates/html/sidebar.html",

templates/html/class.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,32 @@ <h2>Instance Methods</h2>
1111
{{ range .class.InstanceMethods }}
1212
<h4 class="method">
1313
<a class="prefix" href="#{{.FnName}}">#</a>
14-
<span class="title" id="{{.FnName}}">{{.FnName}}</span>
14+
<p class="title" id="{{.FnName}}">
15+
<span>{{.FnName}}</span>
16+
{{ $length := len .Params }} {{ if gt $length 0 }}
17+
<span>(</span>
18+
{{ range $i, $e := .Params }}
19+
{{ if last $i $length }}
20+
<span>{{.Name}}</span>
21+
{{ else }}
22+
<span>{{.Name}}, </span>
23+
{{ end }}
24+
{{ end }}
25+
<span>)</span>
26+
{{ end }}
27+
{{ $length := len .Returns }} {{ if gt $length 0 }}
28+
<span class="return-separator"> => </span>
29+
{{ end }}
30+
{{ $length := len .Returns }} {{ if gt $length 0 }}
31+
{{ range $i, $e := .Returns }}
32+
{{ if last $i $length }}
33+
<span>{{.Class}}</span>
34+
{{ else }}
35+
<span>{{.Class}}, </span>
36+
{{ end }}
37+
{{ end }}
38+
{{ end }}
39+
</p>
1540
</h4>
1641
<div class="method-comment">
1742
<div>

0 commit comments

Comments
 (0)