-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
116 lines (109 loc) · 3.05 KB
/
index.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Generated by CoffeeScript 1.3.3
var cc, fs, hardcode, wrench;
cc = require('coffeecup');
hardcode = require('coffeecup-helpers');
fs = require('fs');
wrench = require('wrench');
exports.attach = function(options) {
var controller, fn, helper, items, match, name, registeredViews, self, valid, view, _i, _j, _k, _len, _len1, _len2, _ref;
if (options == null) {
options = {};
}
self = this;
registeredViews = {};
if (options.views != null) {
items = wrench.readdirSyncRecursive(options.views);
for (_i = 0, _len = items.length; _i < _len; _i++) {
view = items[_i];
if (view.match(/(.+)\.(js|coffee|coffee\.md)$/)) {
fn = require(options.views + '/' + view);
name = view.split('.').shift();
registeredViews[name] = fn;
}
}
}
if (options.controllers != null) {
items = wrench.readdirSyncRecursive(options.controllers);
for (_j = 0, _len1 = items.length; _j < _len1; _j++) {
controller = items[_j];
if (controller.match(/(.+)\.(js|coffee|coffee\.md)$/)) {
fn = require(options.controllers + '/' + controller);
this.router.mount(fn);
}
}
}
if (options.helpers != null) {
items = wrench.readdirSyncRecursive(options.helpers);
for (_k = 0, _len2 = items.length; _k < _len2; _k++) {
helper = items[_k];
match = helper.match(/(.*)\.(js|coffee|coffee\.md)/);
if (match) {
fn = require(options.helpers + '/' + helper);
name = match[1].replace(/[\. \/]+/g, '_');
valid = cc.compile(fn, {
hardcode: hardcode,
locals: true
});
if (typeof fn === 'function') {
hardcode[name] = fn;
}
}
}
}
this.bind = function(page, data) {
var html, _ref;
html = "";
if (typeof page === 'string') {
page = registeredViews[page];
}
if (data == null) {
data = {};
}
if (((_ref = this.req) != null ? _ref.session : void 0) != null) {
data.session = this.req.session;
}
if ((options.layout != null) && typeof page === 'function') {
hardcode.content = page;
html = cc.render(options.layout, data, {
hardcode: hardcode,
locals: true
});
} else if (typeof page === 'function') {
html = cc.render(page, data, {
hardcode: hardcode,
locals: true
});
} else {
'<p>Not Found</p>';
}
if (this.res != null) {
return this.res.html(html);
} else {
return html;
}
};
this.registerHelper = function(name, fn) {
valid = cc.compile(fn, {
hardcode: hardcode,
locals: true
});
if (typeof fn === 'function') {
return hardcode[name] = fn;
}
};
this.registerView = function(name, fn) {
valid = cc.compile(fn, {
hardcode: hardcode,
locals: true
});
return registeredViews[name] = fn;
};
if (((_ref = this.router) != null ? _ref.attach : void 0) != null) {
return this.router.attach((function() {
return this.bind = self.bind;
}));
}
};
exports.init = function(done) {
return done();
};