8
8
"go/token"
9
9
"html/template"
10
10
"io/ioutil"
11
- "regexp"
12
11
"strings"
13
12
)
14
13
@@ -73,7 +72,8 @@ func classFromFile(filepath string) Class {
73
72
return class
74
73
}
75
74
// Retrieve class comments
76
- class .Comment = template .HTML (allComments .findCommentFor (class .Line ))
75
+ comments := allComments .findCommentFor (class .Line )
76
+ class .Comment = template .HTML (comments .Description )
77
77
78
78
// Return class if there is not built-in methods
79
79
if methods == nil {
@@ -95,10 +95,10 @@ func classFromFile(filepath string) Class {
95
95
method .FnLine = fset .Position (thisExpr .Key .(* ast.Ident ).NamePos ).Line
96
96
}
97
97
if name == "Fn" {
98
- comments := allComments .findCommentFor (method .FnLine )
99
- method .Params = ExtractParams ( comments )
100
- method .Returns = ExtractReturns ( comments )
101
- method .Comment = template .HTML (comments )
98
+ methodComments := allComments .findCommentFor (method .FnLine )
99
+ method .Params = methodComments . Params
100
+ method .Returns = methodComments . Returns
101
+ method .Comment = template .HTML (methodComments . Description )
102
102
}
103
103
}
104
104
allMethods = append (allMethods , method )
@@ -119,72 +119,3 @@ func Write(filepath string, classes []Class) {
119
119
panic (err )
120
120
}
121
121
}
122
-
123
- func ExtractParams (comments string ) []Param {
124
- params := []Param {}
125
- lines := strings .Split (comments , "\n " )
126
- for _ , line := range lines {
127
- matched , err := regexp .MatchString ("^ @param" , line )
128
- if err != nil {
129
- panic (err )
130
- }
131
- if matched {
132
- fmt .Println ("MATCHED!!!" )
133
- fmt .Println (line )
134
- param := Param {}
135
- words := strings .Split (line , " " )
136
- words = words [1 :len (words )]
137
- fmt .Println (words )
138
- if len (words ) > 1 {
139
- fmt .Println (words [1 ])
140
- param .Name = words [1 ]
141
- }
142
- if len (words ) > 2 {
143
- fmt .Println (words [2 ])
144
- class := words [2 ]
145
- class = strings .Replace (class , "[" , "" , 1 )
146
- class = strings .Replace (class , "]" , "" , 1 )
147
- param .Class = class
148
- }
149
- if len (words ) > 3 {
150
- fmt .Println (words [3 :len (words )])
151
- theRest := strings .Join (words [3 :len (words )], " " )
152
- param .Description = template .HTML (theRest )
153
- }
154
- if param .Name != "" {
155
- params = append (params , param )
156
- }
157
- }
158
- }
159
- return params
160
- }
161
-
162
- func ExtractReturns (comments string ) []Return {
163
- returns := []Return {}
164
- lines := strings .Split (comments , "\n " )
165
- for _ , line := range lines {
166
- matched , err := regexp .MatchString ("^ @return" , line )
167
- if err != nil {
168
- panic (err )
169
- }
170
- if matched {
171
- r := Return {}
172
- words := strings .Split (line , " " )
173
- words = words [1 :len (words )]
174
- if len (words ) > 1 {
175
- class := words [1 ]
176
- class = strings .Replace (class , "[" , "" , 1 )
177
- class = strings .Replace (class , "]" , "" , 1 )
178
- r .Class = class
179
- }
180
- if len (words ) > 2 {
181
- theRest := strings .Join (words [3 :len (words )], " " )
182
- r .Description = template .HTML (theRest )
183
- }
184
- if r .Class != "" {
185
- returns = append (returns , r )
186
- }
187
- }
188
- }
189
- return returns
190
- }
0 commit comments