github.com/bketelsen/buffalo@v0.9.5/generators/newapp/soda.go (about) 1 package newapp 2 3 import ( 4 "github.com/gobuffalo/makr" 5 sg "github.com/markbates/pop/soda/cmd/generate" 6 ) 7 8 func newSodaGenerator() *makr.Generator { 9 g := makr.New() 10 11 should := func(data makr.Data) bool { 12 if _, ok := data["withPop"]; ok { 13 return ok 14 } 15 return false 16 } 17 18 f := makr.NewFile("models/models.go", nModels) 19 f.Should = should 20 g.Add(f) 21 22 f = makr.NewFile("models/models_test.go", nModelsTest) 23 f.Should = should 24 g.Add(f) 25 26 f = makr.NewFile("grifts/db.go", nSeedGrift) 27 f.Should = should 28 g.Add(f) 29 30 c := makr.NewCommand(makr.GoGet("github.com/markbates/pop/...")) 31 c.Should = should 32 g.Add(c) 33 34 g.Add(&makr.Func{ 35 Should: should, 36 Runner: func(rootPath string, data makr.Data) error { 37 data["dialect"] = data["dbType"] 38 return sg.GenerateConfig("./database.yml", data) 39 }, 40 }) 41 42 return g 43 } 44 45 const nModels = `package models 46 47 import ( 48 "log" 49 50 "github.com/gobuffalo/envy" 51 "github.com/markbates/pop" 52 ) 53 54 // DB is a connection to your database to be used 55 // throughout your application. 56 var DB *pop.Connection 57 58 func init() { 59 var err error 60 env := envy.Get("GO_ENV", "development") 61 DB, err = pop.Connect(env) 62 if err != nil { 63 log.Fatal(err) 64 } 65 pop.Debug = env == "development" 66 } 67 ` 68 69 const nModelsTest = `package models_test 70 71 import ( 72 "testing" 73 74 "github.com/gobuffalo/suite" 75 ) 76 77 type ModelSuite struct { 78 *suite.Model 79 } 80 81 func Test_ModelSuite(t *testing.T) { 82 as := &ModelSuite{suite.NewModel()} 83 suite.Run(t, as) 84 }` 85 86 const nSeedGrift = `package grifts 87 88 import ( 89 "github.com/markbates/grift/grift" 90 ) 91 92 var _ = grift.Namespace("db", func() { 93 94 grift.Desc("seed", "Seeds a database") 95 grift.Add("seed", func(c *grift.Context) error { 96 // Add DB seeding stuff here 97 return nil 98 }) 99 100 })`