github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/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/seed.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 c = makr.NewCommand(makr.GoInstall("github.com/markbates/pop/soda")) 35 c.Should = should 36 g.Add(c) 37 38 g.Add(&makr.Func{ 39 Should: should, 40 Runner: func(rootPath string, data makr.Data) error { 41 data["dialect"] = data["dbType"] 42 return sg.GenerateConfig("./database.yml", data) 43 }, 44 }) 45 46 return g 47 } 48 49 const nModels = `package models 50 51 import ( 52 "log" 53 54 "github.com/gobuffalo/envy" 55 "github.com/markbates/pop" 56 ) 57 58 // DB is a connection to your database to be used 59 // throughout your application. 60 var DB *pop.Connection 61 62 func init() { 63 var err error 64 env := envy.Get("GO_ENV", "development") 65 DB, err = pop.Connect(env) 66 if err != nil { 67 log.Fatal(err) 68 } 69 pop.Debug = env == "development" 70 } 71 ` 72 73 const nModelsTest = `package models_test 74 75 import ( 76 "testing" 77 78 "github.com/gobuffalo/suite" 79 ) 80 81 type ModelSuite struct { 82 *suite.Model 83 } 84 85 func Test_ModelSuite(t *testing.T) { 86 as := &ModelSuite{suite.NewModel()} 87 suite.Run(t, as) 88 }` 89 90 const nSeedGrift = `package grifts 91 92 import ( 93 "github.com/markbates/grift/grift" 94 ) 95 96 var _ = grift.Add("db:seed", func(c *grift.Context) error { 97 // Add DB seeding stuff here 98 return nil 99 })`