diff --git a/lib/pages.js b/lib/pages.js index 71e4722..633a617 100644 --- a/lib/pages.js +++ b/lib/pages.js @@ -5,7 +5,7 @@ var util = require('util'), async = require('async'), hound = require('hound'), redis = require('./pages-connector'), - keyManager = require('./keymanager'), + keyManager = require('./keymanager').KeyManager, ru = require('./reed-util'), FilesystemHelper = require('./filesystem-helper').FilesystemHelper; @@ -43,6 +43,7 @@ function watch() { filename = path.resolve(process.cwd(), filename); redis.insertPage(filename, function(err) { if (err) return pages.emit('error', err); + pages.emit('add', keyManager.toTitle(filename)); }); } }); @@ -52,6 +53,7 @@ function watch() { filename = path.resolve(process.cwd(), filename); redis.updatePage(filename, function(err) { if (err) return pages.emit('error', err); + pages.emit('update', keyManager.toTitle(filename)); }); } }); @@ -61,6 +63,7 @@ function watch() { filename = path.resolve(process.cwd(), filename); redis.removePage(filename, function(err) { if (err) return pages.emit('error', err); + pages.emit('remove', keyManager.toTitle(filename)); }); } }); @@ -153,6 +156,7 @@ pages.get = function(title, callback) { redis.getPage(title, function(err, found, metadata, page) { if (err) return callback(err); + if (found) { callback (null, metadata, page); } @@ -166,9 +170,10 @@ pages.remove = function(title, callback) { if (!open) return queue.push(function() { pages.remove(title, callback); }); - + keyManager.toPagesFilenameFromTitle(title, function(err, filename) { if (err) return callback(err); + redis.removePage(title, function(err) { if (err) return callback(err); diff --git a/test/pages.js b/test/pages.js index b0fb7e1..9eb5a8a 100644 --- a/test/pages.js +++ b/test/pages.js @@ -95,7 +95,9 @@ vows.describe('Pages System').addBatch({ var self = this; fs.writeFile(dir + 'newpage.md', 'This is a new page', function(err) { if (err) return self.callback(err); - reed.pages.get('newpage', self.callback); + reed.pages.on('add', function(title) { + reed.pages.get('newpage', self.callback); + }); }); },