webmaker.org/routes/gallery.js

51 строка
1.4 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

2015-03-05 22:38:35 +03:00
var make = require('../lib/makeapi').readOnly;
2013-11-06 21:31:28 +04:00
module.exports = function (options) {
return function (req, res, next) {
2015-03-05 22:38:35 +03:00
var DEFAULT_LAYOUT = 'index',
2013-11-06 21:31:28 +04:00
DEFAULT_LIMIT = 12,
layouts = {
index: {
2015-03-05 22:38:35 +03:00
template: 'make-teach.html',
tags: ['webmaker:featured']
2013-11-06 21:31:28 +04:00
}
};
2013-11-06 21:31:28 +04:00
options = options || {};
// layout: Choose a layout - should it look like the home or teach page?
// Sets the processing function and template piece
var layoutName = options.layout || (req.query.layout || DEFAULT_LAYOUT).toString(),
layout = layouts[layoutName] || layouts[DEFAULT_LAYOUT];
layout.name = layoutName;
// page: This is for rendering the view.
var page = options.page || layoutName;
// limit
var limit = options.limit || DEFAULT_LIMIT;
make.setLang(req.localeInfo.momentLang);
make
.find({
tags: {
tags: layout.tags
},
2013-11-06 21:31:28 +04:00
limit: limit,
2015-03-05 22:38:35 +03:00
sortByField: ['createdAt', 'desc']
})
.process(function (err, makes, totalHits) {
2015-03-05 22:38:35 +03:00
res.render(page + '.html', {
makes: makes,
totalHits: totalHits,
limit: limit,
page: page,
layout: layout.name,
template: layout.template,
isAdmin: req.session.user ? req.session.user.isAdmin : false
});
}, req.session.user ? req.session.user.id : '');
};
2013-11-06 21:31:28 +04:00
};