From 97c1819dc4c9c3063ea0602328c90abafab5e9fa Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 6 May 2013 22:06:01 +0000 Subject: [PATCH] forgot to commit category files --- public/templates/category.tpl | 15 ++++++++ src/categories.js | 72 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 public/templates/category.tpl create mode 100644 src/categories.js diff --git a/public/templates/category.tpl b/public/templates/category.tpl new file mode 100644 index 0000000000..4fb3c46bc8 --- /dev/null +++ b/public/templates/category.tpl @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/src/categories.js b/src/categories.js new file mode 100644 index 0000000000..830bdae6a4 --- /dev/null +++ b/src/categories.js @@ -0,0 +1,72 @@ +var RDB = require('./redis.js'), + posts = require('./posts.js'), + utils = require('./utils.js'), + user = require('./user.js'); + +(function(Categories) { + + + // An admin-only function. Seeing how we have no control panel yet ima leave this right here. sit pretty, you + Categories.create = function(data, callback) { + RDB.incr('global:next_category_id', function(cid) { + var slug = cid + '/' + utils.slugify(data.name); + RDB.rpush('categories:cid', cid); + + // Topic Info + RDB.set('cid:' + cid + ':name', data.name); + RDB.set('cid:' + cid + ':description', data.description); + RDB.set('cid:' + cid + ':slug', slug); + + RDB.set('category:slug:' + slug + ':cid', cid); + + if (callback) callback({'status': 1}); + }); + }; + + + + Categories.get = function(callback) { + RDB.lrange('categories:cid', 0, -1, function(cids) { + var name = [], + description = [], + slug = []; + + for (var i=0, ii=cids.length; i 0) { + RDB.multi() + .mget(name) + .mget(description) + .mget(slug) + .exec(function(err, replies) { + name = replies[0]; + description = replies[1]; + slug = replies[2]; + + var categories = []; + for (var i=0, ii=cids.length; i