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

Commit

Permalink
Merge pull request #1 from as27/htmltemplates
Browse files Browse the repository at this point in the history
htmltemplates
  • Loading branch information
as27 authored Mar 31, 2017
2 parents 1cfd7a9 + 319d064 commit 2b9283b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
11 changes: 10 additions & 1 deletion buffalo/cmd/generate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var ResourceCmd = &cobra.Command{
modelName = name
}
}
modelProps := getModelPropertiesFromArgs(args)

data := makr.Data{
"name": name,
Expand All @@ -94,17 +95,25 @@ var ResourceCmd = &cobra.Command{
"varSingular": inflect.Singularize(inflect.CamelizeDownFirst(modelName)),
"actions": []string{"List", "Show", "New", "Create", "Edit", "Update", "Destroy"},
"args": args,
"modelProps": modelProps,

// Flags
"skipMigration": SkipResourceMigration,
"skipModel": SkipResourceModel,
"useModel": UseResourceModel,
}

g, err := resource.New(data)
if err != nil {
return err
}
return g.Run(".", data)
},
}

func getModelPropertiesFromArgs(args []string) []string {
var mProps []string
for _, a := range args[1:] {
mProps = append(mProps, inflect.Camelize(a))
}
return mProps
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= if (verrs) { %>
<div class="errors">
<ul>
<%= for (k, v) in verrs { %>
<li><%= v %></li>
<% } %>
</ul>
</div>
<% } %>
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<h2>{{.camel}}#Form</h2>
{{ range $p := .modelProps }}
<div>
<label for="{{$p}}">{{$p}}:</label>
<input type="text" name="{{$p}}" id="{{$p}}" value="<%= {{$.varSingular}}.{{$p}} %>" />
</div>
{{ end }}

<div>
<input type="submit" value="Save" />
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<h1>{{.camel}}#Edit</h1>
<h1>Edit {{.model}}</h1>

<%= partial("{{.modelPluralUnder}}/errors.html") %>

<form action="/{{.under}}/<%= {{.varSingular}}.ID" method="POST" accept-charset="utf-8">
<input type="hidden" name="_method" id="_method" value="PUT" />
<%= partial("{{.modelPluralUnder}}/form.html") %>
</form>
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
<h1>{{.camel}}#Index</h1>

<h1>{{.modelPlural}}</h1>

<p>
<a href="/{{.plural}}/new">Create New {{.model}}</a>
</p>

<table>
<thead>
{{ range $p := .modelProps }}
<th>{{ $p }}</th>
{{ end }}
</thead>
<tbody>
<%= for ({{.varSingular}}) in {{.varPlural}} { %>
<tr>
{{ range $mp := .modelProps }}
<td><%= {{$.varSingular}}.{{$mp}} %></td>
{{ end }}
<td>
<a href="/{{$.plural}}/<%= {{$.varSingular}}.ID %>">View</a>
<a href="/{{$.plural}}/<%= {{$.varSingular}}.ID %>/edit">Edit</a>
<a href="/{{$.plural}}/<%= {{$.varSingular}}.ID %>" data-method="DELETE" data-confirm="Are you sure?">Destroy</a>
</td>
</tr>
<% } %>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<h1>{{.camel}}#New</h1>
<h1>New {{.model}}</h1>

<%= partial("{{.modelPluralUnder}}/errors.html") %>
<form action="/{{.under}}" method="POST" accept-charset="utf-8">
<%= partial("{{.modelPluralUnder}}/form.html") %>
</form>
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
<h1>{{.camel}}#Show</h1>
<h1>{{.camel}}#Show</h1>
{{ range $p := .modelProps }}
<div>
{{ $p }}: <%= {{$.varSingular}}.{{$p}} %>

</div>
{{ end }}

<ul>
<li><a href="/{{$.plural}}">Back to all {{.modelPlural}}</a></li>
<li><a href="/{{$.plural}}/<%= {{$.varSingular}}.ID %>/edit">Edit</a></li>
<li><a href="/{{$.plural}}/<%= {{$.varSingular}}.ID %>" data-method="DELETE" data-confirm="Are you sure?">Destroy</a>
</ul>

0 comments on commit 2b9283b

Please sign in to comment.