Implement method return comments
This commit is contained in:
93
class.go
93
class.go
@@ -11,7 +11,6 @@ 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
|
||||||
@@ -385,72 +384,50 @@ func parseMethod(s *goquery.Selection) (Method, error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if s.Is("div.indented") && state == 1 {
|
if s.Is("div.indented") {
|
||||||
log.Printf("%#v", state)
|
if state == 1 {
|
||||||
parameter := ""
|
parameter := ""
|
||||||
html, err := s.Html()
|
html, err := s.Html()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error parsing html: %v", err)
|
Error.Printf("Error parsing html: %v", err)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
html = strings.ReplaceAll(html, "\t", "")
|
|
||||||
htmlLines := strings.Split(html, "\n")
|
|
||||||
for _, line := range htmlLines {
|
|
||||||
if strings.Contains(line, "<span class=\"parameter\">") {
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
line = strings.ReplaceAll(line, "<span class=\"parameter\">", "")
|
|
||||||
line = strings.ReplaceAll(line, "</span>", "")
|
|
||||||
parameter = line
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if strings.Contains(line, "<br/>") {
|
html = strings.ReplaceAll(html, "\t", "")
|
||||||
comment := strings.TrimSpace(line)
|
htmlLines := strings.Split(html, "\n")
|
||||||
comment = strings.ReplaceAll(comment, "<br/>", "")
|
for _, line := range htmlLines {
|
||||||
for i := range res.Params {
|
if strings.Contains(line, "<span class=\"parameter\">") {
|
||||||
if res.Params[i].Name == parameter {
|
line = strings.TrimSpace(line)
|
||||||
res.Params[i].Comment = comment
|
line = strings.ReplaceAll(line, "<span class=\"parameter\">", "")
|
||||||
break
|
line = strings.ReplaceAll(line, "</span>", "")
|
||||||
|
parameter = line
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(line, "<br/>") {
|
||||||
|
comment := strings.TrimSpace(line)
|
||||||
|
comment = strings.ReplaceAll(comment, "<br/>", "")
|
||||||
|
for i := range res.Params {
|
||||||
|
if res.Params[i].Name == parameter {
|
||||||
|
res.Params[i].Comment = comment
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if state == 2 {
|
||||||
|
text := CleanUp(s.Text())
|
||||||
|
if text == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO: Figure out what to do when a function
|
||||||
|
if res.Returns[0].Comment != "" {
|
||||||
|
res.Returns[0].Comment += "\n"
|
||||||
|
}
|
||||||
|
res.Returns[0].Comment += text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// <div id="addCargo" class="codecontainer">
|
|
||||||
// <div id="addCargo" class="function">
|
|
||||||
// <p>
|
|
||||||
// <span class="keyword">function unsigned int</span> addCargo(<span
|
|
||||||
// class="type">TradingGood</span>
|
|
||||||
// <span class="parameter">good</span>, <span class="type">int</span> <span
|
|
||||||
// class="parameter">amount</span>) <br />
|
|
||||||
// </p>
|
|
||||||
// </div>
|
|
||||||
// <div id="addCargo" class="">
|
|
||||||
// <p>
|
|
||||||
// Adds cargo to the entity. If the amount specified exceeds the maximum capacity of the cargo
|
|
||||||
// bay, as
|
|
||||||
// much cargo as still fits in will be added.
|
|
||||||
// </p>
|
|
||||||
// <p><span class="docheader">Parameters</span></p>
|
|
||||||
// <div class="indented">
|
|
||||||
// <span class="parameter">good</span>
|
|
||||||
// TradingGood that is to be added. <br />
|
|
||||||
// <span class="parameter">amount</span>
|
|
||||||
// The amount of cargo that should be added. <br />
|
|
||||||
// </div>
|
|
||||||
// <p><span class="docheader">Returns</span></p>
|
|
||||||
// <div class="indented">
|
|
||||||
// <p>
|
|
||||||
// How much was actually added (can be less than amount when cargo bay is full)
|
|
||||||
// </p>
|
|
||||||
// </div>
|
|
||||||
// </p>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
spew.Dump(res)
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user