Refine the template to fix excessive newlines
This commit is contained in:
39
main.go
39
main.go
@@ -30,6 +30,12 @@ func init() {
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
}
|
||||
|
||||
var fns = template.FuncMap{
|
||||
"plus1": func(x int) int {
|
||||
return x + 1
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
files := flag.Args()
|
||||
@@ -49,25 +55,42 @@ func main() {
|
||||
{
|
||||
Name: "test",
|
||||
Params: []Param{
|
||||
{Name: "a", Type: "int", Comment: "test"},
|
||||
{Name: "b", Type: "string", Comment: "test"},
|
||||
{Name: "a", Type: "int", Comment: "test param 1"},
|
||||
{Name: "b", Type: "string", Comment: "test param 2"},
|
||||
},
|
||||
Returns: []Return{
|
||||
{Type: "int", Comment: "test"},
|
||||
{Type: "string", Comment: "test"},
|
||||
{Type: "int", Comment: "test return int"},
|
||||
{Type: "string", Comment: "test return string"},
|
||||
},
|
||||
Comment: "test",
|
||||
Comment: "test method",
|
||||
},
|
||||
{
|
||||
Name: "test2",
|
||||
Params: []Param{
|
||||
{Name: "a", Type: "int", Comment: "test param 1"},
|
||||
{Name: "b", Type: "string", Comment: "test param 2"},
|
||||
},
|
||||
Returns: []Return{
|
||||
{Type: "int", Comment: "test return int"},
|
||||
{Type: "string", Comment: "test return string"},
|
||||
},
|
||||
Comment: "test method",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ltemplate, err := template.New("class").Parse(templatestr)
|
||||
ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr)
|
||||
if err != nil {
|
||||
Error.Printf("Error parsing template: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("%#v", ltemplate)
|
||||
ltemplate.Execute(os.Stdout, test)
|
||||
|
||||
outfile, err := test.GetOutFile()
|
||||
if err != nil {
|
||||
Error.Printf("Error creating output file: %v", err)
|
||||
return
|
||||
}
|
||||
ltemplate.Execute(outfile, test)
|
||||
|
||||
for _, file := range files {
|
||||
fmt.Println(file)
|
||||
|
||||
Reference in New Issue
Block a user