Permalink
Browse files

[scfld http] Finished index.html

  • Loading branch information...
1 parent 5982dc9 commit d9ba6b2a2bfdbb9432fe2844880ed41c26f1da79 @pksunkara pksunkara committed Mar 16, 2012
Showing with 76 additions and 13 deletions.
  1. +68 −13 lib/flatiron/cli/generate.js
  2. +8 −0 scaffolds/http/generators/scaffold/index.html
@@ -1,3 +1,11 @@
+/*
+ * generate.js: A generator for `http` template
+ *
+ * Copyright(c) 2011 Nodejitsu Inc.
+ * MIT LICENSE
+ *
+ */
+
var fs = require('fs'),
path = require('path'),
inflect = require('i'),
@@ -15,6 +23,9 @@ module.exports = function generate(/* arguments */) {
generator = path.join(scaffold, 'generators');
if (arguments.length > 1) {
+ //
+ // Show `generate` usage info
+ //
if (arguments[0] == 'help') {
if (module.exports.help[arguments[1]]) {
module.exports.writeHelp(arguments[1]);
@@ -26,6 +37,9 @@ module.exports = function generate(/* arguments */) {
var files = [];
switch(arguments[0]) {
+ //
+ // Assets generator
+ //
case 'assets':
if (arguments.length > 1) {
var name = arguments[1].underscore.pluralize;
@@ -43,6 +57,9 @@ module.exports = function generate(/* arguments */) {
module.exports.writeHelp(arguments[0]);
}
break;
+ //
+ // Helper generator
+ //
case 'helper':
if (arguments.length > 1) {
var name = arguments[1].underscore.singularize;
@@ -55,6 +72,9 @@ module.exports = function generate(/* arguments */) {
module.exports.writeHelp(arguments[0]);
}
break;
+ //
+ // Presenter generator
+ //
case 'presenter':
if (arguments.length > 1) {
var name = arguments[1].underscore;
@@ -69,6 +89,9 @@ module.exports = function generate(/* arguments */) {
fs.mkdirSync(viewDir, '0755');
}
+ //
+ // Views for a presenter
+ //
for (var key in arguments) {
actions.push(' ' + arguments[key] + ': function () {\n this.render();\n }');
files.push({
@@ -87,11 +110,14 @@ module.exports = function generate(/* arguments */) {
module.exports.writeHelp(arguments[0]);
}
break;
+ //
+ // Resource generator
+ //
case 'resource':
if (arguments.length > 1) {
- var name = arguments[1].underscore.singularize;
- var camel = arguments[1].singularize.camelize;
- var prop = '';
+ var name = arguments[1].underscore.singularize,
+ camel = arguments[1].singularize.camelize,
+ prop = '';
delete arguments[0];
delete arguments[1];
@@ -114,12 +140,15 @@ module.exports = function generate(/* arguments */) {
module.exports.writeHelp(arguments[0]);
}
break;
+ //
+ // API generator
+ //
case 'api':
if (arguments.length > 1) {
- var name = arguments[1].underscore.pluralize;
- var singname = name.singularize;
- var camel = arguments[1].singularize.camelize;
- var prop = '';
+ var name = arguments[1].underscore.pluralize,
+ singname = name.singularize,
+ camel = arguments[1].singularize.camelize,
+ prop = '';
delete arguments[0];
delete arguments[1];
@@ -148,12 +177,19 @@ module.exports = function generate(/* arguments */) {
module.exports.writeHelp(arguments[0]);
}
break;
+ //
+ // Scaffold generator
+ //
case 'scaffold':
if (arguments.length > 1) {
- var name = arguments[1].underscore.pluralize;
- var singname = name.singularize;
- var camel = arguments[1].singularize.camelize;
- var prop = '';
+ var name = arguments[1].underscore.pluralize,
+ singname = name.singularize,
+ camel = arguments[1].singularize.camelize,
+ plucamel = camel.pluralize,
+ prop = '';
+
+ var th = ' <th>ID</th>\n';
+ var td = ' <td class="_id"></td>\n';
delete arguments[0];
delete arguments[1];
@@ -166,13 +202,18 @@ module.exports = function generate(/* arguments */) {
for (var key in arguments) {
var arg = arguments[key].split(':');
+ th += ' <th>' + arg[0].camelize + '</th>\n';
+ td += ' <td class="' + arg[0] + '"></td>\n';
if (arg.length == 1) {
prop += ' this.string(\'' + arg[0] + '\');\n';
} else if (arg.length == 2) {
prop += ' this.' + arg[1] + '(\'' + arg[0] + '\');\n';
}
}
+ //
+ // Assets
+ //
files.push({
src: 'asset.css',
conf: {name: name},
@@ -188,21 +229,32 @@ module.exports = function generate(/* arguments */) {
path: path.join(target.stylesheets, 'scaffold.css')
});
+ //
+ // Presenter & Resource
+ //
files.push({
src: 'scaffold/presenter.js',
conf: {name: name, singname: singname, camel: camel},
path: path.join(target.presenters, name + '.js')
});
-
files.push({
src: 'resource.js',
conf: {name: name.singularize, camel: camel, prop: prop},
path: path.join(target.resources, name.singularize + '.js')
});
- ['index', 'new', 'show', 'edit'].forEach(function (action) {
+ //
+ // Views
+ //
+ files.push({
+ src: 'scaffold/index.html',
+ conf: {name: name, plucamel: plucamel, th: th, td: td},
+ path: path.join(target.views, name, 'index.html')
+ });
+ ['new', 'show', 'edit'].forEach(function (action) {
files.push({
src: 'scaffold/' + action + '.html',
+ conf: {name: name, plucamel: plucamel},
path: path.join(target.views, name, action + '.html')
});
});
@@ -215,6 +267,9 @@ module.exports = function generate(/* arguments */) {
break;
}
+ //
+ // Create files
+ //
if (files.length != 0) {
module.exports.writeFiles(generator, root, files, callback);
}
@@ -0,0 +1,8 @@
+<h1>Listing #PLUCAMEL</h1>
+
+<table>
+ <tr>
+#TH </tr>
+ <tr class="#NAME">
+#TD </tr>
+</table>

0 comments on commit d9ba6b2

Please sign in to comment.