зеркало из https://github.com/mozilla/CSOL-site.git
Swapping out `range` for underscore version
This commit is contained in:
Родитель
237a8c27cc
Коммит
975c205fda
23
app.js
23
app.js
|
@ -5,6 +5,7 @@ const http = require('http');
|
|||
const express = require('express');
|
||||
const app = express();
|
||||
const nunjucks = require('nunjucks');
|
||||
const _ = require('underscore');
|
||||
|
||||
const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(path.join(__dirname, 'views')));
|
||||
env.express(app);
|
||||
|
@ -28,27 +29,7 @@ app.use(function(req, res, next) {
|
|||
app.use(function(req, res, next) {
|
||||
// This should be in Nunjucks, but right now it's not
|
||||
// https://github.com/jlongster/nunjucks/issues/72
|
||||
res.locals.range = function(start, stop, step) {
|
||||
if (!step) step = 1;
|
||||
if (!stop) {
|
||||
stop = start;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
var arr = [start];
|
||||
|
||||
if (start > stop) {
|
||||
while (start - step > stop) {
|
||||
arr.push(start -= step);
|
||||
}
|
||||
} else {
|
||||
while (start + step < stop) {
|
||||
arr.push(start += step);
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
res.locals.range = _.range;
|
||||
next();
|
||||
})
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче