Implement field/property parsing
This commit is contained in:
45
class.go
45
class.go
@@ -11,6 +11,7 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
//go:embed class.tmpl
|
||||
@@ -152,7 +153,14 @@ func ParseClass(file string) (*Class, error) {
|
||||
return
|
||||
}
|
||||
if id == "Properties" {
|
||||
// TODO: Implement parsing properties
|
||||
s.Children().Each(func(i int, s *goquery.Selection) {
|
||||
field, err := parseField(s)
|
||||
if err != nil {
|
||||
Error.Printf("Error parsing field: %v", err)
|
||||
return
|
||||
}
|
||||
res.Fields = append(res.Fields, field)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -266,6 +274,41 @@ func getConstructor(dataContainer *goquery.Selection) (Constructor, error) {
|
||||
return resConstructor, nil
|
||||
}
|
||||
|
||||
func parseField(s *goquery.Selection) (Field, error) {
|
||||
res := Field{}
|
||||
|
||||
id, ok := s.Attr("id")
|
||||
if !ok {
|
||||
return res, fmt.Errorf("no id found")
|
||||
}
|
||||
res.Name = id
|
||||
|
||||
typeElement := s.Find("span.type")
|
||||
if typeElement.Length() == 0 {
|
||||
return res, fmt.Errorf("no type found")
|
||||
}
|
||||
res.Type = CleanUp(typeElement.Text())
|
||||
|
||||
comments := s.ChildrenFiltered("div")
|
||||
if comments.Length() == 0 {
|
||||
return res, fmt.Errorf("no comments found")
|
||||
}
|
||||
comments.Each(func(i int, s *goquery.Selection) {
|
||||
text := CleanUp(s.Text())
|
||||
if text == "" {
|
||||
return
|
||||
}
|
||||
if res.Comment != "" {
|
||||
res.Comment += ". "
|
||||
}
|
||||
res.Comment += text
|
||||
})
|
||||
res.Comment = strings.ReplaceAll(res.Comment, "\n--", ". ")
|
||||
|
||||
spew.Dump(res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func CleanUp(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.ReplaceAll(s, "\t", " ")
|
||||
|
||||
Reference in New Issue
Block a user