Skip to content

Commit

Permalink
Merge pull request #107 from gobuffalo/update-inflect
Browse files Browse the repository at this point in the history
Use gobuffalo/flect instead of markbates/inflect
  • Loading branch information
paganotoni authored Nov 29, 2018
2 parents 9f2f3bf + 2bee234 commit e8a80a4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: go

sudo: false
install: false

matrix:
include:
Expand Down Expand Up @@ -29,6 +30,6 @@ matrix:
env:
- GO111MODULE=on

install: make deps

script: make ci-test
script:
- go get -v -t ./...
- go test -v -timeout=5s -race ./...
4 changes: 2 additions & 2 deletions form/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"strings"

"github.com/gobuffalo/flect"
"github.com/gobuffalo/tags"
"github.com/markbates/inflect"
)

func buildOptions(opts tags.Options, err bool) {
Expand Down Expand Up @@ -43,7 +43,7 @@ func divWrapper(opts tags.Options, fn func(opts tags.Options) tags.Body) *tags.T
if opts["label"] == nil && opts["tags-field"] != nil {
if tf, ok := opts["tags-field"].(string); ok {
tf = strings.Join(strings.Split(tf, "."), " ")
opts["label"] = inflect.Titleize(tf)
opts["label"] = flect.Titleize(tf)
}
}

Expand Down
2 changes: 1 addition & 1 deletion form/bootstrap/form_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_InputFieldLabelWithAchronym(t *testing.T) {
"URL": "URL",
"MyURL": "My URL",
"SimpleURIAdded": "Simple URI Added",
"GaveAThing": "Gave A Thing",
"GaveAnExample": "Gave An Example",
}
r := require.New(t)
f := bootstrap.NewFormFor(struct{ URL string }{}, tags.Options{})
Expand Down
30 changes: 15 additions & 15 deletions form/form_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"strings"
"sync"

"github.com/gobuffalo/flect"
"github.com/gobuffalo/tags"
"github.com/gobuffalo/uuid"
"github.com/gobuffalo/validate"
"github.com/markbates/inflect"
)

var arrayFieldRegExp = regexp.MustCompile("^([A-Za-z0-9]+)\\[(\\d+)\\]$")

//FormFor is a form made for a struct
// FormFor is a form made for a struct
type FormFor struct {
*Form
Model interface{}
Expand All @@ -27,14 +27,14 @@ type FormFor struct {
Errors *validate.Errors
}

//NewFormFor creates a new Formfor with passed options, it also creates the id of the form from the struct name and adds errors if present.
// NewFormFor creates a new Formfor with passed options, it also creates the id of the form from the struct name and adds errors if present.
func NewFormFor(model interface{}, opts tags.Options) *FormFor {
rv := reflect.ValueOf(model)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
name := rv.Type().Name()
dashedName := inflect.Dasherize(name)
dashedName := flect.Dasherize(name)

if opts["id"] == nil {
opts["id"] = fmt.Sprintf("%s-form", dashedName)
Expand Down Expand Up @@ -72,33 +72,33 @@ func loadErrors(opts tags.Options) *validate.Errors {
return errors
}

//CheckboxTag creates a checkbox for a field on the form Struct
// CheckboxTag creates a checkbox for a field on the form Struct
func (f FormFor) CheckboxTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
return f.Form.CheckboxTag(opts)
}

//InputTag creates an input for a field on the form Struct
// InputTag creates an input for a field on the form Struct
func (f FormFor) InputTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
f.addFormatTag(field, opts)
return f.Form.InputTag(opts)
}

//HiddenTag adds a wrappter for input type hidden on the form
// HiddenTag adds a wrappter for input type hidden on the form
func (f FormFor) HiddenTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
return f.Form.HiddenTag(opts)
}

//FileTag creates a input[type=file] for a field name passed
// FileTag creates a input[type=file] for a field name passed
func (f FormFor) FileTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
f.addFormatTag(field, opts)
return f.Form.FileTag(opts)
}

//DateTimeTag creates a input[type=datetime-local] for a field name passed
// DateTimeTag creates a input[type=datetime-local] for a field name passed
func (f FormFor) DateTimeTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
f.addFormatTag(field, opts)
Expand Down Expand Up @@ -128,35 +128,35 @@ func (f FormFor) addFormatTag(field string, opts tags.Options) {
}
}

//RadioButton creates a radio button for a struct field
// RadioButton creates a radio button for a struct field
func (f FormFor) RadioButton(field string, opts tags.Options) *tags.Tag {
return f.RadioButtonTag(field, opts)
}

//RadioButtonTag creates a radio button for a struct field
// RadioButtonTag creates a radio button for a struct field
func (f FormFor) RadioButtonTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
return f.Form.RadioButtonTag(opts)
}

//SelectTag creates a select tag for a specified struct field and loads options from the options opject
// SelectTag creates a select tag for a specified struct field and loads options from the options opject
func (f FormFor) SelectTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
return f.Form.SelectTag(opts)
}

//TextArea creates text area for the specified struct field
// TextArea creates text area for the specified struct field
func (f FormFor) TextArea(field string, opts tags.Options) *tags.Tag {
return f.TextAreaTag(field, opts)
}

//TextAreaTag creates text area for the specified struct field
// TextAreaTag creates text area for the specified struct field
func (f FormFor) TextAreaTag(field string, opts tags.Options) *tags.Tag {
f.buildOptions(field, opts)
return f.Form.TextArea(opts)
}

//SubmitTag adds a submit button to the form
// SubmitTag adds a submit button to the form
func (f FormFor) SubmitTag(value string, opts tags.Options) *tags.Tag {
return f.Form.SubmitTag(value, opts)
}
Expand Down
14 changes: 13 additions & 1 deletion shoulders.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Thank you to the following **GIANTS**:

* [github.com/fatih/structs](https://godoc.org/github.com/fatih/structs)

* [github.com/gobuffalo/tags](https://godoc.org/github.com/gobuffalo/tags)
* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)

* [github.com/gobuffalo/flect](https://godoc.org/github.com/gobuffalo/flect)

* [github.com/gobuffalo/uuid](https://godoc.org/github.com/gobuffalo/uuid)

* [github.com/gobuffalo/validate](https://godoc.org/github.com/gobuffalo/validate)

* [github.com/joho/godotenv](https://godoc.org/github.com/joho/godotenv)

* [github.com/kr/pretty](https://godoc.org/github.com/kr/pretty)

* [github.com/kr/text](https://godoc.org/github.com/kr/text)

* [github.com/pkg/errors](https://godoc.org/github.com/pkg/errors)

0 comments on commit e8a80a4

Please sign in to comment.