-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathmodel
More file actions
74 lines (59 loc) · 1.98 KB
/
model
File metadata and controls
74 lines (59 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
if (_args.length < 1) {
print("USAGE : js jquery/generate/model cookbook/models/recipe")
print();
quit();
}
load('steal/rhino/rhino.js');
steal( 'steal/generate',
'steal/generate/system.js',
'steal/generate/inflector.js',
function(steal){
var upper = function(parts){
for(var i =0; i < parts.length; i++){
parts[i] = parts[i].charAt(0).toUpperCase()+parts[i].substr(1)
}
return parts
}
if(_args[0].charAt(0) !== _args[0].charAt(0).toUpperCase()){
var caps = upper( _args[0].split(/_|-/) ).join(''),
name = upper(caps.split("/")).join('.');
print(" Creating "+name);
_args[0] = name;
}
var md = steal.generate.convert(_args[0]),
path = _args[0].toLowerCase().replace('.',"/");
var folder = md.path.replace(/\/\w+$/, "")
if(!folder){
print("! Error: Models need to be part of an app");
quit();
}
if(!steal.File(folder).exists()){
print("! Error: folder "+folder+" does not exist!");
quit();
}
md.path_to_steal = new steal.File(path).pathToRoot();
md.appPath = md.path.replace(/\/models$/,"");
//check pluralization of last part
if(steal.Inflector.singularize(md.underscore) !== md.underscore){
print("! Warning: Model names should be singular. I don't think "+md.underscore+" is singular!")
}
// generate the files
steal.generate("jquery/generate/templates/model", md.appPath, md)
try{
// steal this model in models.js
steal.generate.insertSteal(md.appPath+"/models/models.js", "./"+md.underscore+".js");
// steal this model's unit test in qunit.js
steal.generate.insertSteal(md.appPath+"/test/qunit/qunit.js", "./"+md.underscore+"_test.js");
} catch (e) {
if(e.type && e.type == "DUPLICATE"){
print("! Error: This model was already created!")
quit();
}
}
// $.fixture.make for this model in fixtures.js
var text = readFile("jquery/generate/templates/fixturemake.ejs");
var fixturetext = new steal.EJS({
text: text
}).render(md);
steal.generate.insertCode(md.appPath+"/fixtures/fixtures.js", fixturetext);
});