Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

< 78 cols in view.js so people stop complaining :D

  • Loading branch information...
commit 626d322639b41661b2809da6ffab4a0a7e3e2f76 1 parent 7dce7a8
TJ Holowaychuk tj authored
Showing with 26 additions and 19 deletions.
  1. +26 −19 lib/express/view.js
45 lib/express/view.js
View
@@ -96,26 +96,29 @@ exports.watcher = function(interval){
interval = interval === true
? 500
: interval;
- (function cache(dir){
+
+ function watch(file) {
+ fs.watchFile(file, { interval: interval }, function(curr, prev){
+ if (curr.mtime > prev.mtime) {
+ cacheView(file);
+ }
+ });
+ }
+
+ (function traverse(dir){
fs.readdir(dir, function(err, files){
- if (!err) {
- files.forEach(function(file){
- file = dir + '/' + file;
- fs.stat(file, function(err, stats){
- if (!err) {
- if (stats.isFile()) {
- fs.watchFile(file, { interval: interval }, function(curr, prev){
- if (curr.mtime > prev.mtime) {
- cacheView(file);
- }
- });
- } else if (stats.isDirectory()) {
- cache(file);
- }
- }
- });
+ if (err) return;
+ files.forEach(function(file){
+ file = dir + '/' + file;
+ fs.stat(file, function(err, stats){
+ if (err) return;
+ if (stats.isFile()) {
+ watch(file);
+ } else if (stats.isDirectory()) {
+ traverse(file);
+ }
});
- }
+ });
});
})(viewRoot(this));
};
@@ -262,7 +265,11 @@ http.ServerResponse.prototype.render = function(view, options, fn){
var key = keys[i],
val = dynamicHelpers[key];
if (typeof val === 'function') {
- helpers[key] = val.call(this.app, this.req, this, this.req.params.path);
+ helpers[key] = val.call(
+ this.app,
+ this.req,
+ this,
+ this.req.params.path);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.