-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.js
More file actions
73 lines (54 loc) · 1.48 KB
/
view.js
File metadata and controls
73 lines (54 loc) · 1.48 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
// View Engine
"use strict";
var view = (function(){
var path = require('path'),
fs = require('fs'),
root = __dirname;
function _view(name){
var that = this;
that.defaultViewExtension = !!app.config.viewExtension ? app.config.viewExtension: ".html";
that.renderView = function(viewName){
//app.render(viewName + app.config.viewExtension);
var viewExists;
viewExists = that.lookup(viewName);
if(viewExists){
app.render(path.join(name, viewName + that.defaultViewExtension));
}
};
// lookup for the given "view"
that.lookup = function(viewName){
//var path;
var resolvedFilePath = path.resolve(app.config.viewPath, name, viewName);
//var dir = path.dirname(loc);
if(!!resolvedFilePath){
resolvedFilePath = this.resolve(resolvedFilePath);
}
console.log(resolvedFilePath);
return resolvedFilePath;
};
that.resolve = function(resolvedFilePath){
var stat = this.tryStat(resolvedFilePath);
console.log("2:"+resolvedFilePath);
if (!!stat && stat.isFile()) {
return true;
}
resolvedFilePath = path.join(resolvedFilePath + that.defaultViewExtension);
console.log("3:"+resolvedFilePath);
stat = this.tryStat(resolvedFilePath);
if (!!stat && stat.isFile()) {
return true;
}
return false;
};
that.tryStat = function(path) {
console.log("path: "+ path);
try {
return fs.statSync(path);
} catch (e) {
return undefined;
}
}
};
return _view;
})();
module.exports = view;