|
@@ -6,10 +6,10 @@ import (
|
|
"log"
|
|
"log"
|
|
"os"
|
|
"os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "strings"
|
|
"text/template"
|
|
"text/template"
|
|
|
|
|
|
"github.com/jinzhu/inflection"
|
|
"github.com/jinzhu/inflection"
|
|
- "gogs.carducci-dante.gov.it/karmen/core/renderer"
|
|
|
|
tpl_util "gogs.carducci-dante.gov.it/karmen/util/template"
|
|
tpl_util "gogs.carducci-dante.gov.it/karmen/util/template"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -21,6 +21,10 @@ var (
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func toUpper(str string) string {
|
|
|
|
+ return strings.Title(str)
|
|
|
|
+}
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
flag.Usage = func() {
|
|
flag.Usage = func() {
|
|
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
|
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
|
@@ -35,15 +39,15 @@ func main() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ funcMap := template.FuncMap{
|
|
|
|
+ "toUpper": toUpper,
|
|
|
|
+ }
|
|
|
|
+
|
|
model := flag.Args()[0]
|
|
model := flag.Args()[0]
|
|
|
|
|
|
for tplName, pattern := range fnPatterns {
|
|
for tplName, pattern := range fnPatterns {
|
|
name := fmt.Sprintf(pattern, model)
|
|
name := fmt.Sprintf(pattern, model)
|
|
|
|
|
|
- funcMap := template.FuncMap{
|
|
|
|
- "query": renderer.Query,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
tpl, err := tpl_util.LoadTextTemplate(filepath.Join(*tplDir, tplName+".tpl"), funcMap)
|
|
tpl, err := tpl_util.LoadTextTemplate(filepath.Join(*tplDir, tplName+".tpl"), funcMap)
|
|
if err != nil {
|
|
if err != nil {
|
|
panic(err)
|
|
panic(err)
|
|
@@ -62,9 +66,12 @@ func main() {
|
|
Models string
|
|
Models string
|
|
}
|
|
}
|
|
|
|
|
|
- data.Model = inflection.Singular(name)
|
|
|
|
- data.Models = inflection.Plural(name)
|
|
|
|
|
|
+ data.Model = inflection.Singular(model)
|
|
|
|
+ data.Models = inflection.Plural(model)
|
|
|
|
|
|
- tpl.Execute(oFn, data)
|
|
|
|
|
|
+ err = tpl.Execute(oFn, data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|