Skip to content

Commit

Permalink
Add real CRUD to handlebars/mustache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Ng committed Jul 2, 2013
1 parent be7b55d commit 1edb87f
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 34 deletions.
24 changes: 20 additions & 4 deletions gen/scaffold/views/handlebars/add.html.hbs.ejs
@@ -1,6 +1,22 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.filename.plural %>" method="POST">
<fieldset>
<legend>Create a new <%= names.constructor.singular %></legend>
{{#if params.errors }}
<div class="control-group">
<ul>
{{#each params.errors}}
<li>{{this}}</li>
{{/each}}
</ul>
</div>
{{/if}}

{{{partial "form" this}}}

<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Add" />
</div>
</fieldset>
</form>
</div>
27 changes: 22 additions & 5 deletions gen/scaffold/views/handlebars/edit.html.hbs.ejs
@@ -1,6 +1,23 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
</div>
<form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.filename.plural %>/{{params.id}}?_method=PUT" method="POST">
<fieldset>
<legend>Update this <%= names.constructor.singular %></legend>
{{#if params.errors}}
<div class="control-group">
<ul>
{{#each params.errors }}
<li>{{this}}</li>
{{/each}}
</ul>
</div>
{{/if}}

{{{partial "form" this}}}

<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Save" />
<input type="submit" class="btn btn-danger" value="Delete" formaction="/<%= names.filename.plural %>/{{params.id}}?_method=DELETE" />
</div>
</fieldset>
</form>
</div>
36 changes: 36 additions & 0 deletions gen/scaffold/views/handlebars/form.html.hbs.ejs
@@ -0,0 +1,36 @@
<% for(var i in properties) { -%>
<% if(properties[i].name && properties[i].name !== 'id') { -%>
<div class="control-group">
<label for="<%= properties[i].name %>" class="control-label"><%= properties[i].name %></label>
<div class="controls">
<% if(properties[i].type === 'string') { -%>
<% if(properties[i].name === 'password') { -%>
<input type="password" class="span6" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else { -%>
<input type="text" class="span6" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } -%>
<% } else if(properties[i].type === 'text') { -%>
<textarea rows="10" class="span6" name="<%= properties[i].name %>"></textarea>
<% } else if(properties[i].type === 'number' || properties[i].type === 'int') { -%>
<input type="number" class="span2" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else if(properties[i].type === 'boolean') { -%>
<select name="<%= properties[i].name %>", class="span1">
{% if <%= names.property.singular %>.<%= properties[i].name %> %}
<option>false</option>
<option selected>true</option>
{% else %}
<option selected>false</option>
<option>true</option>
{% endif %}
</select>
<% } else if(properties[i].type === 'datetime') { -%>
<input type="datetime" class="span3" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else if(properties[i].type === 'date') { -%>
<input type="date" class="span2" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else { -%>
<%= properties[i].type %>
<% } -%>
</div>
</div>
<% } -%>
<% } -%>
19 changes: 15 additions & 4 deletions gen/scaffold/views/handlebars/index.html.hbs.ejs
@@ -1,6 +1,17 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<h2>All <%= names.constructor.plural %></h2>
<a href="/<%= names.property.plural %>/add" class="btn pull-right">Create a new <%= names.constructor.singular %></a>
</div>

<div id="<%= names.property.plural %>-list">
{{#each <%= names.property.plural %> }}
<div class="row list-item" id="<%= names.property.singular %>-{{id}}">
<div class="span8">
<h3><a href="/<%= names.property.plural %>/{{id}}">{{id}}</a></h3>
</div>
<div class="span4">
<h3><i class="icon-list-alt"></i>{{id}}</h3>
</div>
</div>
{{/each}}
</div>
18 changes: 14 additions & 4 deletions gen/scaffold/views/handlebars/show.html.hbs.ejs
@@ -1,6 +1,16 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<h2 class="<%= properties['default'].name || "id" %>">{{ <%= names.property.singular %>.<%= properties['default'].name || "id" %> }}</h2>
<a href="/<%= names.property.plural %>/{{params.id}}/edit" class="btn pull-right">Edit this <%= names.property.singular %></a>
</div>

<h2><%= names.constructor.singular %> Properties</h2>
{{#each <%= names.property.singular %> }}
<div class="row list-item">
<div class="span4">
<h3>{{@key}}</h3>
</div>
<div class="span8">
<h3><i class="icon-list-alt"></i><span class="{{ @key }}">{{ this }}</span></h3>
</div>
</div>
{{/each}}
22 changes: 18 additions & 4 deletions gen/scaffold/views/mustache/add.html.ms.ejs
@@ -1,6 +1,20 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.filename.plural %>" method="POST">
<fieldset>
<legend>Create a new <%= names.constructor.singular %></legend>
<div class="control-group">
<ul>
{{#params.errors}}
<li>{{.}}</li>
{{/params.errors}}
</ul>
</div>

{{{partial "form" this}}}

<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Add" />
</div>
</fieldset>
</form>
</div>
25 changes: 20 additions & 5 deletions gen/scaffold/views/mustache/edit.html.ms.ejs
@@ -1,6 +1,21 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
</div>
<form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.filename.plural %>/{{params.id}}?_method=PUT" method="POST">
<fieldset>
<legend>Update this <%= names.constructor.singular %></legend>
<div class="control-group">
<ul>
{{#params.errors}}
<li>{{.}}</li>
{{/params.errors}}
</ul>
</div>

{{{partial "form" this}}}

<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Save" />
<input type="submit" class="btn btn-danger" value="Delete" formaction="/<%= names.filename.plural %>/{{params.id}}?_method=DELETE" />
</div>
</fieldset>
</form>
</div>
36 changes: 36 additions & 0 deletions gen/scaffold/views/mustache/form.html.ms.ejs
@@ -0,0 +1,36 @@
<% for(var i in properties) { -%>
<% if(properties[i].name && properties[i].name !== 'id') { -%>
<div class="control-group">
<label for="<%= properties[i].name %>" class="control-label"><%= properties[i].name %></label>
<div class="controls">
<% if(properties[i].type === 'string') { -%>
<% if(properties[i].name === 'password') { -%>
<input type="password" class="span6" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else { -%>
<input type="text" class="span6" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } -%>
<% } else if(properties[i].type === 'text') { -%>
<textarea rows="10" class="span6" name="<%= properties[i].name %>"></textarea>
<% } else if(properties[i].type === 'number' || properties[i].type === 'int') { -%>
<input type="number" class="span2" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else if(properties[i].type === 'boolean') { -%>
<select name="<%= properties[i].name %>", class="span1">
{% if <%= names.property.singular %>.<%= properties[i].name %> %}
<option>false</option>
<option selected>true</option>
{% else %}
<option selected>false</option>
<option>true</option>
{% endif %}
</select>
<% } else if(properties[i].type === 'datetime') { -%>
<input type="datetime" class="span3" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else if(properties[i].type === 'date') { -%>
<input type="date" class="span2" name="<%= properties[i].name %>" value="{{<%= names.property.singular %>.<%= properties[i].name %>}}" />
<% } else { -%>
<%= properties[i].type %>
<% } -%>
</div>
</div>
<% } -%>
<% } -%>
19 changes: 15 additions & 4 deletions gen/scaffold/views/mustache/index.html.ms.ejs
@@ -1,6 +1,17 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<h2>All <%= names.constructor.plural %></h2>
<a href="/<%= names.property.plural %>/add" class="btn pull-right">Create a new <%= names.constructor.singular %></a>
</div>

<div id="<%= names.property.plural %>-list">
{{#<%= names.property.plural %>}}
<div class="row list-item" id="<%= names.property.singular %>-{{id}}">
<div class="span8">
<h3><a href="/<%= names.property.plural %>/{{id}}">{{id}}</a></h3>
</div>
<div class="span4">
<h3><i class="icon-list-alt"></i>{{id}}</h3>
</div>
</div>
{{/<%= names.property.plural %>}}
</div>
19 changes: 15 additions & 4 deletions gen/scaffold/views/mustache/show.html.ms.ejs
@@ -1,6 +1,17 @@
<div class="hero-unit">
<h3>Params</h3>
{{#params}}
<p>{{action}} action on {{controller}} controller.</p>
{{/params}}
<h2 class="<%= properties['default'].name || "id" %>">{{ <%= names.property.singular %>.<%= properties['default'].name || "id" %> }}</h2>
<a href="/<%= names.property.plural %>/{{params.id}}/edit" class="btn pull-right">Edit this <%= names.property.singular %></a>
</div>

<h2><%= names.constructor.singular %> Properties</h2>
<% for(var i in properties) { -%>
<div class="row list-item">
<div class="span4">
<h3><%= properties[i].name %></h3>
</div>
<div class="span8">
<h3><i class="icon-list-alt"></i>
<span class="<%= properties[i].name %>"><% if(properties[i].name === 'id') { %>{{ params.id }}<% } else { %>{{ <%= names.property.singular %>.<%= properties[i].name %> }}<% } %></span></h3>
</div>
</div>
<% } -%>

0 comments on commit 1edb87f

Please sign in to comment.