Skip to content
Browse files

Fetching posts by tag now handled in view `couchpress/tag`, added `co…

…uchpress/tag` view to install script
  • Loading branch information...
1 parent 78eb176 commit e43d604264eedd09461d1a62cc7f2d5087293cc5 @jhbertram jhbertram committed with alejandro May 14, 2012
Showing with 15 additions and 6 deletions.
  1. +3 −5 controllers/posts.coffee
  2. +12 −1 setup/install.js
View
8 controllers/posts.coffee
@@ -31,16 +31,14 @@ class Post
callback null, res
findByTag: (tag, callback) ->
- @db.view 'couchpress/all', {descending: true}, (err, res) ->
+ @db.view 'couchpress/tag', {key: tag, descending: true}, (err, res) ->
if (err)
callback(err)
else
docs = []
- # find posts with a certain tag
res.forEach (row) ->
- if (row.tags && row.tags.indexOf(tag) != -1)
- row.created_at = moment(row.created_at).fromNow()
- docs.push row
+ row.created_at = moment(row.created_at).fromNow()
+ docs.push row
callback(null, docs)
save: (article, callback) ->
View
13 setup/install.js
@@ -215,8 +215,19 @@ function installViews(data,cb){
all: {
map: 'function(doc) {\n if (doc.type !== \'upload\')\n emit(doc.created_at, doc);\n}\n'
},
+ tag: {
+ map: function(doc) {
+ for (tag in doc.tags) {
+ emit(doc.tags[tag], doc)
+ }
+ }
+ },
uploads_all: {
- map: 'function(doc) {\n if (doc.type === \'upload\')\n emit(doc.created_at, doc);\n}'
+ map: function(doc) {
+ if (doc.type === 'upload') {
+ emit(doc.created_at, doc);
+ }
+ }
}
}
}, function(error,res){

0 comments on commit e43d604

Please sign in to comment.
Something went wrong with that request. Please try again.