diff --git a/class.go b/class.go index 4197904..1c556d4 100644 --- a/class.go +++ b/class.go @@ -62,6 +62,7 @@ type ( } Constructor struct { Params []Param + Returns string Comment string } ) @@ -89,6 +90,7 @@ func (c *Class) Write(root string, tmpl *template.Template) error { if err != nil { return fmt.Errorf("error creating output file %v: %v", c.ClassName, err) } + // spew.Dump(c) err = tmpl.Execute(outfile, c) if err != nil { return fmt.Errorf("error writing output file %v: %v", c.ClassName, err) @@ -135,7 +137,7 @@ func ParseClass(file string) (*Class, error) { if err != nil { return nil, fmt.Errorf("error getting constructor: %w", err) } - constructor = constructor + res.Constructors = append(res.Constructors, constructor) // Doing div+div specifically skips only the constructor which is usually the first div // So the constructor would then be located at h1 + p + div OR h1 + div if there is no description (no p) @@ -200,7 +202,7 @@ func getConstructor(dataContainer *goquery.Selection) (Constructor, error) { types.Each(func(i int, s *goquery.Selection) { resConstructor.Params = append(resConstructor.Params, Param{ Name: strings.TrimSpace(params.Eq(i).Text()), - Type: strings.TrimSpace(types.Eq(i).Text()), + Type: MapType(strings.TrimSpace(types.Eq(i).Text())), Comment: "", }) }) @@ -251,7 +253,11 @@ func getConstructor(dataContainer *goquery.Selection) (Constructor, error) { } } case 2: - log.Printf("%#v", s.Text()) + cleaned := CleanUp(s.Text()) + if resConstructor.Returns != "" { + resConstructor.Returns += "\n" + } + resConstructor.Returns = cleaned } } }) diff --git a/class.tmpl b/class.tmpl index dc234ff..af788b2 100644 --- a/class.tmpl +++ b/class.tmpl @@ -27,7 +27,8 @@ {{- if ne .Comment ""}} ---{{.Name}} ({{.Type}}) -> {{.Comment}} {{- end}} - {{- end}} + {{- end}}{{if ne .Returns ""}} +---Returns {{.Returns}}{{end}} ---@overload fun({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}): {{$.ClassName}}{{- if ne .Comment ""}} ---{{.Comment}} {{- end}}