-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
45 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,18 @@ | ||
package plush | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
|
||
"github.com/gobuffalo/tags" | ||
"github.com/gobuffalo/tags/form" | ||
"github.com/gobuffalo/tags/form/bootstrap" | ||
"github.com/gobuffalo/helpers/forms" | ||
"github.com/gobuffalo/helpers/forms/bootstrap" | ||
) | ||
|
||
// FormHelper implements a Plush helper around the | ||
// form.New function in the github.com/gobuffalo/tags/form package | ||
func FormHelper(opts tags.Options, help HelperContext) (template.HTML, error) { | ||
return helper(opts, help, func(opts tags.Options) helperable { | ||
return form.New(opts) | ||
}) | ||
} | ||
|
||
// FormForHelper implements a Plush helper around the | ||
// form.NewFormFor function in the github.com/gobuffalo/tags/form package | ||
func FormForHelper(model interface{}, opts tags.Options, help HelperContext) (template.HTML, error) { | ||
return helper(opts, help, func(opts tags.Options) helperable { | ||
return form.NewFormFor(model, opts) | ||
}) | ||
} | ||
|
||
// BootstrapFormHelper implements a Plush helper around the | ||
// bootstrap.New function in the github.com/gobuffalo/tags/form/bootstrap package | ||
func BootstrapFormHelper(opts tags.Options, help HelperContext) (template.HTML, error) { | ||
return helper(opts, help, func(opts tags.Options) helperable { | ||
return bootstrap.New(opts) | ||
}) | ||
} | ||
// FormHelper is deprecated use github.com/gobuffalo/helpers/forms#Form instead. | ||
var FormHelper = forms.Form | ||
|
||
// BootstrapFormForHelper implements a Plush helper around the | ||
// bootstrap.NewFormFor function in the github.com/gobuffalo/tags/form/bootstrap package | ||
func BootstrapFormForHelper(model interface{}, opts tags.Options, help HelperContext) (template.HTML, error) { | ||
return helper(opts, help, func(opts tags.Options) helperable { | ||
return bootstrap.NewFormFor(model, opts) | ||
}) | ||
} | ||
// FormForHelper is deprecated use github.com/gobuffalo/helpers/forms#FormFor instead. | ||
var FormForHelper = forms.FormFor | ||
|
||
type helperable interface { | ||
SetAuthenticityToken(string) | ||
Append(...tags.Body) | ||
HTMLer | ||
} | ||
// BootstrapFormHelper is deprecated use github.com/gobuffalo/helpers/forms/bootstrap#Form instead. | ||
var BootstrapFormHelper = bootstrap.Form | ||
|
||
func helper(opts tags.Options, help HelperContext, fn func(opts tags.Options) helperable) (template.HTML, error) { | ||
hn := "f" | ||
if n, ok := opts["var"]; ok { | ||
hn = n.(string) | ||
delete(opts, "var") | ||
} | ||
if opts["errors"] == nil && help.Context.Value("errors") != nil { | ||
opts["errors"] = help.Context.Value("errors") | ||
} | ||
form := fn(opts) | ||
if help.Value("authenticity_token") != nil && opts["method"] != "GET" { | ||
form.SetAuthenticityToken(fmt.Sprint(help.Value("authenticity_token"))) | ||
} | ||
help.Context.Set(hn, form) | ||
s, err := help.Block() | ||
if err != nil { | ||
return "", err | ||
} | ||
form.Append(s) | ||
return form.HTML(), nil | ||
} | ||
// BootstrapFormForHelper is deprecated use github.com/gobuffalo/helpers/forms/bootstrap#FormFor instead. | ||
var BootstrapFormForHelper = bootstrap.FormFor |
Oops, something went wrong.