Navigation Menu

Skip to content

Commit

Permalink
Fetching posts by tag now handled in view couchpress/tag, added `co…
Browse files Browse the repository at this point in the history
…uchpress/tag` view to install script
  • Loading branch information
jhbertram authored and alejandro committed May 15, 2012
1 parent 78eb176 commit e43d604
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 3 additions & 5 deletions controllers/posts.coffee
Expand Up @@ -31,16 +31,14 @@ class Post
callback null, res callback null, res


findByTag: (tag, callback) -> findByTag: (tag, callback) ->
@db.view 'couchpress/all', {descending: true}, (err, res) -> @db.view 'couchpress/tag', {key: tag, descending: true}, (err, res) ->
if (err) if (err)
callback(err) callback(err)
else else
docs = [] docs = []
# find posts with a certain tag
res.forEach (row) -> res.forEach (row) ->
if (row.tags && row.tags.indexOf(tag) != -1) row.created_at = moment(row.created_at).fromNow()
row.created_at = moment(row.created_at).fromNow() docs.push row
docs.push row
callback(null, docs) callback(null, docs)


save: (article, callback) -> save: (article, callback) ->
Expand Down
13 changes: 12 additions & 1 deletion setup/install.js
Expand Up @@ -215,8 +215,19 @@ function installViews(data,cb){
all: { all: {
map: 'function(doc) {\n if (doc.type !== \'upload\')\n emit(doc.created_at, doc);\n}\n' 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: { 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){ }, function(error,res){
Expand Down

0 comments on commit e43d604

Please sign in to comment.