Skip to content
This repository
Newer
Older
100644 730 lines (620 sloc) 20.545 kb
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
1 // Load the basic Geddy toolkit
2 require('../lib/geddy')
3
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
4 // Dependencies
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
5 var fs = require('fs')
6 , path = require('path')
d278a7e8 »
2012-08-15 Get example app working with external model lib
7 , utils = require('../lib/utils')
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
8 , Adapter = require('../lib/template/adapters');
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
9
d278a7e8 »
2012-08-15 Get example app working with external model lib
10 namespace('env', function () {
3e0c059f »
2012-09-28 Added basic console feature
11 task('init', function (environment) {
d278a7e8 »
2012-08-15 Get example app working with external model lib
12 jake.addListener('complete', function (e) {
13 jake.Task['env:cleanup'].invoke();
14 });
9e1fe046 »
2012-08-16 Got generators working.
15
3e0c059f »
2012-09-28 Added basic console feature
16 geddy.config = require('../lib/config').readConfig({
17 environment: environment || 'development'
18 });
9e1fe046 »
2012-08-16 Got generators working.
19 geddy.model = require('model');
20
5da7b94e »
2012-08-20 Cleaned up env init process a little more
21 require('../lib/init').init(geddy, function () {
9e1fe046 »
2012-08-16 Got generators working.
22 complete();
23 });
24 }, {async: true});
d278a7e8 »
2012-08-15 Get example app working with external model lib
25
26 task('cleanup', function () {
27 // Disconnect all the adapters
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
28 var adapters = geddy.model.loadedAdapters
29 , adapter;
30
d278a7e8 »
2012-08-15 Get example app working with external model lib
31 for (var p in adapters) {
48fb464a »
2012-08-16 Fixed DB adapter connect/disconnect
32 adapter = adapters[p];
33 if (typeof adapter.disconnect == 'function') {
34 adapter.disconnect();
35 }
d278a7e8 »
2012-08-15 Get example app working with external model lib
36 }
37 });
38
3e0c059f »
2012-09-28 Added basic console feature
39 });
40
41 namespace('console', function () {
42 task('start', ['env:init'], {async: true}, function (environment) {
43 var env = environment || 'development'
44 , t = jake.Task['env:init'];
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
45
3e0c059f »
2012-09-28 Added basic console feature
46 t.addListener('complete', function () {
47 var readline = require('readline')
48 , rl = readline.createInterface({
49 input: process.stdin
50 , output: process.stdout
51 });
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
52
3e0c059f »
2012-09-28 Added basic console feature
53 rl.setPrompt('>>> ');
54 rl.prompt();
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
55
3e0c059f »
2012-09-28 Added basic console feature
56 rl.addListener('line', function (line) {
57 try {
58 console.log(global.eval(line));
59 }
60 catch (e) {
61 console.log(e.stack);
62 }
63 rl.prompt();
64 });
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
65
3e0c059f »
2012-09-28 Added basic console feature
66 rl.addListener('close', function () {
67 console.log('Exiting ...');
f0c7bc1f »
2012-09-28 added echo and capture helper funtions to the console
68 return complete();
3e0c059f »
2012-09-28 Added basic console feature
69 });
70 });
f0c7bc1f »
2012-09-28 added echo and capture helper funtions to the console
71
72 global.capture = function (err, data) {
73 return global.results = {
74 err: err
75 , data: data
76 };
77 }
78
79 global.echo = function (err, data) {
80 capture(err, data);
81 if (err) {
82 console.log('Error: ', err);
83 }
84 if (data) {
85 if (data.length) {
86 for (var i in data) {
87 if (data[i] && data[i].toData) {
88 console.log(data[i].toData());
89 } else {
90 console.log(data[i]);
91 }
92 }
93 } else {
94 if (data && data.toData) {
95 console.log(data.toData());
96 } else {
97 console.log(data);
98 }
99 }
100 } else {
101 console.log('No data');
102 }
103 }
104
3e0c059f »
2012-09-28 Added basic console feature
105 t.invoke(env);
106 });
107 });
d278a7e8 »
2012-08-15 Get example app working with external model lib
108
109 namespace('db', function () {
48fb464a »
2012-08-16 Fixed DB adapter connect/disconnect
110 task('createTable', ['env:init'], function (name) {
9e1fe046 »
2012-08-16 Got generators working.
111 var modelName
48fb464a »
2012-08-16 Fixed DB adapter connect/disconnect
112 , createTable
d278a7e8 »
2012-08-15 Get example app working with external model lib
113 , adapters
9e1fe046 »
2012-08-16 Got generators working.
114 , adapter;
115
116 if (typeof name == 'string') {
117 if (name.indexOf(',') > -1) {
118 modelNames = name.split(',');
119 }
120 else {
121 modelNames = [name];
122 }
123 }
124 else {
125 modelNames = name;
126 }
127
d278a7e8 »
2012-08-15 Get example app working with external model lib
128 createTable = function () {
48fb464a »
2012-08-16 Fixed DB adapter connect/disconnect
129 if ((m = modelNames.shift())) {
9e1fe046 »
2012-08-16 Got generators working.
130
131 // Make sure this is a correct model-name
132 m = utils.string.getInflections(m).constructor.singular;
133 if (!geddy.model[m]) {
134 throw new Error(m + ' is not a known model.');
135 }
136
d278a7e8 »
2012-08-15 Get example app working with external model lib
137 adapter = geddy.model.adapters[m];
9e1fe046 »
2012-08-16 Got generators working.
138 if (adapter) {
139 console.log('Creating table for ' + m);
140 adapter.createTable(m, function (err, data) {
141 if (err) { throw err }
142 createTable();
143 });
144 }
145 else {
d278a7e8 »
2012-08-15 Get example app working with external model lib
146 createTable();
9e1fe046 »
2012-08-16 Got generators working.
147 }
d278a7e8 »
2012-08-15 Get example app working with external model lib
148 }
149 else {
150 complete();
151 }
152 };
153 createTable();
48fb464a »
2012-08-16 Fixed DB adapter connect/disconnect
154 }, {async: true});
155
156 task('retrofit', ['env:init'], function () {
157 var modelNames = Object.keys(geddy.model.descriptionRegistry)
158 , createTask = jake.Task['db:createTable'];
159 createTask.once('complete', function () {
160 complete();
161 });
162 createTask.invoke(modelNames);
d278a7e8 »
2012-08-15 Get example app working with external model lib
163 }, {async: true});
164
165 });
166
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
167 namespace('gen', function () {
168
b262b1c3 »
2012-08-28 Default ID attribute is now 'int', if scaffold model template the def…
169 var _writeTemplate = function (name, filename, dirname, opts) {
170 var options = opts || {}
171 , names = utils.string.getInflections(name)
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
172 , text = fs.readFileSync(path.join(__dirname, filename + '.ejs'), 'utf8').toString()
cf999eaa »
2012-07-06 Deleted bare controller template
173 , bare = options.bare || false // Default to full controller
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
174 , adapter
175 , templContent
9ec7c3a2 »
2012-09-24 Changed the generator to create the directory in case it doesn't exis…
176 , fileDir
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
177 , filePath;
178
179 // Render with the right model name
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
180 adapter = new Adapter({engine: 'ejs', template: text});
181 templContent = adapter.render({names: names, bare: bare, properties: options.properties});
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
182
183 // Write file
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
184 fileDir = dirname;
fc704022 »
2012-09-25 Removed usage of fs.existsSync for compatibility with node 0.6 and ch…
185 if (!utils.file.existsSync(fileDir)) {
186 fs.mkdirSync(fileDir);
187 }
9ec7c3a2 »
2012-09-24 Changed the generator to create the directory in case it doesn't exis…
188
189 filePath = path.join(fileDir, names.filename[options.inflection] + '.js');
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
190 fs.writeFileSync(filePath, templContent, 'utf8');
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
191
a0820314 »
2012-07-11 Updated readme to reflect new generators
192 console.log('[Added] ' + filePath);
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
193 };
194
edf26c75 »
2012-08-16 Formatting
195 var _formatModelProperties = function (properties) {
b262b1c3 »
2012-08-28 Default ID attribute is now 'int', if scaffold model template the def…
196 var obj = {'default': {name: 'id', type: 'int'}};
9e1fe046 »
2012-08-16 Got generators working.
197 if (!properties) {
198 return obj;
199 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
200
d3f4d449 »
2012-10-01 Spaces aren't legal inside passed Jake params.
201 var itemsArr = properties.split('%')
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
202 , name
203 , type
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
204 , args
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
205 , i
206 , value;
207
26600c53 »
2012-07-24 Just made a few loop optimizations for Array loops
208 i = -1;
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
209 while (++i < itemsArr.length) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
210 value = itemsArr[i];
dd3a65ba »
2012-10-19 Don't allow nodel property names to be CamelCased
211 name = utils.string.camelize(value.replace(/:.*/g, ''));
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
212 type = value.replace(/[a-zA-Z]*:?/, '');
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
213 args = type.replace(/[a-zA-Z]*:?/, '');
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
214
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
215 // Take off any args on the type
216 type = type.replace(/:.*/g, '');
217
9e1fe046 »
2012-08-16 Got generators working.
218 // Defaults and aliases
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
219 if (!type) {
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
220 type = 'string';
9e2a69d7 »
2012-08-25 If text attribute is given it switches to string, also took out place…
221 }
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
222 if (args === 'def') {
223 args = 'default';
224 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
225
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
226 switch (type) {
f835d2fb »
2012-08-26 Move type checks for generatirs into a switch statement so can be eas…
227 case 'text':
228 type = 'string';
229 break;
230 case 'integer':
231 type = 'int';
232 break;
233 case 'bool':
234 type = 'boolean';
235 break;
236 case 'default':
237 case 'def':
238 type = 'string';
239 args = 'default';
240 break;
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
241 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
242
bc021706 »
2012-10-14 Closes #230, Don't manually add the ID attribute into the model prope…
243 // Manage properties that deal with changing default properties
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
244 if (args === 'default') {
bc021706 »
2012-10-14 Closes #230, Don't manually add the ID attribute into the model prope…
245 // Reset old default property to it's own property, only if it's not
246 // already the default
247 if (name !== obj['default'].name) {
248 // If the new default item already exists then delete it
249 if (obj[name]) {
250 delete obj[name];
251 }
252
253 obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
254 }
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
255
256 // Add new default property
257 obj['default'] = {name: name, type: type};
258 continue;
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
259 }
260
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
261 // If ID property is given and it matches the default
262 // then rewrite the default with the new ID property
263 if (name === 'id' && obj['default'].name === 'id') {
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
264 obj['default'] = {name: name, type: type};
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
265 continue;
9e1fe046 »
2012-08-16 Got generators working.
266 }
d9489a2a »
2012-10-07 Closes 210, Generators will use `name` and `title` properties as the …
267
268 // If the name is name or title then set them to default, otherwise add
269 // the property normally
270 if (name === 'name' || name === 'title') {
271 // Reset old default to it's own property
272 obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
273
274 // Add new default property
275 obj['default'] = {name: name, type: type};
276 } else {
277 obj[name] = {name: name, type: type};
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
278 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
279 }
280
9925793b »
2012-07-19 Added default option to model property arguments as @TechWraith sugge…
281 return obj;
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
282 };
283
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
284 // Creates a new Geddy app scaffold
9e1fe046 »
2012-08-16 Got generators working.
285 task('app', function (name, engine) {
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
286 var mkdirs
287 , cps
288 , text
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
289 , adapter;
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
290
9e1fe046 »
2012-08-16 Got generators working.
291 if (!name) {
292 throw new Error('No app name specified.');
293 }
294 if (!engine) {
295 engine = 'ejs';
296 }
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
297
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
298 mkdirs = [
299 ''
300 , 'config'
301 , 'app/models'
302 , 'app/controllers'
303 , 'app/helpers'
304 , 'lib'
305 , 'log'
306 , 'node_modules'
307 , 'test'
308 ];
309 cps = [
310 ['views/' + engine, 'app/views']
311 , ['public', '']
312 , ['router.js', 'config']
313 , ['init.js', 'config']
314 , ['environment.js', 'config']
315 , ['development.js', 'config']
316 , ['production.js', 'config']
317 , ['main.js', 'app/controllers']
318 , ['application.js', 'app/controllers']
319 , ['favicon.ico', 'public']
320 ];
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
321
edf26c75 »
2012-08-16 Formatting
322 mkdirs.forEach(function (dir) {
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
323 jake.mkdirP(path.join(name, dir));
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
324 });
edf26c75 »
2012-08-16 Formatting
325 cps.forEach(function (cp) {
229b0bd4 »
2012-08-21 Made app copying silent, and hid ID property in model and controller …
326 jake.cpR(path.join(__dirname, 'base', cp[0]), path.join(name, cp[1]), {silent: true});
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
327 });
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
328
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
329 text = fs.readFileSync(path.join(__dirname, 'base', 'Jakefile.ejs'), 'utf8').toString();
330 adapter = new Adapter({engine: 'ejs', template: text});
331 fs.writeFileSync(path.join(name, 'Jakefile'), adapter.render({appName: name}), 'utf8');
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
332
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
333 console.log('Created app ' + name + '.');
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
334 });
335
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
336 // Creates a resource with a model, controller and a resource route
edf26c75 »
2012-08-16 Formatting
337 task('resource', function (name, modelProperties) {
9e1fe046 »
2012-08-16 Got generators working.
338 var names
339 , modelTask = jake.Task['gen:model'];
a0820314 »
2012-07-11 Updated readme to reflect new generators
340
9e1fe046 »
2012-08-16 Got generators working.
341 if (!name) {
342 throw new Error('No resource name specified.');
343 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
344
9e1fe046 »
2012-08-16 Got generators working.
345 modelTask.on('complete', function () {
346 jake.Task['gen:controller'].invoke(name);
347 jake.Task['gen:route'].invoke(name);
348 names = utils.string.getInflections(name);
349 // Create views folder but not actions
350 jake.mkdirP(path.join('app', 'views', names.filename.plural));
351 console.log('[Added] ' + names.filename.plural + ' view directory');
352 complete();
353 });
354 modelTask.invoke(name, modelProperties);
a0820314 »
2012-07-11 Updated readme to reflect new generators
355
9e1fe046 »
2012-08-16 Got generators working.
356 }, {async: true});
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
357
229b0bd4 »
2012-08-21 Made app copying silent, and hid ID property in model and controller …
358
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
359 // Creates a full scaffold with views, a model, controller and a resource route
edf26c75 »
2012-08-16 Formatting
360 task('scaffold', function (name, engine, modelProperties) {
9e1fe046 »
2012-08-16 Got generators working.
361 var modelTask = jake.Task['gen:model'];
362
6967867a »
2012-08-16 Misc. fixes to get generators working
363 if (!modelProperties && engine) {
a0820314 »
2012-07-11 Updated readme to reflect new generators
364 modelProperties = engine;
365 engine = '';
366 }
9e1fe046 »
2012-08-16 Got generators working.
367 if (!name) {
368 throw new Error('No scaffold name specified.');
369 }
370 if (!engine) {
371 engine = 'ejs';
372 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
373
9e1fe046 »
2012-08-16 Got generators working.
374 modelTask.on('complete', function () {
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
375 jake.Task['gen:test'].invoke(name,
376 {properties: modelProperties});
9e1fe046 »
2012-08-16 Got generators working.
377 jake.Task['gen:controllerScaffold'].invoke(name,
378 {properties: modelProperties});
379 jake.Task['gen:route'].invoke(name);
380 jake.Task['gen:viewsScaffold'].invoke(name,
381 {engine: engine, properties: modelProperties});
382 complete();
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
383 });
b262b1c3 »
2012-08-28 Default ID attribute is now 'int', if scaffold model template the def…
384 modelTask.invoke(name, modelProperties, 'scaffold');
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
385
9e1fe046 »
2012-08-16 Got generators working.
386 }, {async: true});
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
387
b262b1c3 »
2012-08-28 Default ID attribute is now 'int', if scaffold model template the def…
388 task('model', function (name, properties, modelPath) {
9e1fe046 »
2012-08-16 Got generators working.
389 var createTableTask;
390 if (!name) {
391 throw new Error('No model name specified.');
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
392 }
b262b1c3 »
2012-08-28 Default ID attribute is now 'int', if scaffold model template the def…
393 if (!modelPath) {
394 modelPath = 'resource';
395 }
396 modelPath += '/model';
a0820314 »
2012-07-11 Updated readme to reflect new generators
397
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
398 _writeTemplate(name, modelPath, path.join('app', 'models'), {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
399 inflection: 'singular'
400 , properties: _formatModelProperties(properties)
401 });
a0820314 »
2012-07-11 Updated readme to reflect new generators
402
9e1fe046 »
2012-08-16 Got generators working.
403 // Try to create a table -- should be a no-op if an
404 // appropriate DB adapter can't be found
405 createTableTask = jake.Task['db:createTable'];
406 createTableTask.on('complete', function () {
407 complete();
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
408 });
9e1fe046 »
2012-08-16 Got generators working.
409 createTableTask.invoke(name);
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
410
9e1fe046 »
2012-08-16 Got generators working.
411 }, {async: true});
a0820314 »
2012-07-11 Updated readme to reflect new generators
412
9e1fe046 »
2012-08-16 Got generators working.
413 task('controller', function (name) {
414 if (!name) {
415 throw new Error('No controller name specified.');
416 }
417
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
418 _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
9e1fe046 »
2012-08-16 Got generators working.
419 {inflection: 'plural', bare: false});
a0820314 »
2012-07-11 Updated readme to reflect new generators
420 });
421
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
422 task('test', function (name) {
423 if (!name) {
424 throw new Error('No test name specified.');
425 }
426
427 _writeTemplate(name, 'resource/test', 'test',
428 {inflection: 'singular'});
429 });
430
9e1fe046 »
2012-08-16 Got generators working.
431 task('controllerScaffold', function (name, options) {
432 if (!name) {
433 throw new Error('No controller name specified.');
434 }
a0820314 »
2012-07-11 Updated readme to reflect new generators
435 options = options || {};
436
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
437 _writeTemplate(name, 'scaffold/controller', path.join('app', 'controllers'), {
a0820314 »
2012-07-11 Updated readme to reflect new generators
438 inflection: 'plural'
439 , bare: false
440 , properties: _formatModelProperties(options.properties)
441 });
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
442 });
443
9e1fe046 »
2012-08-16 Got generators working.
444 task('bareController', function (name, engine) {
445 if (!name) {
446 throw new Error('No controller name specified.');
447 }
448 if (!engine) {
449 engine = 'ejs';
450 }
a0820314 »
2012-07-11 Updated readme to reflect new generators
451
109ee592 »
2012-10-05 Added Jakefile, test dir to app, test stubs to scaffolds.
452 _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
453 {inflection: 'plural', bare: true});
a0820314 »
2012-07-11 Updated readme to reflect new generators
454 jake.Task['gen:route'].invoke(name, {bare: true});
455 jake.Task['gen:views'].invoke(name, {bare: true, engine: engine});
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
456 });
457
9e1fe046 »
2012-08-16 Got generators working.
458 task('route', function (name, options) {
459 if (!name) {
460 throw new Error('No route name specified.');
461 }
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
462 options = options || {};
463
d92f1576 »
2012-08-02 Get generators working
464 var names = utils.string.getInflections(name)
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
465 , routeType = options.bare ? 'Bare' : 'Resource'
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
466 , jsRouter = path.normalize('config/router.js')
467 , coffeeRouter = path.normalize('config/router.coffee')
468 , routerPath
469 , routerArr
470 , text
471 , splitText
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
472 , newRoute
473 , beginPath;
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
474
475 // Check if the router file exists
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
476 beginPath = path.join(process.cwd(), 'config');
edf26c75 »
2012-08-16 Formatting
477 utils.file.searchParentPath(jsRouter, function (err) {
6967867a »
2012-08-16 Misc. fixes to get generators working
478 if (err) {
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
479 var jsErr = err;
480 // If jsEnvironment wasn't found, try finding coffee variant
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
481 utils.file.searchParentPath(coffeeRouter, beginPath, function (err) {
6967867a »
2012-08-16 Misc. fixes to get generators working
482 if (err) {
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
483 throw jsErr;
484 } else {
485 routerPath = coffeeRouter;
486 }
487 });
488 } else {
489 routerPath = jsRouter;
490 }
491 });
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
492
6967867a »
2012-08-16 Misc. fixes to get generators working
493 if (routerPath) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
494 text = fs.readFileSync(routerPath, 'utf8');
495
6967867a »
2012-08-16 Misc. fixes to get generators working
496 if (routerPath.match('.coffee')) {
497 if (options.bare) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
498 newRoute = 'router.match(\'/' + names.filename.plural +
499 '\').to controller: \'' + names.constructor.plural +
500 '\', action: \'index\'';
baa8cdf8 »
2012-07-25 Updated /site to reflect new features related to generators and templ…
501 } else {
502 newRoute = 'router.resource \'' + names.filename.plural + '\'';
503 }
6967867a »
2012-08-16 Misc. fixes to get generators working
504 } else if (routerPath.match('.js')) {
505 if (options.bare) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
506 newRoute = 'router.match(\'/' + names.filename.plural +
507 '\').to({controller: \'' + names.constructor.plural +
508 '\', action: \'index\'});';
baa8cdf8 »
2012-07-25 Updated /site to reflect new features related to generators and templ…
509 } else {
510 newRoute = 'router.resource(\'' + names.filename.plural + '\');';
511 }
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
512 }
513
514 // Don't add the same route over and over
6967867a »
2012-08-16 Misc. fixes to get generators working
515 if (text.indexOf(newRoute) == -1) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
516 // Add the new resource route just above the export
517 routerArr = text.split('exports.router');
518 routerArr[0] += newRoute + '\n';
519
520 text = routerArr.join('exports.router');
521 fs.writeFileSync(routerPath, text, 'utf8');
522
a0820314 »
2012-07-11 Updated readme to reflect new generators
523 console.log('[Added] ' + routeType + ' ' + names.filename.plural +
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
524 ' route added to ' + routerPath);
525 }
526 else {
a0820314 »
2012-07-11 Updated readme to reflect new generators
527 console.log(routeType + ' ' + names.filename.plural + ' route already defined in ' +
528 routerPath);
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
529 }
530
baa8cdf8 »
2012-07-25 Updated /site to reflect new features related to generators and templ…
531 } else {
532 console.log('There is no router file to add routes too');
533 }
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
534 });
535
9e1fe046 »
2012-08-16 Got generators working.
536 task('views', function (name, options) {
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
537 if (!name) {
538 throw new Error('No view name specified.');
539 }
a0820314 »
2012-07-11 Updated readme to reflect new generators
540
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
541 options = options || {};
542
a0820314 »
2012-07-11 Updated readme to reflect new generators
543 // Option defaults
544 options.engine = options.engine || 'ejs';
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
545
d92f1576 »
2012-08-02 Get generators working
546 var names = utils.string.getInflections(name)
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
547 , engine = options.engine
548 , appViewDir = path.join('app', 'views', names.filename.plural)
549 , templateViewDir = path.join(__dirname, 'views', engine)
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
550 , cmds = []
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
551 , ext = '.html'
552 , appLayoutPath
553 , actions
554 , addActionView;
555
556 // Set extension based on engine option
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
557 switch (engine) {
558 case 'ejs':
559 ext += '.ejs';
560 break;
561 case 'jade':
562 ext += '.jade';
563 break;
564 case 'handlebars':
565 ext += '.hbs';
566 break;
567 case 'mustache':
568 ext += '.ms';
569 break;
570 }
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
571
572 // Set application layout path
573 appLayoutPath = path.join('app', 'views', 'layouts', 'application');
574 // Copy template view to application path
edf26c75 »
2012-08-16 Formatting
575 addActionView = function (action) {
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
576 jake.cpR(path.join(templateViewDir, action + ext), appViewDir);
577 };
578
579 jake.mkdirP(appViewDir);
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
580 jake.mkdirP('app/views/layouts');
581 addActionView('index');
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
582
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
583 // Add views for the other CRUD actions when doing a full-on resource
6967867a »
2012-08-16 Misc. fixes to get generators working
584 if (!options.bare) {
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
585 ['add', 'edit', 'show'].forEach(function (action) {
586 addActionView(action);
587 });
588 }
589
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
590 // Create default layout if one doesn't exist
591 // Hack: There should be a better way to detect if a application layout exists
6967867a »
2012-08-16 Misc. fixes to get generators working
592 if (!utils.file.existsSync(appLayoutPath + '.html.ejs') && !utils.file.existsSync(appLayoutPath + '.html.jade') &&
593 !utils.file.existsSync(appLayoutPath + '.html.hbs') && !utils.file.existsSync(appLayoutPath + '.html.ms')) {
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
594 // Copy template layout file to apps application layout file
595 jake.cpR(path.join(templateViewDir, 'layout' + ext), appLayoutPath + ext);
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
596 }
597
a0820314 »
2012-07-11 Updated readme to reflect new generators
598 console.log('[Added] View templates');
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
599 });
600
edf26c75 »
2012-08-16 Formatting
601 task('viewsScaffold', function (name, options) {
6967867a »
2012-08-16 Misc. fixes to get generators working
602 if (!name) {
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
603 throw new Error('No view name specified.');
604 }
a0820314 »
2012-07-11 Updated readme to reflect new generators
605
606 options = options || {};
607
608 // Option defaults
609 options.engine = options.engine || 'ejs';
610
d92f1576 »
2012-08-02 Get generators working
611 var names = utils.string.getInflections(name)
a0820314 »
2012-07-11 Updated readme to reflect new generators
612 , engine = options.engine
613 , appViewDir = path.join('app', 'views', names.filename.plural)
614 , templateViewDir = path.join(__dirname, 'scaffold', 'views', engine)
615 , cmds = []
616 , ext = '.html'
617 , appLayoutPath
618 , actions
619 , addActionView
620 , text
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
621 , adapter
622 , templContent;
a0820314 »
2012-07-11 Updated readme to reflect new generators
623
624 // Set extension based on engine option
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
625 switch (engine) {
626 case 'ejs':
627 ext += '.ejs';
628 break;
629 case 'jade':
630 ext += '.jade';
631 break;
632 case 'handlebars':
633 ext += '.hbs';
634 break;
635 case 'mustache':
636 ext += '.ms';
637 break;
638 }
a0820314 »
2012-07-11 Updated readme to reflect new generators
639
640 // Set application layout path
641 appLayoutPath = path.join('app', 'views', 'layouts', 'application');
642
643 // Function to compile the template
edf26c75 »
2012-08-16 Formatting
644 addActionView = function (action) {
a0820314 »
2012-07-11 Updated readme to reflect new generators
645 text = fs.readFileSync(path.join(templateViewDir, action + ext + '.ejs')).toString();
646
647 // Compile template text
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
648 adapter = new Adapter({engine: 'ejs', template: text});
649 templContent = adapter.render({names: names, properties: _formatModelProperties(options.properties)});
a0820314 »
2012-07-11 Updated readme to reflect new generators
650
651 // Write file
652 fs.writeFileSync(path.join(appViewDir, action + ext),
2e8e3fb5 »
2012-10-24 Remove the third party dependency Templato(which was rewritten in JS …
653 templContent.replace(/<@/g, '<%').replace(/@>/g, '%>'), 'utf8');
a0820314 »
2012-07-11 Updated readme to reflect new generators
654 };
655
656 jake.mkdirP(appViewDir);
657 jake.mkdirP('app/views/layouts');
658
659 // Add views for the other CRUD actions when doing a full-on resource
edf26c75 »
2012-08-16 Formatting
660 ['index', 'add', 'show', 'edit'].forEach(function (action) {
a0820314 »
2012-07-11 Updated readme to reflect new generators
661 addActionView(action);
662 });
663
664 // Create default layout if one doesn't exist
665 // Hack: There should be a better way to detect if a application layout exists
6967867a »
2012-08-16 Misc. fixes to get generators working
666 if (!utils.file.existsSync(appLayoutPath + '.html.ejs') && !utils.file.existsSync(appLayoutPath + '.html.jade') &&
667 !utils.file.existsSync(appLayoutPath + '.html.hbs') && !utils.file.existsSync(appLayoutPath + '.html.ms')) {
a0820314 »
2012-07-11 Updated readme to reflect new generators
668 // Copy template layout file to apps application layout file
669 jake.cpR(path.join(templateViewDir, 'layout' + ext), appLayoutPath + ext);
670 }
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
671
a0820314 »
2012-07-11 Updated readme to reflect new generators
672 console.log('[Added] View templates');
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
673 });
674
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
675 // Generate a new application secret in environment.js
9e1fe046 »
2012-08-16 Got generators working.
676 task('secret', function () {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
677 var jsEnvironment = path.normalize('config/environment.js')
678 , coffeeEnvironment = path.normalize('config/environment.coffee')
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
679 , secret = utils.string.uuid(128)
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
680 , environmentPath
681 , environmentArr
682 , text
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
683 , splitText
684 , beginPath;
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
685
686 // Check if the environment file exists
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
687 beginPath = path.join(process.cwd(), 'config');
edf26c75 »
2012-08-16 Formatting
688 utils.file.searchParentPath(jsEnvironment, function (err) {
6967867a »
2012-08-16 Misc. fixes to get generators working
689 if (err) {
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
690 var jsErr = err;
691 // If jsEnvironment wasn't found, try finding coffee variant
0d9e54e5 »
2012-10-08 Fix a bug in generators where searching for Coffee config variants di…
692 utils.file.searchParentPath(coffeeEnvironment, beginPath, function (err) {
6967867a »
2012-08-16 Misc. fixes to get generators working
693 if (err) {
693a0fe0 »
2012-07-24 Created a file utils function that will search for a dir/file in up t…
694 throw jsErr;
695 } else {
696 environmentPath = coffeeEnvironment;
697 }
698 });
699 } else {
700 environmentPath = jsEnvironment;
701 }
702 });
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
703
6967867a »
2012-08-16 Misc. fixes to get generators working
704 if (environmentPath) {
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
705 text = fs.readFileSync(environmentPath, 'utf8').toString();
706
707 // Remove any old secret
708 text = text.replace(/\nconfig.secret.+\n/, '');
709
710 splitText = 'module.exports = config';
d9fe3bb5 »
2012-09-25 Get rid of all the syntax differences, well most of them.
711 if (environmentPath.match('.js')) {
712 splitText += ';';
713 }
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
714
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
715 environmentArr = text.split(splitText);
716 environmentArr[0] += "config.secret = '" + secret + "'";
717 environmentArr[0] += environmentPath.match('.js') ? ';\n\n' : '\n\n';
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
718
1282075d »
2012-07-09 Fix old Fleegix lib code for template adapters
719 text = environmentArr.join(splitText);
720 fs.writeFileSync(environmentPath, text, 'utf8');
ae3f611a »
2012-07-02 Created app and resource generators for Jade, Handlebars and Mustache
721
a0820314 »
2012-07-11 Updated readme to reflect new generators
722 console.log('[Added] Application secret to \'' + environmentPath + '\'');
6967867a »
2012-08-16 Misc. fixes to get generators working
723 }
9e1fe046 »
2012-08-16 Got generators working.
724 else {
725 console.log('There is no environment config to add the app-secret to.');
726 }
c389ea99 »
2012-06-23 Move generator Jake tasks into a separate Jakefile.
727 });
728
729 });
Something went wrong with that request. Please try again.