forked from OpenUserJS/OpenUserJS.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_template.js
115 lines (88 loc) · 3.12 KB
/
_template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var async = require('async');
var _ = require('underscore');
//--- Models
var Group = require('../models/group').Group;
//--- Local
// Parse a mongoose model and add generated fields (eg: urls, formatted dates)
// Seperate functions for rendering
var modelParser = require('../libs/modelParser');
// Tools for parsing req.query.q and applying it to a mongoose query.
var modelQuery = require('../libs/modelQuery');
// Generate a bootstrap3 pagination widget.
var getDefaultPagination = require('../libs/templateHelpers').getDefaultPagination;
//--- Views
exports.example = function (req, res, next) {
var authedUser = req.session.user;
//
var options = {};
var tasks = [];
// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;
// Metadata
options.title = 'OpenUserJS.org';
options.pageMetaDescription = 'Download Userscripts to enhance your browser.';
var pageMetaKeywords = ['userscript', 'greasemonkey'];
pageMetaKeywords.concat(['web browser']);
options.pageMetaKeywords = pageMetaKeywords.join(', ');
//--- Tasks
// ...
//---
function preRender(){};
function render(){ res.render('pages/_templatePage', options); }
function asyncComplete(){ preRender(); render(); }
async.parallel(tasks, asyncComplete);
};
exports.example = function (req, res, next) {
var authedUser = req.session.user;
//
var options = {};
var tasks = [];
// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;
// Metadata
options.title = 'OpenUserJS.org';
options.pageMetaDescription = 'Download Userscripts to enhance your browser.';
var pageMetaKeywords = ['userscript', 'greasemonkey'];
pageMetaKeywords.concat(['web browser']);
options.pageMetaKeywords = pageMetaKeywords.join(', ');
// Scripts: Query
var scriptListQuery = Script.find();
// Scripts: Query: isLib=false
scriptListQuery.find({isLib: false});
// Scripts: Query: Search
if (req.query.q)
modelQuery.parseScriptSearchQuery(scriptListQuery, req.query.q);
// Scripts: Query: Sort
modelQuery.parseModelListSort(scriptListQuery, req.query.orderBy, req.query.orderDir, function(){
scriptListQuery.sort('-rating -installs -updated');
});
// Pagination
var pagination = getDefaultPagination(req);
pagination.applyToQuery(scriptListQuery);
//--- Tasks
// Pagination
tasks.push(pagination.getCountTask(scriptListQuery));
// Scripts
tasks.push(function (callback) {
scriptListQuery.exec(function(err, scriptDataList){
if (err) {
callback();
} else {
options.scriptList = _.map(scriptDataList, modelParser.parseScript);
callback();
}
});
});
//---
function preRender(){
// Pagination
options.paginationRendered = pagination.renderDefault(req);
};
function render(){ res.render('pages/_templatePage', options); }
function asyncComplete(){ preRender(); render(); }
async.parallel(tasks, asyncComplete);
};