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

Commit

Permalink
Fixes #1987 and #2023 (#2026)
Browse files Browse the repository at this point in the history
* v0.16.13 (#2019)

* adding direct version on the docker build

* fixing plugin installation

* Fix npm's package.json permissions (#2005)

Changed created file permissions from 644 (`-w----r--`) to 0644 (`rw-r--r--`)

* Bump spf13/viper to v1.7.0 (#1999)

* bunping version

* changing version on dockerfile

* patch to fix the keywords check on new app

* removing unneeded append

* Task fixing html binder (#2016)

* binder was not wired

* packing

* adding new version number

* pulling the buffalo binary from gobinaries.com

Co-authored-by: Disconnect3d <[email protected]>
Co-authored-by: hackerman <[email protected]>

* fixing #1987 and #2023

* adding missing converstion

* removing commented code

Co-authored-by: Disconnect3d <[email protected]>
Co-authored-by: hackerman <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2020
1 parent b0f043a commit 2a6f20b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
10 changes: 10 additions & 0 deletions genny/newapp/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func Test_New(t *testing.T) {
r.NoError(err)
r.Contains(f.String(), `return c.Render(http.StatusOK, r.JSON(map[string]string{"message": "Welcome to Buffalo!"}))`)

f, err = res.Find("actions/app.go")
r.NoError(err)
r.Contains(f.String(), `i18n "github.com/gobuffalo/mw-i18n"`)
r.Contains(f.String(), `var T *i18n.Translator`)
r.Contains(f.String(), `func translations() buffalo.MiddlewareFunc {`)

f, err = res.Find("locales/all.en-us.yaml")
r.NoError(err)
r.Contains(f.String(), `translation: "Welcome to Buffalo (EN)"`)

unexpected := []string{
"Dockerfile",
"database.yml",
Expand Down
14 changes: 14 additions & 0 deletions genny/newapp/api/templates/actions/app.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
forcessl "github.com/gobuffalo/mw-forcessl"
paramlogger "github.com/gobuffalo/mw-paramlogger"
"github.com/unrolled/secure"
i18n "github.com/gobuffalo/mw-i18n"

{{ if .opts.App.WithPop }}
"{{.opts.App.ModelsPkg}}"
Expand All @@ -21,6 +22,7 @@ import (
// application is being run. Default is "development".
var ENV = envy.Get("GO_ENV", "development")
var app *buffalo.App
var T *i18n.Translator

// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
Expand Down Expand Up @@ -68,6 +70,18 @@ func App() *buffalo.App {
return app
}

// translations will load locale files, set up the translator `actions.T`,
// and will return a middleware to use to load the correct locale for each
// request.
// for more information: https://gobuffalo.io/en/docs/localization
func translations() buffalo.MiddlewareFunc {
var err error
if T, err = i18n.New(packr.New("app:locales", "../locales"), "en-US"); err != nil {
app.Stop(err)
}
return T.Middleware()
}

// forceSSL will return a middleware that will redirect an incoming request
// if it is not HTTPS. "http://example.com" => "https://example.com".
// This middleware does **not** enable SSL. for your application. To do that
Expand Down
3 changes: 3 additions & 0 deletions genny/newapp/api/templates/locales/all.en-us.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# For more information on using i18n see: https://github.com/nicksnyder/go-i18n
- id: welcome_greeting
translation: "Welcome to Buffalo (EN)"
34 changes: 34 additions & 0 deletions genny/resource/resource_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"fmt"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -220,3 +221,36 @@ func Test_New_UseModel(t *testing.T) {
r.Contains(f.String(), "users := &models.Users{}")

}

func Test_New_SkipModel(t *testing.T) {
r := require.New(t)

app := meta.New(".")
app.PackageRoot("github.com/markbates/coke")

opts := &Options{
App: app,
Name: "Widget",
SkipModel: true,
}

g, err := New(opts)
r.NoError(err)

run := runner()
run.With(g)
r.NoError(run.Run())

res := run.Results()

r.Len(res.Commands, 0)
r.Len(res.Files, 9)

f, err := res.Find("actions/widgets.go")
r.NoError(err)
actions := []string{"List", "Show", "Create", "Update", "Destroy", "New", "Edit"}
for _, action := range actions {
r.Contains(f.String(), fmt.Sprintf("func (v WidgetsResource) %v(c buffalo.Context) error {", action))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type {{.opts.Name.Resource}}Resource struct{
}

{{ range $a := .actions }}
// {{$a.String}} default implementation.
func (v {{$.opts.Name.Resource}}Resource) {{$a.String}}(c buffalo.Context) error {
return c.Render(http.StatusOK, r.String("{{$.opts.Model.Proper}}#{{$a.String}}"))
// {{$a.Pascalize}} default implementation.
func (v {{$.opts.Name.Resource}}Resource) {{$a.Pascalize}}(c buffalo.Context) error {
return c.Render(http.StatusOK, r.String("{{$.opts.Model.Proper}}#{{$a.Pascalize}}"))
}

{{end}}
Loading

0 comments on commit 2a6f20b

Please sign in to comment.