Skip to content

Commit

Permalink
Merge pull request #395 from ben-ng/ci
Browse files Browse the repository at this point in the history
New 'stache + handlebars CRUD scaffolding, and tests
  • Loading branch information
Ben committed Jul 2, 2013
2 parents 7631869 + 54da7d8 commit e3638c7
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,3 +15,4 @@ site/log/*
.log
npm-debug.log
doc/
test/tmp
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -2,3 +2,11 @@ language: node_js
node_js:
- "0.10"
- "0.8"

before_script:
- rm -R node_modules/model
- rm -R node_modules/utilities
- npm install https://github.com/mde/model/archive/master.tar.gz
- npm install https://github.com/mde/utilities/archive/master.tar.gz

script: node_modules/jake/bin/cli.js test
10 changes: 9 additions & 1 deletion Jakefile
Expand Up @@ -2,6 +2,8 @@
require('./lib/geddy')

var fs = require('fs')
, path = require('path')
, utils = require('utilities')
, createPackageTask
, JSPAT = /\.js$/
, testTask;
Expand Down Expand Up @@ -61,7 +63,7 @@ testTask = new jake.TestTask('Geddy', function () {
});

desc('Run the Geddy tests');
task('test', function () {
task('test', ['clean'], function () {
var t = jake.Task.testBase;
t.addListener('error', function (err) {
var module
Expand Down Expand Up @@ -89,3 +91,9 @@ task('test', function () {
t.invoke.apply(t, arguments);
}, {async: true});

desc('Clears the test temp dir');
task('clean', function () {
tmpDir = path.join(__dirname, 'test', 'tmp');
utils.file.rmRf(tmpDir, {silent:true});
fs.mkdirSync(tmpDir);
});
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>
<% } -%>
2 changes: 1 addition & 1 deletion gen/scaffold/views/swig/show.html.swig.ejs
Expand Up @@ -10,7 +10,7 @@
<h3>{{loop.key}}</h3>
</div>
<div class="span8">
<h3><i class="icon-list-alt"></i><span class="">{{ prop }}</span></h3>
<h3><i class="icon-list-alt"></i><span class="{{ loop.key }}">{{ prop }}</span></h3>
</div>
</div>
{% endfor %}
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -31,7 +31,11 @@
"preferGlobal": true,
"devDependencies": {
"browserify": "1.16.x",
"socket.io-client": "0.9.x"
"socket.io-client": "0.9.x",
"handlebars": "latest",
"jade": "latest",
"swig": "latest",
"ejs": "latest"
},
"engines": {
"node": "*"
Expand Down
2 changes: 1 addition & 1 deletion test/cmd.js → test/cli/cmd.js
@@ -1,5 +1,5 @@
var assert = require('assert')
, cmd = require('../lib/cmd')
, cmd = require('../../lib/cmd')
, Cmd = cmd.Cmd
, tests;

Expand Down

0 comments on commit e3638c7

Please sign in to comment.