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

Commit

Permalink
Merge pull request #885 from gobuffalo/migrate-meta-name
Browse files Browse the repository at this point in the history
moved the meta.Name type to the github.com/markbates/inflect package instead
  • Loading branch information
markbates authored Jan 30, 2018
2 parents 44bde5b + 9db7e65 commit a447616
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 349 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN go get -v -u github.com/golang/lint/golint
RUN go get -v -u github.com/markbates/filetest
RUN go get -v -u github.com/gobuffalo/makr
RUN go get -v -u github.com/markbates/grift
RUN go get -v -u github.com/markbates/inflect
RUN go get -v -u github.com/markbates/refresh
RUN go get -v -u github.com/gobuffalo/tags

Expand All @@ -17,7 +18,7 @@ RUN mkdir -p $BP
WORKDIR $BP
ADD . .

RUN go get -v -t $(go list ./... | grep -v /vendor/)
RUN go get -v -t ./...

RUN go install -v ./buffalo

Expand Down
3 changes: 2 additions & 1 deletion buffalo/cmd/generate/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gobuffalo/buffalo/generators/mail"
"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/makr"
"github.com/markbates/inflect"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand All @@ -19,7 +20,7 @@ var MailCmd = &cobra.Command{
return errors.New("you must supply a name for your mailer")
}
mailer.App = meta.New(".")
mailer.Name = meta.Name(args[0])
mailer.Name = inflect.Name(args[0])
data := makr.Data{}
return mailer.Run(".", data)

Expand Down
4 changes: 2 additions & 2 deletions buffalo/cmd/generate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package generate
import (
"strings"

"github.com/markbates/inflect"
"github.com/pkg/errors"

"github.com/gobuffalo/buffalo/generators/resource"
"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/makr"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -35,7 +35,7 @@ var ResourceCmd = &cobra.Command{
o.SkipMigration = resourceOptions.SkipMigration
if resourceOptions.ModelName != "" {
o.UseModel = true
o.Model = meta.Name(resourceOptions.ModelName)
o.Model = inflect.Name(resourceOptions.ModelName)
}

if err := o.Validate(); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/markbates/inflect"
"github.com/sirupsen/logrus"

"github.com/pkg/errors"
Expand Down Expand Up @@ -39,11 +40,11 @@ var newCmd = &cobra.Command{
return errors.New("you must enter a name for your new application")
}

app.Name = meta.Name(args[0])
app.Name = inflect.Name(args[0])
app.Version = Version

if app.Name == "." {
app.Name = meta.Name(filepath.Base(app.Root))
app.Name = inflect.Name(filepath.Base(app.Root))
} else {
app.Root = filepath.Join(app.Root, app.Name.File())
}
Expand Down
16 changes: 8 additions & 8 deletions generators/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"path/filepath"
"strings"

"github.com/markbates/inflect"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/gobuffalo/buffalo/generators"
"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/makr"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func (act Generator) buildTestsTemplate(filePath string) string {
return testsTemplate
}

func (act Generator) addTemplateFiles(actionsToAdd []meta.Name, data makr.Data) error {
func (act Generator) addTemplateFiles(actionsToAdd []inflect.Name, data makr.Data) error {
for _, action := range actionsToAdd {
vg := makr.New()
viewPath := filepath.Join("templates", fmt.Sprintf("%s", act.Name.File()), fmt.Sprintf("%s.html", action.File()))
Expand All @@ -90,13 +90,13 @@ func (act Generator) addTemplateFiles(actionsToAdd []meta.Name, data makr.Data)
return nil
}

func (act Generator) findActionsToAdd(path string) []meta.Name {
func (act Generator) findActionsToAdd(path string) []inflect.Name {
fileContents, err := ioutil.ReadFile(path)
if err != nil {
fileContents = []byte("")
}

actionsToAdd := []meta.Name{}
actionsToAdd := []inflect.Name{}

for _, action := range act.Actions {
funcSignature := fmt.Sprintf("func %s%s(c buffalo.Context) error", act.Name.Camel(), action.Camel())
Expand All @@ -111,13 +111,13 @@ func (act Generator) findActionsToAdd(path string) []meta.Name {
return actionsToAdd
}

func (act Generator) findHandlersToAdd(path string) []meta.Name {
func (act Generator) findHandlersToAdd(path string) []inflect.Name {
fileContents, err := ioutil.ReadFile(path)
if err != nil {
fileContents = []byte("")
}

handlersToAdd := []meta.Name{}
handlersToAdd := []inflect.Name{}

for _, action := range act.Actions {
funcSignature := fmt.Sprintf("app.GET(\"/%s/%s\", %s%s)", act.Name.URL(), action.URL(), act.Name.Camel(), action.Camel())
Expand All @@ -132,13 +132,13 @@ func (act Generator) findHandlersToAdd(path string) []meta.Name {
return handlersToAdd
}

func (act Generator) findTestsToAdd(path string) []meta.Name {
func (act Generator) findTestsToAdd(path string) []inflect.Name {
fileContents, err := ioutil.ReadFile(path)
if err != nil {
fileContents = []byte("")
}

actionsToAdd := []meta.Name{}
actionsToAdd := []inflect.Name{}

for _, action := range act.Actions {
funcSignature := fmt.Sprintf("func (as *ActionSuite) Test_%v_%v() {", act.Name.Camel(), action.Camel())
Expand Down
19 changes: 10 additions & 9 deletions generators/action/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@ import (
"errors"

"github.com/gobuffalo/buffalo/meta"
"github.com/markbates/inflect"
)

// Generator for generating new actions
type Generator struct {
App meta.App `json:"app"`
Name meta.Name `json:"name"`
Method string `json:"method"`
SkipTemplate bool `json:"skip_template"`
Actions []meta.Name `json:"actions"`
Args []string `json:"args"`
App meta.App `json:"app"`
Name inflect.Name `json:"name"`
Method string `json:"method"`
SkipTemplate bool `json:"skip_template"`
Actions []inflect.Name `json:"actions"`
Args []string `json:"args"`
}

// New returns a well formed set of Options
// for generating new actions
func New(args ...string) (Generator, error) {
o := Generator{
App: meta.New("."),
Actions: []meta.Name{},
Actions: []inflect.Name{},
Args: args,
Method: "GET",
}
if len(args) < 2 {
return o, errors.New("you need to provide at least an action name and handler name")
}
o.Name = meta.Name(args[0])
o.Name = inflect.Name(args[0])
for _, a := range args[1:] {
o.Actions = append(o.Actions, meta.Name(a))
o.Actions = append(o.Actions, inflect.Name(a))
}

return o, nil
Expand Down
19 changes: 10 additions & 9 deletions generators/grift/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import (
"strings"

"github.com/gobuffalo/buffalo/meta"
"github.com/markbates/inflect"
"github.com/pkg/errors"
)

// Generator for creating a new grift task
type Generator struct {
App meta.App `json:"app"`
Name meta.Name `json:"name"`
Parts []meta.Name `json:"parts"`
Args []string `json:"args"`
Namespaced bool `json:"namespaced"`
App meta.App `json:"app"`
Name inflect.Name `json:"name"`
Parts []inflect.Name `json:"parts"`
Args []string `json:"args"`
Namespaced bool `json:"namespaced"`
}

// Last checks if the name is the last of the parts
func (g Generator) Last(n meta.Name) bool {
func (g Generator) Last(n inflect.Name) bool {
return g.Parts[len(g.Parts)-1] == n
}

Expand All @@ -26,15 +27,15 @@ func New(args ...string) (Generator, error) {
g := Generator{
App: meta.New("."),
Args: args,
Parts: []meta.Name{},
Parts: []inflect.Name{},
}
if len(args) > 0 {
g.Namespaced = strings.Contains(args[0], ":")

for _, n := range strings.Split(args[0], ":") {
g.Parts = append(g.Parts, meta.Name(n))
g.Parts = append(g.Parts, inflect.Name(n))
}
g.Name = meta.Name(g.Parts[len(g.Parts)-1])
g.Name = inflect.Name(g.Parts[len(g.Parts)-1])
}

return g, g.Validate()
Expand Down
7 changes: 4 additions & 3 deletions generators/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/makr"
"github.com/gobuffalo/packr"
"github.com/markbates/inflect"
"github.com/pkg/errors"
)

// Generator for creating new mailers
type Generator struct {
App meta.App `json:"app"`
Name meta.Name `json:"name"`
SkipInit bool `json:"skip_init"`
App meta.App `json:"app"`
Name inflect.Name `json:"name"`
SkipInit bool `json:"skip_init"`
}

// Run the new mailer generator. It will init the mailers directory
Expand Down
5 changes: 3 additions & 2 deletions generators/newapp/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/envy"
"github.com/markbates/inflect"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -42,10 +43,10 @@ func New(name string) (Generator, error) {
AsWeb: true,
Docker: "multi",
}
g.Name = meta.Name(name)
g.Name = inflect.Name(name)

if g.Name == "." {
g.Name = meta.Name(filepath.Base(g.Root))
g.Name = inflect.Name(filepath.Base(g.Root))
} else {
g.Root = filepath.Join(g.Root, g.Name.File())
}
Expand Down
30 changes: 15 additions & 15 deletions generators/resource/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (

// Generator for generating a new resource
type Generator struct {
App meta.App `json:"app"`
Name meta.Name `json:"name"`
Model meta.Name `json:"model"`
SkipMigration bool `json:"skip_migration"`
SkipModel bool `json:"skip_model"`
UseModel bool `json:"use_model"`
MimeType string `json:"mime_type"`
FilesPath string `json:"files_path"`
ActionsPath string `json:"actions_path"`
Props []Prop `json:"props"`
Args []string `json:"args"`
App meta.App `json:"app"`
Name inflect.Name `json:"name"`
Model inflect.Name `json:"model"`
SkipMigration bool `json:"skip_migration"`
SkipModel bool `json:"skip_model"`
UseModel bool `json:"use_model"`
MimeType string `json:"mime_type"`
FilesPath string `json:"files_path"`
ActionsPath string `json:"actions_path"`
Props []Prop `json:"props"`
Args []string `json:"args"`
}

// New constructs new options for generating a resource
Expand All @@ -34,20 +34,20 @@ func New(modelName string, args ...string) (Generator, error) {
o.App = meta.New(pwd)

if len(o.Args) > 0 {
o.Name = meta.Name(o.Args[0])
o.Model = meta.Name(o.Args[0])
o.Name = inflect.Name(o.Args[0])
o.Model = inflect.Name(o.Args[0])
}
o.Props = modelPropertiesFromArgs(o.Args)

o.FilesPath = o.Name.PluralUnder()
o.ActionsPath = o.FilesPath
if strings.Contains(string(o.Name), "/") {
parts := strings.Split(string(o.Name), "/")
o.Model = meta.Name(parts[len(parts)-1])
o.Model = inflect.Name(parts[len(parts)-1])
o.ActionsPath = inflect.Underscore(o.Name.Resource())
}
if modelName != "" {
o.Model = meta.Name(modelName)
o.Model = inflect.Name(modelName)
}
return o, o.Validate()
}
Expand Down
5 changes: 2 additions & 3 deletions generators/resource/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package resource
import (
"strings"

"github.com/gobuffalo/buffalo/meta"
"github.com/markbates/inflect"
)

// Prop of a model. Starts as name:type on the command line.
type Prop struct {
Name meta.Name
Name inflect.Name
Type string
}

Expand All @@ -26,7 +25,7 @@ func modelPropertiesFromArgs(args []string) []Prop {
for _, a := range args[1:] {
ax := strings.Split(a, ":")
p := Prop{
Name: meta.Name(inflect.ForeignKeyToAttribute(ax[0])),
Name: inflect.Name(inflect.ForeignKeyToAttribute(ax[0])),
Type: "string",
}
if len(ax) > 1 {
Expand Down
31 changes: 16 additions & 15 deletions meta/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ import (
"runtime"

"github.com/gobuffalo/envy"
"github.com/markbates/inflect"
)

// App represents meta data for a Buffalo application on disk
type App struct {
Pwd string `json:"pwd"`
Root string `json:"root"`
GoPath string `json:"go_path"`
Name Name `json:"name"`
Bin string `json:"bin"`
PackagePkg string `json:"package_path"`
ActionsPkg string `json:"actions_path"`
ModelsPkg string `json:"models_path"`
GriftsPkg string `json:"grifts_path"`
WithPop bool `json:"with_pop"`
WithDep bool `json:"with_dep"`
WithWebpack bool `json:"with_webpack"`
WithYarn bool `json:"with_yarn"`
WithDocker bool `json:"with_docker"`
WithGrifts bool `json:"with_grifts"`
Pwd string `json:"pwd"`
Root string `json:"root"`
GoPath string `json:"go_path"`
Name inflect.Name `json:"name"`
Bin string `json:"bin"`
PackagePkg string `json:"package_path"`
ActionsPkg string `json:"actions_path"`
ModelsPkg string `json:"models_path"`
GriftsPkg string `json:"grifts_path"`
WithPop bool `json:"with_pop"`
WithDep bool `json:"with_dep"`
WithWebpack bool `json:"with_webpack"`
WithYarn bool `json:"with_yarn"`
WithDocker bool `json:"with_docker"`
WithGrifts bool `json:"with_grifts"`
}

// New App based on the details found at the provided root path
Expand Down
Loading

0 comments on commit a447616

Please sign in to comment.