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

Convert Buffalo to use Plush by default #267

Merged
merged 11 commits into from
Mar 3, 2017
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Buffalo would not be possible if not for all of the great projects it depends on

### Templating

[github.com/gobuffalo/velvet](https://github.com/gobuffalo/velvet) - This templating package was chosen over the standard Go `html/template` package for a variety of reasons. The biggest of which is that it is significantly more flexible and easy to work with. It also has the added factor of being familiar to those who have worked with "Handlebars" or "Mustache" templates before.
[github.com/gobuffalo/plush](https://github.com/gobuffalo/plush) - This templating package was chosen over the standard Go `html/template` package for a variety of reasons. The biggest of which is that it is significantly more flexible and easy to work with.

### Routing

Expand Down
16 changes: 8 additions & 8 deletions buffalo/cmd/app_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/buffalo/render/resolvers"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
)

var r *render.Engine

func init() {
r = render.New(render.Options{
HTMLLayout: "application.html",
TemplateEngine: velvet.BuffaloRenderer,
TemplateEngine: plush.BuffaloRenderer,
FileResolverFunc: func() resolvers.FileResolver {
return &resolvers.RiceBox{
Box: rice.MustFindBox("../templates"),
Expand Down Expand Up @@ -233,13 +233,13 @@ const nIndexHTML = `<div class="row">
</tr>
</thead>
<tbody>
\{{#each routes as |r|}}
<%= for (r) in routes { %>
<tr>
<td>\{{r.Method}}</td>
<td>\{{r.Path}}</td>
<td><code>\{{r.HandlerName}}</code></td>
<td><%= r.Method %></td>
<td><%= r.Path %></td>
<td><code><%= r.HandlerName %></code></td>
</tr>
\{{/each}}
<% } %>
</tbody>
</table>
</div>
Expand All @@ -256,7 +256,7 @@ const nApplicationHTML = `<html>
<body>

<div class="container">
\{{ yield }}
<%= yield %>
</div>

<script src="/assets/application.js" type="text/javascript" charset="utf-8"></script>
Expand Down
33 changes: 16 additions & 17 deletions buffalo/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"

"github.com/gobuffalo/buffalo/buffalo/cmd/generate"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -286,7 +286,7 @@ func (b *builder) buildMain() error {
return err
}

ctx := velvet.NewContext()
ctx := plush.NewContext()
ctx.Set("root", rootPath)
ctx.Set("hasDB", hasDB)
if hasDB {
Expand All @@ -298,7 +298,7 @@ func (b *builder) buildMain() error {
}
ctx.Set("aPack", packagePath(rootPath)+"/a")
ctx.Set("name", filepath.Base(rootPath))
s, err := velvet.Render(buildMainTmpl, ctx)
s, err := plush.Render(buildMainTmpl, ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -473,15 +473,15 @@ import (

"github.com/markbates/grift/grift"
rice "github.com/GeertJohan/go.rice"
_ "{{aPack}}"
{{#if modelsPack}}
_ "<%= aPack %>"
<%= if (modelsPack) { %>
"io/ioutil"
"path/filepath"
"{{modelsPack}}"
{{/if}}
{{#if griftsPack}}
_ "{{griftsPack}}"
{{/if}}
"<%= modelsPack %>"
<% } %>
<%= if (griftsPack) { %>
_ "<%= griftsPack %>"
<% } %>
)

var version = "unknown"
Expand All @@ -495,10 +495,10 @@ func main() {
}
c := args[1]
switch c {
{{#if modelsPack}}
<%= if (modelsPack) { %>
case "migrate":
migrate()
{{/if}}
<% } %>
case "start", "run", "serve":
printVersion()
originalMain()
Expand All @@ -515,10 +515,10 @@ func main() {
}

func printVersion() {
fmt.Printf("{{name}} version %s (%s)\n\n", version, buildTime)
fmt.Printf("<%= name %> version %s (%s)\n\n", version, buildTime)
}

{{#if modelsPack}}
<%= if (modelsPack) { %>
func migrate() {
var err error
migrationBox, err = rice.FindBox("./migrations")
Expand All @@ -537,7 +537,7 @@ func migrate() {
}

func unpackMigrations() (string, error) {
dir, err := ioutil.TempDir("", "{{name}}-migrations")
dir, err := ioutil.TempDir("", "<%= name %>-migrations")
if err != nil {
log.Fatalf("Unable to create temp directory: %s", err)
}
Expand All @@ -555,7 +555,7 @@ func unpackMigrations() (string, error) {

return dir, nil
}
{{/if}}
<% } %>
`

var aGo = `package a
Expand All @@ -571,7 +571,6 @@ func init() {

func dropDatabaseYml() {
if DB_CONFIG != "" {

_, err := os.Stat("database.yml")
if err == nil {
// yaml already exists, don't do anything
Expand Down
4 changes: 2 additions & 2 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os/exec"

"github.com/gobuffalo/buffalo/buffalo/cmd/generate"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
"github.com/markbates/refresh/refresh"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -76,7 +76,7 @@ func startDevServer(ctx context.Context) error {
return err
}
defer f.Close()
t, err := velvet.Render(nRefresh, velvet.NewContextWith(map[string]interface{}{
t, err := plush.Render(nRefresh, plush.NewContextWith(map[string]interface{}{
"name": "buffalo",
}))
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
"github.com/markbates/inflect"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -105,7 +105,7 @@ func validateInGoPath(name string) error {
if err != nil {
return err
}
t, err := velvet.Render(notInGoWorkspace, velvet.NewContextWith(map[string]interface{}{
t, err := plush.Render(notInGoWorkspace, plush.NewContextWith(map[string]interface{}{
"name": name,
"gopath": gp,
"current": rootPath,
Expand Down Expand Up @@ -184,13 +184,13 @@ func init() {

const notInGoWorkspace = `Oops! It would appear that you are not in your Go Workspace.

Your $GOPATH is set to "{{gopath}}".
Your $GOPATH is set to "<%= gopath %>".

You are currently in "{{current}}".
You are currently in "<%= current %>".

The standard location for putting Go projects is something along the lines of "$GOPATH/src/github.com/{{username}}/{{name}}" (adjust accordingly).
The standard location for putting Go projects is something along the lines of "$GOPATH/src/github.com/<%= username %>/<%= name %>" (adjust accordingly).

We recommend you go to "$GOPATH/src/github.com/{{username}}/" and try "buffalo new {{name}}" again.`
We recommend you go to "$GOPATH/src/github.com/<%= username %>/" and try "buffalo new <%= name %>" again.`

const noGoPath = `You do not have a $GOPATH set. In order to work with Go, you must set up your $GOPATH and your Go Workspace.

Expand Down
2 changes: 1 addition & 1 deletion default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_DefaultContext_Render(t *testing.T) {
c.params = url.Values{"name": []string{"Mark"}}
c.Set("greet", "Hello")

err := c.Render(123, render.String("{{greet}} {{params.name}}!"))
err := c.Render(123, render.String(`<%= greet %> <%= params["name"] %>!`))
r.NoError(err)

r.Equal(123, res.Code)
Expand Down
28 changes: 14 additions & 14 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -71,8 +71,8 @@ func defaultErrorHandler(status int, err error, c Context) error {
"status": status,
"data": c.Data(),
}
ctx := velvet.NewContextWith(data)
t, err := velvet.Render(devErrorTmpl, ctx)
ctx := plush.NewContextWith(data)
t, err := plush.Render(devErrorTmpl, ctx)
if err != nil {
return errors.WithStack(err)
}
Expand All @@ -87,7 +87,7 @@ func defaultErrorHandler(status int, err error, c Context) error {
var devErrorTmpl = `
<html>
<head>
<title>{{status}} - ERROR!</title>
<title><%= status %> - ERROR!</title>
<style>
body {
font-family: helvetica;
Expand Down Expand Up @@ -121,13 +121,13 @@ var devErrorTmpl = `
</style>
</head>
<body>
<h1>{{status}} - ERROR!</h1>
<pre>{{error}}</pre>
<h1><%= status %> - ERROR!</h1>
<pre><%= error %></pre>
<hr>
<h3>Context</h3>
<pre>{{#each data as |k v|}}
{{inspect k}}: {{inspect v}}
{{/each}}</pre>
<pre><%= for (k, v) in data { %>
<%= inspect(k) %>: <%= inspect(v) %>
<% } %></pre>
<hr>
<h3>Routes</h3>
<table id="buffalo-routes-table">
Expand All @@ -139,13 +139,13 @@ var devErrorTmpl = `
</tr>
</thead>
<tbody>
{{#each routes as |route|}}
<%= for (route) in routes { %>
<tr>
<td>{{route.Method}}</td>
<td>{{route.Path}}</td>
<td><code>{{route.HandlerName}}</code></td>
<td><%= route.Method %></td>
<td><%= route.Path %></td>
<td><code><%= route.HandlerName %></code></td>
</tr>
{{/each}}
<% } %>
</tbody>
</table>
</body>
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/actions/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/buffalo/render/resolvers"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
)

var r *render.Engine

func init() {
r = render.New(render.Options{
HTMLLayout: "application.html",
TemplateEngine: velvet.BuffaloRenderer,
TemplateEngine: plush.BuffaloRenderer,
FileResolverFunc: func() resolvers.FileResolver {
return &resolvers.RiceBox{
Box: rice.MustFindBox("../templates"),
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/templates/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="/assets/application.css" type="text/css" media="all" />
</head>
<body>
{{ yield }}
<%= yield %>

<script src="/assets/application.js" type="text/javascript" charset="utf-8"></script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions examples/html-crud/actions/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/buffalo/render/resolvers"
"github.com/gobuffalo/velvet"
"github.com/gobuffalo/plush"
)

var r *render.Engine

func init() {
r = render.New(render.Options{
HTMLLayout: "application.html",
TemplateEngine: velvet.BuffaloRenderer,
TemplateEngine: plush.BuffaloRenderer,
FileResolverFunc: func() resolvers.FileResolver {
return &resolvers.RiceBox{
Box: rice.MustFindBox("../templates"),
Expand Down
10 changes: 5 additions & 5 deletions examples/html-crud/templates/_errors.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{#if verrs }}
<%= if (verrs) { %>
<div class="errors">
<ul>
{{#each verrs as |k v|}}
<li>{{ v }}</li>
{{/each}}
<%= for (k, v) in verrs { %>
<li><%= v %></li>
<% } %>
</ul>
</div>
{{/if}}
<% } %>
2 changes: 1 addition & 1 deletion examples/html-crud/templates/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>

{{ yield }}
<%= yield %>

<script src="/assets/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="/assets/application.js" type="text/javascript" charset="utf-8"></script>
Expand Down
6 changes: 3 additions & 3 deletions examples/html-crud/templates/users/_form.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div>
<label for="FirstName">First Name:</label>
<input type="text" name="FirstName" id="FirstName" value="{{ user.FirstName }}" />
<input type="text" name="FirstName" id="FirstName" value="<%= user.FirstName %>" />
</div>
<div>
<label for="LastName">Last Name:</label>
<input type="text" name="LastName" id="LastName" value="{{ user.LastName }}" />
<input type="text" name="LastName" id="LastName" value="<%= user.LastName %>" />
</div>
<div>
<label for="Email">Email:</label>
<input type="email" name="Email" id="Email" value="{{ user.Email }}" />
<input type="email" name="Email" id="Email" value="<%= user.Email %>" />
</div>
<div>
<input type="submit" value="Save" />
Expand Down
6 changes: 3 additions & 3 deletions examples/html-crud/templates/users/edit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Edit User</h1>

{{ partial "errors.html" }}
<form action="/users/{{ user.ID }}" method="POST" accept-charset="utf-8">
<%= partial("errors.html") %>
<form action="/users/<%= user.ID %>" method="POST" accept-charset="utf-8">
<input type="hidden" name="_method" id="_method" value="PUT" />
{{ partial "users/form.html" }}
<%= partial("users/form.html") %>
</form>
Loading