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

Commit

Permalink
Assorted fixes and things (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Jul 16, 2019
1 parent 5ee03ca commit e2a1d7a
Show file tree
Hide file tree
Showing 62 changed files with 962 additions and 448 deletions.
14 changes: 10 additions & 4 deletions buffalo/cmd/destroy/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ func removeMailer(name string) {
if YesToAll || confirm("Want to remove mailer? (y/N)") {
mailerFileName := flect.Singularize(flect.Underscore(name))

os.Remove(filepath.Join("mailers", fmt.Sprintf("%v.go", mailerFileName)))
os.Remove(filepath.Join("templates/mail", fmt.Sprintf("%v.html", mailerFileName)))
files := []string{
filepath.Join("mailers", fmt.Sprintf("%v.go", mailerFileName)),
filepath.Join("templates/mail", fmt.Sprintf("%v.html", mailerFileName)),
filepath.Join("templates/mail", fmt.Sprintf("%v.plush.html", mailerFileName)),
}

for _, f := range files {
os.Remove(f)
logrus.Infof("- Deleted %v", f)
}

logrus.Infof("- Deleted %v", fmt.Sprintf("mailers/%v.go", mailerFileName))
logrus.Infof("- Deleted %v", fmt.Sprintf("templates/mail/%v.html", mailerFileName))
}
}
20 changes: 13 additions & 7 deletions buffalo/cmd/filetests/destroy_mailer_all.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[{
"path": "mailers/ouch.go",
"absent": true
},
{
"path": "templates/mail/ouch.html",
"absent": true
}]
"path": "mailers/ouch.go",
"absent": true
},
{
"path": "templates/mail/ouch.html",
"absent": true
},
{
"path": "templates/mail/ouch.plush.html",
"absent": true
}

]
43 changes: 22 additions & 21 deletions buffalo/cmd/filetests/generate_action_all.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
[{
"path": "actions/comments.go",
"contains": [
"func CommentsShow(c buffalo.Context) error {",
"func CommentsEdit(c buffalo.Context) error {",
"comments/edit.html",
"comments/show.html"
]
},
{
"path": "actions/app.go",
"contains": [
"app.GET(\"/comments/show\", CommentsShow)",
"app.GET(\"/comments/edit\", CommentsEdit)"
]
},
{
"path": "templates/comments/show.html",
"contains": [
"<h1>Comments#Show</h1>"
]
}]
"path": "actions/comments.go",
"contains": [
"func CommentsShow(c buffalo.Context) error {",
"func CommentsEdit(c buffalo.Context) error {",
"comments/edit.html",
"comments/show.html"
]
},
{
"path": "actions/app.go",
"contains": [
"app.GET(\"/comments/show\", CommentsShow)",
"app.GET(\"/comments/edit\", CommentsEdit)"
]
},
{
"path": "templates/comments/show.plush.html",
"contains": [
"<h1>Comments#Show</h1>"
]
}
]
27 changes: 15 additions & 12 deletions buffalo/cmd/filetests/generate_action_skip_template.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[
{
"path": "actions/users.go",
"contains": [
"func UsersCreate(c buffalo.Context) error {"
]
},
{
"path": "templates/users/create.html",
"absent": true
}
]
[{
"path": "actions/users.go",
"contains": [
"func UsersCreate(c buffalo.Context) error {"
]
},
{
"path": "templates/users/create.html",
"absent": true
},
{
"path": "templates/users/create.plush.html",
"absent": true
}
]
35 changes: 19 additions & 16 deletions buffalo/cmd/filetests/generate_action_with_method.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[
{
"path": "actions/users.go",
"contains": [
"func UsersCreate(c buffalo.Context) error {"
]
},
{
"path": "templates/users/update.html",
"absent": true
},
{
"path": "actions/app.go",
"contains": ["app.POST(\"/users/update\", UsersUpdate)"]
}
]
[{
"path": "actions/users.go",
"contains": [
"func UsersCreate(c buffalo.Context) error {"
]
},
{
"path": "templates/users/update.html",
"absent": true
},
{
"path": "templates/users/update.plush.html",
"absent": true
},
{
"path": "actions/app.go",
"contains": ["app.POST(\"/users/update\", UsersUpdate)"]
}
]
8 changes: 4 additions & 4 deletions buffalo/cmd/filetests/generate_mailer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
]
},
{
"path": "templates/mail/layout.html",
"path": "templates/mail/layout.plush.html",
"contains": [
"<h1>templates/mailers/layout.html</h1>"
"<h1>templates/mailers/layout.plush.html</h1>"
]
},
{
Expand All @@ -21,10 +21,10 @@
]
},
{
"path": "templates/mail/welcome_email.html",
"path": "templates/mail/welcome_email.plush.html",
"contains": [
"<h2>Welcome Email</h2>",
"<h3>../templates/mail/welcome_email.html</h3>"
"<h3>../templates/mail/welcome_email.plush.html</h3>"
]
}
]
6 changes: 3 additions & 3 deletions buffalo/cmd/filetests/generate_resource_nested_web.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
]
},
{
"path": "templates/admin/planes/_form.html",
"path": "templates/admin/planes/_form.plush.html",
"contains": [
"<button class=\"btn btn-success\" role=\"submit\">Save</button>"
]
},
{
"path": "templates/admin/planes/index.html",
"path": "templates/admin/planes/index.plush.html",
"contains": [
"newAdminPlanesPath()"
]
},
{
"path": "templates/admin/planes/show.html",
"path": "templates/admin/planes/show.plush.html",
"contains": [
"editAdminPlanePath({ admin_plane_id: plane.ID })"
]
Expand Down
1 change: 1 addition & 0 deletions buffalo/cmd/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var checks = []Check{
fixDocker,
encodeApp,
Plugins,
Plush,
}

func encodeApp(r *Runner) error {
Expand Down
50 changes: 50 additions & 0 deletions buffalo/cmd/fix/plush.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fix

import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
)

// Plush will update foo.html templates to foo.plush.html templates
func Plush(r *Runner) error {
fmt.Println("~~~ Adding .plush extension to .html files ~~~")
return filepath.Walk(r.App.Root, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}

dir := filepath.Dir(p)
base := filepath.Base(p)
sep := strings.Split(base, ".")

if filepath.Ext(p) != ".html" {
return nil
}

if len(sep) != 2 {
return nil
}

pn := filepath.Join(dir, sep[0]+".plush."+sep[1])

fn, err := os.Create(pn)
if err != nil {
return err
}
defer fn.Close()

fo, err := os.Open(p)
if err != nil {
return err
}
defer fo.Close()
_, err = io.Copy(fn, fo)

defer os.Remove(p)

return err
})
}
8 changes: 3 additions & 5 deletions genny/actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ func Test_New(t *testing.T) {

box := packr.New("genny/actions/Test_New", "../actions/_fixtures/outputs/clean")

files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/index.html"}
files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/index.plush.html"}

for _, s := range files {
x, err := box.FindString(s)
r.NoError(err)
f, err := res.Find(strings.TrimSuffix(s, ".tmpl"))
r.NoError(err)
fmt.Println(x)
fmt.Println(f.String())
r.True(compare(x, f.String()))
}
}
Expand All @@ -87,7 +85,7 @@ func Test_New_Multi(t *testing.T) {

box := packr.New("genny/actions/Test_New_Multi", "../actions/_fixtures/outputs/multi")

files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/show.html", "templates/user/edit.html"}
files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/show.plush.html", "templates/user/edit.plush.html"}

for _, s := range files {
x, err := box.FindString(s)
Expand Down Expand Up @@ -126,7 +124,7 @@ func Test_New_Multi_Existing(t *testing.T) {

box := packr.New("genny/actions/Test_New_Multi_Existing", "../actions/_fixtures/outputs/existing")

files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/show.html", "templates/user/edit.html"}
files := []string{"actions/user.go.tmpl", "actions/app.go.tmpl", "actions/user_test.go.tmpl", "templates/user/show.plush.html", "templates/user/edit.plush.html"}

for _, s := range files {
x, err := box.FindString(s)
Expand Down
4 changes: 2 additions & 2 deletions genny/actions/build_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

func buildTemplates(pres *presenter) genny.RunFn {
return func(r *genny.Runner) error {
f, err := box.FindString("view.html.tmpl")
f, err := box.FindString("view.plush.html.tmpl")
if err != nil {
return err
}
for _, a := range pres.Actions {
pres.Data["action"] = a
fn := fmt.Sprintf("templates/%s/%s.html.tmpl", pres.Name.Folder(), a.File())
fn := fmt.Sprintf("templates/%s/%s.plush.html.tmpl", pres.Name.Folder(), a.File())
xf := genny.NewFileS(fn, f)
xf, err = transform(pres, xf)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions genny/build/_fixtures/coke/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2847,9 +2847,9 @@ lodash.debounce@^4.0.8:
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash.mergewith@^4.6.0:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927"
integrity sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55"
integrity sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==

lodash.tail@^4.1.1:
version "4.1.1"
Expand Down
3 changes: 0 additions & 3 deletions genny/mail/init/templates/templates/mail/layout.html.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>templates/mailers/layout.plush.html</h1>

<%= yield %>
4 changes: 2 additions & 2 deletions genny/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New(opts *Options) (*genny.Group, error) {

fn := opts.Name.File().String()
g.File(genny.NewFileS("mailers/"+fn+".go.tmpl", mailerTmpl))
g.File(genny.NewFileS("templates/mail/"+fn+".html.tmpl", mailTmpl))
g.File(genny.NewFileS("templates/mail/"+fn+".plush.html.tmpl", mailTmpl))
gg.Add(g)

return gg, nil
Expand Down Expand Up @@ -83,4 +83,4 @@ func Send{{.opts.Name.Resource}}() error {

const mailTmpl = `<h2>{{.opts.Name.Titleize}}</h2>
<h3>../templates/mail/{{.opts.Name.File}}.html</h3>`
<h3>../templates/mail/{{.opts.Name.File}}.plush.html</h3>`
10 changes: 5 additions & 5 deletions genny/mail/mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func Test_New_NoMailers(t *testing.T) {
r.Equal("mailers/mailers.go", f.Name())

f = res.Files[2]
r.Equal("templates/mail/foo.html", f.Name())
r.Equal("templates/mail/foo.plush.html", f.Name())
body = f.String()
r.Contains(body, `<h3>../templates/mail/foo.html</h3>`)
r.Contains(body, `<h3>../templates/mail/foo.plush.html</h3>`)

f = res.Files[3]
r.Equal("templates/mail/layout.html", f.Name())
r.Equal("templates/mail/layout.plush.html", f.Name())
}

func Test_New_WithMailers(t *testing.T) {
Expand All @@ -60,7 +60,7 @@ func Test_New_WithMailers(t *testing.T) {
r.Contains(body, `err := m.AddBody(r.HTML("foo.html"), render.Data{})`)

f = res.Files[2]
r.Equal("templates/mail/foo.html", f.Name())
r.Equal("templates/mail/foo.plush.html", f.Name())
body = f.String()
r.Contains(body, `<h3>../templates/mail/foo.html</h3>`)
r.Contains(body, `<h3>../templates/mail/foo.plush.html</h3>`)
}
4 changes: 2 additions & 2 deletions genny/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Test_New(t *testing.T) {
nn := name.New(tt.Options.Name).Pluralize().String()
actions := []string{"_form", "index", "show", "new", "edit"}
for _, s := range actions {
p := path.Join("templates", nn, s+".html")
p := path.Join("templates", nn, s+".plush.html")
_, err = res.Find(p)
r.NoError(err)
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func Test_New_UseModel(t *testing.T) {
r.Len(res.Files, 9)

for _, s := range []string{"_form", "edit", "index", "new", "show"} {
p := path.Join("templates", "widgets", s+".html")
p := path.Join("templates", "widgets", s+".plush.html")
_, err = res.Find(p)
r.NoError(err)
}
Expand Down
Loading

0 comments on commit e2a1d7a

Please sign in to comment.