Skip to content

Commit

Permalink
fixes issues with v3 and reduces dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jan 15, 2020
1 parent 0eb7712 commit 2949e18
Show file tree
Hide file tree
Showing 31 changed files with 193 additions and 275 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ generated/
bin/*
gin-bin
.idea/
cover.out
59 changes: 6 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
TAGS ?= "sqlite"
GO_BIN ?= go

install:
packr
$(GO_BIN) install -tags ${TAGS} -v .
make tidy

tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif

deps:
$(GO_BIN) get github.com/gobuffalo/release
$(GO_BIN) get github.com/gobuffalo/packr/packr
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy

build:
packr
$(GO_BIN) build -v .
make tidy

test:
packr
$(GO_BIN) test -tags ${TAGS} ./...
make tidy

ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy

lint:
gometalinter --vendor ./... --deadline=1m --skip=internal
make tidy

update:
$(GO_BIN) get -u -tags ${TAGS}
make tidy
packr
make test
make install
make tidy

release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
go test -failfast -short -cover ./...
go mod tidy -v

release:
make tidy
release -y -f version.go
make tidy
cov:
go test -short -coverprofile cover.out ./...
go tool cover -html cover.out
go mod tidy -v
2 changes: 1 addition & 1 deletion form/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/gobuffalo/flect"
"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/v3"
)

func buildOptions(opts tags.Options, err bool) {
Expand Down
7 changes: 3 additions & 4 deletions form/bootstrap/common_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package bootstrap_test
package bootstrap

import (
"testing"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form/bootstrap"
"github.com/gobuffalo/tags/v3"
"github.com/stretchr/testify/require"
)

func Test_BootstrapFormGroupClass(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})

tcases := []struct {
options tags.Options
Expand Down
4 changes: 2 additions & 2 deletions form/bootstrap/form.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package bootstrap

import (
"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form"
"github.com/gobuffalo/tags/v3"
"github.com/gobuffalo/tags/v3/form"
)

//Form is the bootstrap version of Form
Expand Down
6 changes: 3 additions & 3 deletions form/bootstrap/form_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"strings"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form"
"github.com/gobuffalo/validate/validators"
"github.com/gobuffalo/tags/v3"
"github.com/gobuffalo/tags/v3/form"
"github.com/gobuffalo/validate/v3/validators"
)

//FormFor is the FormFor version for bootstrap
Expand Down
55 changes: 27 additions & 28 deletions form/bootstrap/form_for_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package bootstrap_test
package bootstrap

import (
"fmt"
"testing"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form/bootstrap"
"github.com/gobuffalo/validate"
"github.com/gobuffalo/tags/v3"
"github.com/gobuffalo/validate/v3"
"github.com/stretchr/testify/require"
)

func Test_InputFieldLabel(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})
l := f.InputTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label>Custom</label><input class=" form-control" id="-Name" name="Name" type="text" value="" /></div>`, l.String())
}
Expand All @@ -25,7 +24,7 @@ func Test_InputFieldLabelWithAchronym(t *testing.T) {
"GaveAnExample": "Gave An Example",
}
r := require.New(t)
f := bootstrap.NewFormFor(struct{ URL string }{}, tags.Options{})
f := NewFormFor(struct{ URL string }{}, tags.Options{})

for key, expectedLabel := range cases {
l := f.InputTag(key, tags.Options{})
Expand All @@ -35,14 +34,14 @@ func Test_InputFieldLabelWithAchronym(t *testing.T) {

func Test_InputFieldLabel_Humanized(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ LongName string }{}, tags.Options{})
f := NewFormFor(struct{ LongName string }{}, tags.Options{})
l := f.InputTag("LongName", tags.Options{})
r.Equal(`<div class="form-group"><label>Long Name</label><input class=" form-control" id="-LongName" name="LongName" type="text" value="" /></div>`, l.String())
}

func Test_InputFieldSchema(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `schema:"notName"`
}{}, tags.Options{})

Expand All @@ -52,7 +51,7 @@ func Test_InputFieldSchema(t *testing.T) {

func Test_InputFieldFormInsteadOfSchema(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `form:"notName"`
}{}, tags.Options{})

Expand All @@ -62,7 +61,7 @@ func Test_InputFieldFormInsteadOfSchema(t *testing.T) {

func Test_InputFieldFormAndSchema(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `form:"notName" schema:"name"`
}{}, tags.Options{})

Expand All @@ -72,7 +71,7 @@ func Test_InputFieldFormAndSchema(t *testing.T) {

func Test_InputFieldSchema_FieldNotPresent(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `schema:"notName"`
}{}, tags.Options{})

Expand All @@ -82,7 +81,7 @@ func Test_InputFieldSchema_FieldNotPresent(t *testing.T) {

func Test_InputFieldSchema_FieldDash(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `schema:"-"`
}{}, tags.Options{})

Expand All @@ -92,14 +91,14 @@ func Test_InputFieldSchema_FieldDash(t *testing.T) {

func Test_SelectLabel(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})
l := f.SelectTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label>Custom</label><select class=" form-control" id="-Name" name="Name"></select></div>`, l.String())
}

func Test_Select_With_String_As_BeforeTag_Opt(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})

s := `<span>Test</span>`
l := f.SelectTag("Name", tags.Options{"before_tag": s})
Expand All @@ -109,7 +108,7 @@ func Test_Select_With_String_As_BeforeTag_Opt(t *testing.T) {

func Test_Select_With_Nested_Tag_As_BeforeTag_Opt(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})

s := tags.New("span", tags.Options{"body": "Test"})
l := f.SelectTag("Name", tags.Options{"before_tag": s})
Expand All @@ -119,7 +118,7 @@ func Test_Select_With_Nested_Tag_As_BeforeTag_Opt(t *testing.T) {

func Test_Select_With_String_As_AfterTag_Opt(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})

b := `<button type="button">Button Name</button>`
l := f.SelectTag("Name", tags.Options{"after_tag": b})
Expand All @@ -129,7 +128,7 @@ func Test_Select_With_String_As_AfterTag_Opt(t *testing.T) {

func Test_Select_With_Nested_Tag_As_AfterTag_Opt(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})

b := tags.New("button", tags.Options{
"body": "Button Name",
Expand All @@ -142,20 +141,20 @@ func Test_Select_With_Nested_Tag_As_AfterTag_Opt(t *testing.T) {

func Test_RadioButton(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})
l := f.RadioButton("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label>Custom</label><label for="-Name"><input class=" form-control" id="-Name" name="Name" type="radio" value="" /> </label></div>`, l.String())
}
func Test_TextArea(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})
l := f.TextArea("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label>Custom</label><textarea class=" form-control" id="-Name" name="Name"></textarea></div>`, l.String())
}

func Test_CheckBox(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})
f := NewFormFor(struct{ Name string }{}, tags.Options{})
l := f.CheckboxTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label><input class="" id="-Name" name="Name" type="checkbox" value="true" /> Custom</label></div>`, l.String())
}
Expand All @@ -166,7 +165,7 @@ func Test_InputError(t *testing.T) {
errors := validate.NewErrors()
errors.Add("name", "Name shoud be AJ.")

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.InputTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group has-error"><label>Custom</label><input class=" form-control is-invalid" id="-Name" name="Name" type="text" value="" /><div class="invalid-feedback help-block">Name shoud be AJ.</div></div>`, l.String())
}
Expand All @@ -177,7 +176,7 @@ func Test_InputHidden(t *testing.T) {
errors := validate.NewErrors()
errors.Add("name", "Name shoud be AJ.")

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.InputTag("Name", tags.Options{"type": "hidden"})
r.Equal(`<input errors="[Name shoud be AJ.]" id="-Name" name="Name" tags-field="Name" type="hidden" value="" />`, l.String())

Expand All @@ -192,7 +191,7 @@ func Test_InputError_Map(t *testing.T) {
"name": {"Name shoud be AJ."},
}

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.InputTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group has-error"><label>Custom</label><input class=" form-control is-invalid" id="-Name" name="Name" type="text" value="" /><div class="invalid-feedback help-block">Name shoud be AJ.</div></div>`, l.String())
}
Expand All @@ -204,7 +203,7 @@ func Test_InputError_InvalidMap(t *testing.T) {
"name": "Name shoud be AJ.",
}

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.InputTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group"><label>Custom</label><input class=" form-control" id="-Name" name="Name" type="text" value="" /></div>`, l.String())
}
Expand All @@ -216,7 +215,7 @@ func Test_InputMultipleError(t *testing.T) {
errors.Add("name", "Name shoud be AJ.")
errors.Add("name", "Name shoud start with A.")

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.InputTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group has-error"><label>Custom</label><input class=" form-control is-invalid" id="-Name" name="Name" type="text" value="" /><div class="invalid-feedback help-block">Name shoud be AJ.</div><div class="invalid-feedback help-block">Name shoud start with A.</div></div>`, l.String())
}
Expand All @@ -227,7 +226,7 @@ func Test_CheckBoxError(t *testing.T) {
errors := validate.NewErrors()
errors.Add("name", "Name shoud be AJ.")

f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
f := NewFormFor(struct{ Name string }{}, tags.Options{"errors": errors})
l := f.CheckboxTag("Name", tags.Options{"label": "Custom"})
r.Equal(`<div class="form-group has-error"><label><input class=" is-invalid" id="-Name" name="Name" type="checkbox" value="true" /> Custom</label><div class="invalid-feedback help-block">Name shoud be AJ.</div></div>`, l.String())
}
Expand All @@ -252,15 +251,15 @@ func Test_FormFor_Nested_Struct(t *testing.T) {
},
}

f := bootstrap.NewFormFor(p, tags.Options{})
f := NewFormFor(p, tags.Options{})
tag := f.InputTag("Address.State", tags.Options{})

exp := `<div class="form-group"><label>Address State</label><input class=" form-control" id="person-Address.State" name="Address.State" type="text" value="MA" /></div>`
r.Equal(exp, tag.String())
}

func Test_Field_TagOnly(t *testing.T) {
f := bootstrap.NewFormFor(struct {
f := NewFormFor(struct {
Name string `schema:"-"`
}{}, tags.Options{})

Expand Down
2 changes: 1 addition & 1 deletion form/checkbox_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"html/template"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/v3"
)

//CheckboxTag builds a checkbox from the options passed
Expand Down
13 changes: 6 additions & 7 deletions form/checkbox_tag_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package form_test
package form

import (
"testing"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form"
"github.com/gobuffalo/tags/v3"
"github.com/stretchr/testify/require"
)

func Test_Form_CheckboxTag(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
f := New(tags.Options{})
ct := f.CheckboxTag(tags.Options{"name": "Chubby"})
r.Equal(`<label><input name="Chubby" type="checkbox" value="true" /></label>`, ct.String())
}

func Test_Form_CheckboxTag_WithValue(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
f := New(tags.Options{})
ct := f.CheckboxTag(tags.Options{
"value": 1,
"checked": "1",
Expand All @@ -29,7 +28,7 @@ func Test_Form_CheckboxTag_WithValue(t *testing.T) {

func Test_Form_CheckboxTag_Checked(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
f := New(tags.Options{})
ct := f.CheckboxTag(tags.Options{
"checked": true,
"value": true,
Expand All @@ -39,7 +38,7 @@ func Test_Form_CheckboxTag_Checked(t *testing.T) {

func Test_Form_CheckboxTag_WithLabel(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
f := New(tags.Options{})
ct := f.CheckboxTag(tags.Options{
"label": "check me",
"name": "Chubby",
Expand Down
Loading

0 comments on commit 2949e18

Please sign in to comment.