/
common.go
51 lines (43 loc) · 1.18 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package repository
import (
"fmt"
"strings"
"github.com/alenn-m/rgen/generator/parser"
"github.com/alenn-m/rgen/util/config"
"github.com/jinzhu/inflection"
)
type parsedData struct {
Public bool
Actions []string
Root string
Package string
Model string
Fields string
NamedFields string
UpdateFields string
Controller string
RepoContent string
ImplContent string
}
func parseData(input *parser.Parser, conf *config.Config) parsedData {
parsedData := parsedData{
Public: input.Public,
Package: strings.ToLower(inflection.Singular(input.Name)),
Model: strings.Title(inflection.Singular(input.Name)),
Controller: strings.Title(inflection.Plural(input.Name)) + "Controller",
Root: conf.Package,
Actions: input.Actions,
}
f := []string{}
nf := []string{}
uf := []string{}
for _, item := range input.Fields {
f = append(f, item.Key)
nf = append(nf, fmt.Sprintf(":%s", item.Key))
uf = append(uf, fmt.Sprintf("%s = :%s", item.Key, item.Key))
}
parsedData.Fields = strings.Join(f, ", ")
parsedData.NamedFields = strings.Join(nf, ", ")
parsedData.UpdateFields = strings.Join(uf, ", ")
return parsedData
}