Code polish
This commit is contained in:
9
class.go
9
class.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed class.tmpl
|
//go:embed class.tmpl
|
||||||
@@ -90,7 +91,7 @@ func (c *Class) Write(root string, tmpl *template.Template) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating output file %v: %v", c.ClassName, err)
|
return fmt.Errorf("error creating output file %v: %v", c.ClassName, err)
|
||||||
}
|
}
|
||||||
// spew.Dump(c)
|
spew.Dump(c)
|
||||||
err = tmpl.Execute(outfile, c)
|
err = tmpl.Execute(outfile, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing output file %v: %v", c.ClassName, err)
|
return fmt.Errorf("error writing output file %v: %v", c.ClassName, err)
|
||||||
@@ -128,10 +129,10 @@ func ParseClass(file string) (*Class, error) {
|
|||||||
res.ClassName = className
|
res.ClassName = className
|
||||||
|
|
||||||
classDescription, err := getClassDescription(dataContainer)
|
classDescription, err := getClassDescription(dataContainer)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return nil, fmt.Errorf("error getting class description: %w", err)
|
// return nil, fmt.Errorf("error getting class description: %w", err)
|
||||||
|
res.Description = classDescription
|
||||||
}
|
}
|
||||||
res.Description = classDescription
|
|
||||||
|
|
||||||
constructor, err := getConstructor(dataContainer)
|
constructor, err := getConstructor(dataContainer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---@diagnostic disable: missing-return, lowercase-global
|
---@diagnostic disable: missing-return, lowercase-global
|
||||||
---@class {{.ClassName}}
|
---@class {{.ClassName}}{{if ne .Description ""}}
|
||||||
---{{.Description}}
|
---{{.Description}}{{end}}
|
||||||
{{- range .Fields}}
|
{{- range .Fields}}
|
||||||
---@field {{.Name}} {{.Type}}{{if ne .Comment ""}} {{.Comment}}{{end}}
|
---@field {{.Name}} {{.Type}}{{if ne .Comment ""}} {{.Comment}}{{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
{{- end}}{{if ne .Comment ""}}
|
{{- end}}{{if ne .Comment ""}}
|
||||||
---{{.Comment}}{{end}}
|
---{{.Comment}}{{end}}
|
||||||
{{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end,
|
{{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end,
|
||||||
{{- if ne (plus1 $index) $n}}
|
{{- if ne (plus1 $index) $n}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user