-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathviews.pagination.js
94 lines (76 loc) · 2.82 KB
/
views.pagination.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
'use strict';
var fs = require('fs');
var path = require('path');
var glob = require('matched');
var assert = require('assert');
var should = require('should');
var utils = require('../lib/utils');
var once = require('once');
var App = require('..');
var app;
describe('views pagination', function () {
beforeEach(function () {
app = new App();
app.engine('hbs', require('engine-handlebars'));
app.create('page');
app.create('list');
});
describe('.pagination', function () {
it('should render a paginated list from a views collection:', function (done) {
done = once(done);
app.pages('a.hbs', {path: 'a.hbs', content: 'a<%= title %>z', title: 'AAA'});
app.pages('b.hbs', {path: 'b.hbs', content: 'a<%= title %>z', title: 'BBB'});
app.pages('c.hbs', {path: 'c.hbs', content: 'a<%= title %>z', title: 'CCC'});
app.pages('d.hbs', {path: 'd.hbs', content: 'a<%= title %>z', title: 'DDD'});
app.pages('e.hbs', {path: 'e.hbs', content: 'a<%= title %>z', title: 'EEE'});
app.list('list.hbs', {
content: 'BEFORE\n{{#each pagination.items}}{{locals.title}}\n{{/each}}\nAFTER',
locals: {
limit: 2,
permalinks: {
structure: ':collection/:num.html'
}
}
});
var list = app.lists.get('list.hbs');
app.views.pages
.paginate(list, {limit: 2})
.render({}, function (err, res) {
if (err) return done(err);
res.length.should.equal(3);
res.forEach(function (ele) {
ele.content.should.match(/AAA|BBB|CCC|DDD|EEE/);
});
done();
});
});
it('should chain the `.pagination` method from the collection loader method:', function (done) {
done = once(done);
app.pages('a.hbs', {path: 'a.hbs', content: 'a<%= title %>z', title: 'AAA'});
app.pages('b.hbs', {path: 'b.hbs', content: 'a<%= title %>z', title: 'BBB'});
app.pages('c.hbs', {path: 'c.hbs', content: 'a<%= title %>z', title: 'CCC'});
app.pages('d.hbs', {path: 'd.hbs', content: 'a<%= title %>z', title: 'DDD'});
app.pages('e.hbs', {path: 'e.hbs', content: 'a<%= title %>z', title: 'EEE'});
app.list('list.hbs', {
content: 'BEFORE\n{{#each pagination.items}}{{locals.title}}\n{{/each}}\nAFTER',
locals: {
limit: 2,
permalinks: {
structure: ':collection/:num.html'
}
}
});
var list = app.lists.get('list.hbs');
var res = app.pages.paginate(list, {limit: 2});
res.items.length.should.equal(3);
res.render({}, function (err, res) {
if (err) return done(err);
res.length.should.equal(3);
res.forEach(function (ele) {
ele.content.should.match(/AAA|BBB|CCC|DDD|EEE/);
});
done();
});
});
});
});