github.com/friesencr/pop/v6@v6.1.6/genny/config/config.go (about) 1 package config 2 3 import ( 4 "embed" 5 "fmt" 6 "path/filepath" 7 8 "github.com/gobuffalo/genny/v2" 9 "github.com/gobuffalo/genny/v2/gogen" 10 ) 11 12 //go:embed templates/* 13 var templates embed.FS 14 15 // New generator to create a database.yml file 16 func New(opts *Options) (*genny.Generator, error) { 17 g := genny.New() 18 if err := opts.Validate(); err != nil { 19 return g, err 20 } 21 22 f, err := templates.Open("templates/" + opts.Dialect + ".yml.tmpl") 23 if err != nil { 24 return g, fmt.Errorf("unable to find database.yml template for dialect %s", opts.Dialect) 25 } 26 27 name := filepath.Join(opts.Root, opts.FileName+".tmpl") 28 gf := genny.NewFile(name, f) 29 g.File(gf) 30 31 data := map[string]interface{}{ 32 "opts": opts, 33 } 34 35 t := gogen.TemplateTransformer(data, gogen.TemplateHelpers) 36 g.Transformer(t) 37 g.Transformer(genny.Dot()) 38 39 return g, nil 40 }