Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Provide a way to load custom inflection rules fixes #747 #748

Merged
merged 3 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions buffalo/cmd/build/apkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ func (b *Builder) prepAPackage() error {
if err != nil {
return errors.WithStack(err)
}

infl := filepath.Join(b.Root, "inflections.json")
if _, err := os.Stat(infl); err == nil {
logrus.Debugf("preparing %s", infl)
// there's an inflection file we need to copy it over
fa, err := os.Open(infl)
if err != nil {
return errors.WithStack(err)
}
defer fa.Close()
fb, err := os.Create(filepath.Join(b.Root, "a", "inflections.json"))
if err != nil {
return errors.WithStack(err)
}
defer fb.Close()
_, err = io.Copy(fb, fa)
if err != nil {
return errors.WithStack(err)
}
}

b.cleanups = append(b.cleanups, func() error {
return os.RemoveAll(a)
})
Expand Down
33 changes: 22 additions & 11 deletions buffalo/cmd/build/templates/a.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package a

import (
"log"
"strings"
"github.com/markbates/pop"
"log"
"strings"
"github.com/markbates/pop"
"github.com/markbates/inflect"
"github.com/gobuffalo/packr"
)

func init() {
dropDatabaseYml()
dropDatabaseYml()

box := packr.NewBox("./")
if box.Has("inflections.json") {
r := strings.NewReader(box.String("inflections.json"))
err := inflect.LoadReader(r)
if err != nil {
log.Fatal(err)
}
}
}

func dropDatabaseYml() {
if DB_CONFIG != "" {
r := strings.NewReader(DB_CONFIG)
err := pop.LoadFrom(r)
if err != nil {
log.Fatal(err)
}
}
if DB_CONFIG != "" {
r := strings.NewReader(DB_CONFIG)
err := pop.LoadFrom(r)
if err != nil {
log.Fatal(err)
}
}
}
3 changes: 3 additions & 0 deletions generators/newapp/templates/inflections.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singular": "plural"
}