Skip to content

Commit

Permalink
basic language + search API
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Sep 20, 2012
1 parent 2f115e0 commit bde71a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions routes/home.js
Expand Up @@ -95,7 +95,22 @@ exports.lang = function (req, res, next) {
.find({ 'language': lang, fork: false }, { skip: skip, limit: pageSize, sort: { followers: -1 }})
.toArray(function (err, projects) {
if (err) return next(err);
res.render('index', { langs: langs, projects: projects || [], lang: encodeURIComponent(String(lang)), page: page });

var locals = {
langs: langs
, projects: projects || []
, lang: lang
, page: page
};

res.format({
html: function () {
res.render('index', locals);
}
, json: function () {
res.send(locals);
}
})
});
}

Expand Down Expand Up @@ -138,6 +153,13 @@ exports.search = function (req, res, next) {
, lang: ''
};

res.render('index', locals);
res.format({
html: function () {
res.render('index', locals);
}
, json: function () {
res.send(locals);
}
})
});
}
1 change: 1 addition & 0 deletions views/index.jade
Expand Up @@ -48,6 +48,7 @@ html
li(class= projects.length < 20 ? 'disabled' : '')
a(href="/search?term=#{term}&page=#{page+1}") Next
else
- lang = encodeURIComponent(lang || '');
li(class= 0 === page ? 'disabled' : '')
a(href="/language/#{lang}?page=#{page > 0 ? page-1 : page}") Previous
li(class= projects.length < 20 ? 'disabled' : '')
Expand Down

0 comments on commit bde71a8

Please sign in to comment.