Skip to content
Myr

Removed "reload views" setting and support code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

development env will always bypass cache, however production will not

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent d0fe19f · Browse files · 5 files+3 added−86 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+3 added−86 removed

  • other:+3 added−86 removed

5 files+3 added−86 removed

modified:bin/express-1 removed
83 unmodified lines
84 ' app.use(connect.staticProvider(__dirname + \'/public\'));',85 '});',86 '',87 'app.configure(\'development\', function(){',88 ' app.set(\'reload views\', 500);',88 ' app.use(connect.errorHandler({ dumpExceptions: true, showStack: true })); ',89 '});',90 '',91 'app.configure(\'production\', function(){',
93 unmodified lines
modified:docs/guide.md+3 added-5 removed
81 unmodified lines
82 * _env_ Application environment set internally, use _app.set('env')_ on _Server#listen()_83 * _home_ Application base path used for _res.redirect()_ and transparently handling mounted apps.84 * _views_ Root views directory defaulting to **CWD/views**85 * _view engine_ Default view engine name for views rendered without extensions86 * _reload views_ Reloads altered views, by default watches for _mtime_ changes with87 with a 500 millisecond interval.8687### Routing8889Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.
429 unmodified lines
519520Apply an application level setting _name_ to _val_, or521get the value of _name_ when _val_ is not present:522525 app.set('reload views', 200);526 app.set('reload views');527 // => 200523 app.set('views', __dirname + '/views');524 app.set('views');525 // => ...path...526527### app.enable(name)528529Enable the given setting _name_:
128 unmodified lines
modified:examples/jade/app.js-8 removed
modified:lib/express/server.js-16 removed
70 unmodified lines
7172sys.inherits(Server, connect.Server);7374/**75 * Start listening on the given `port` / `host`.76 *77 * @param {Number} port78 * @param {String} host79 * @api public80 */8182Server.prototype.listen = function(port, host){83 // Setup view reloading84 if (this.set('reload views')) {85 view.watcher.call(this, this.set('reload views'));86 }87 connect.Server.prototype.listen.call(this, port, host);88};8990/**75 * Proxy `connect.Server#use()` to apply settings to76 * mounted applications.77 *78 * @param {String|Function|Server} route
182 unmodified lines
modified:lib/express/view.js-56 removed
43 unmodified lines
44 viewCache = {};45};4647/**48 * Cache view at the given `path`.49 *50 * @param {String} path51 * @return {String}52 * @api private53 */5455function cacheView(path) {56 fs.readFile(path, 'utf8', function(err, data){57 if (!err) {58 viewCache[path] = data;59 }60 });61}6263/**48 * Synchronously cache view at the given `path`.49 *50 * @param {String} path51 * @return {String}
16 unmodified lines
68 return app.set('views') || process.cwd() + '/views';69}7071/**88 * Setup view reloading, checking at the given `interval`89 * which defaults to 500 milliseconds.90 *91 * @param {Numbers} interval92 * @api private93 */9495exports.watcher = function(interval){96 interval = interval === true97 ? 50098 : interval;99100 function watch(file) {101 fs.watchFile(file, { interval: interval }, function(curr, prev){102 if (curr.mtime > prev.mtime) {103 cacheView(file);104 }105 });106 }107108 (function traverse(dir){109 fs.readdir(dir, function(err, files){110 if (err) return;111 files.forEach(function(file){112 file = dir + '/' + file;113 fs.stat(file, function(err, stats){114 if (err) {115 return;116 } else if (stats.isFile()) {117 watch(file);118 } else if (stats.isDirectory()) {119 traverse(file);120 }121 });122 });123 });124 })(viewRoot(this));125};126127/**72 * Render `view` partial with the given `options`.73 *74 * Options:75 * - `object` Single object with name derived from the view (unless `as` is present)
189 unmodified lines