Swapping out `range` for underscore version

This commit is contained in:
Andrew Hayward 2013-04-18 17:32:27 +01:00
Родитель 237a8c27cc
Коммит 975c205fda
1 изменённых файлов: 2 добавлений и 21 удалений

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();
})