-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy patherrors.js
More file actions
81 lines (62 loc) · 1.86 KB
/
errors.js
File metadata and controls
81 lines (62 loc) · 1.86 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
75
76
77
78
79
80
81
/*
* errors.js: Methods for generating "error" pages (the 404 page in particular).
*
* (C) 2011, Nodejitsu Inc.
*
*/
var docs = require('../docs'),
weld = require('weld').weld,
markdown = require('github-flavored-markdown'),
findit = require('findit'),
fs = require('fs'),
fs2 = require('../fs2'),
path = require('path'),
helpers = require('../helpers'),
buildToc = require('../toc').buildToc;
var errors = exports;
errors.weld = function(dom, errs) {
var $ = docs.window.$, // Shortcut to jquery.
toc = docs.content.toc;
Object.keys(errs).forEach(function(err) {
var data = {
status: errs[err].status,
message: errs[err].message,
toc: toc
};
// Grab the "error" view.
dom.innerHTML = docs.content.theme['./error.html'].toString();
// Weld the data to the dom.
weld(dom, data, {
map: function(parent, element, key, val) {
// Handle welding the table of contents.
if ($(element).attr("id") === "toc") {
element.innerHTML = val;
return false;
}
return true;
}
});
// After welding, pull the html back out of the dom.
errs[err].content = dom.innerHTML;
});
return dom;
};
errors.generate = function(output, errs) {
// Write all the welded error pages to disk.
Object.keys(errs).forEach(function(err){
var newPath = path.normalize("./public/" + errs[err].status + '.html');
fs2.writeFile(newPath, errs[err].content, function(){});
});
return errs;
};
errors.load = function() {
// In this case, I simply return a hash of error pages to be generated, with
// a simple message. There is only one expected error, a 404, and its contents
// are static, so it's simply hard-coded here.
return {
404: {
status: 404,
message: "File not found"
}
};
};