forked from fabiocaseri/dashing-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththor.js
49 lines (47 loc) · 1.54 KB
/
thor.js
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
var fs = require('fs-extra')
, path = require('path')
, scaffold = require('./scaffold');
exports.Thor = {
source_root: path.resolve(__dirname, '../templates'),
directory: function(src, dest, locals, options) {
dest = dest || src;
locals = locals || {};
locals.Thor = this;
options = options || {};
scaffold([this.source_root, src].join(path.sep), dest, {
engine: 'ejs',
engine_opts: {
open: '{{',
close: '}}'
},
ext: 'tt',
namepre: '%',
namesuf: '%',
data: locals,
filterFile: function(file, stat) {
return !file.match(/\.empty_directory$/);
}
}, function(err) {
if (err) console.error(err);
});
},
empty_directory: function(dest, options) {
fs.mkdirp(dest, function(err) {
if (err) console.error(err);
});
},
Util: {
camel_case: function(str) {
if (str.charAt(0) !== '_') str = '_' + str;
return str.replace(/(_[a-z0-9])/mg, function(s) {return s.replace('_', '').toUpperCase()});
},
dash_case: function(str) {
if (str.charAt(0) >= 'A' && str.charAt(0) <= 'Z') str = str.substring(0,1).toLowerCase() + str.substring(1);
return str.replace(/([A-Z])/g, function(s){return '-' + s.toLowerCase()});
},
snake_case: function(str) {
if (str.charAt(0) >= 'A' && str.charAt(0) <= 'Z') str = str.substring(0,1).toLowerCase() + str.substring(1);
return str.replace(/([A-Z])/g, function(s){return '_' + s.toLowerCase()});
}
}
};