-
Notifications
You must be signed in to change notification settings - Fork 1
/
views.js
78 lines (68 loc) · 1.75 KB
/
views.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
var env;
/**
* Primary rendering function
*
* @param response Object Function passed from callback
* @param pageName String Name of page to render
* @param kwargs Object Optional arguments for template as javascript object
*/
function render(response, pageName, kwargs)
{
console.log('Rendering ' + pageName);
var start = Date.now();
kwargs = kwargs == 'undefined' ? {}:kwargs;
response.render('./'+pageName+'/'+pageName+'.html', kwargs);
console.log('Page rendered in ' + ((Date.now()-start)/1000) + " seconds");
}
function ajaxRender(response, pageName, kwargs)
{
kwargs = kwargs == 'undefined' ? {}:kwargs;
var bodyTemplate = env.getTemplate('./'+pageName+'/'+pageName+'-body.html');
return bodyTemplate.render(kwargs);
}
// Object to map pages to output.
module.exports =
{
setEnvironment: function(environment)
{
env = environment;
},
mainPage: function mainPage(request, response)
{
render(response, arguments.callee.name);
},
techPage: function techPage(request, response)
{
render(response, arguments.callee.name);
},
clientPage: function clientPage(request, response)
{
render(response, arguments.callee.name);
}
};
// AUXILLARY FUNCTIONS
/**
* This is a reverse hash map lookup function
*
* @param fn
* @return {*}
*/
function name(fn) { for (var o in module.exports) { if (fn===module.exports[o]) {return o} }}
/**
* Merges two javascript objects into one
*
* @return {Object}
*/
function objectMerge()
{
var out = {};
if(!arguments.length) { return out; }
for(var i=0; i<arguments.length; i++)
{
for(var key in arguments[i])
{
out[key] = arguments[i][key];
}
}
return out;
}