-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathindex.js
103 lines (81 loc) · 2.19 KB
/
index.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
'use strict';
const hbs = require('../../index');
const koa = require('koa');
const router = require('koa-router')();
function create (opts) {
const app = koa();
const _hbs = hbs.create();
app.on('error', (err) => console.error(err.stack));
app.use(_hbs.middleware(opts));
app
.use(router.routes())
.use(router.allowedMethods());
router.get('/', function* () {
yield this.render('main', {title: 'test'});
});
router.get('/partials', function* () {
yield this.render('mainWithPartials', {
title: 'test',
anchorList:[
{url: 'https://google.com', name: 'google'},
{url: 'https://github.com', name: 'github'}
]
});
});
router.get('/nestedPartials', function* () {
yield this.render('nestedPartials' );
});
router.get('/layout', function* () {
yield this.render('useDefaultLayout');
});
router.get('/altLayout', function* () {
yield this.render('useAlternativeLayout');
});
router.get('/overrideLayout', function* () {
yield this.render('useOverrideLayout', {
layout: 'override'
});
});
router.get('/noLayout', function* () {
yield this.render('useNoLayout', {
layout: false
});
});
router.get('/block', function* () {
yield this.render('usesBlockLayout');
});
router.get('/blockNoReplace', function* () {
yield this.render('usesBlockLayoutNoBlock');
});
router.get('/empty', function* () {
yield this.render('empty');
});
router.get('/locals', function* () {
yield this.render('locals');
});
router.get('/localsOverride', function* () {
yield this.render('locals', {
title: 'Bar'
});
});
router.get('/localsRecursive', function* () {
let obj = {};
obj.title = 'Bar';
obj.recursive = obj;
yield this.render('locals', obj);
});
router.get('/localsState', function* () {
this.state = { title: 'Foo', article: 'State' };
yield this.render('locals', {
title: 'Bar'
});
});
router.get('/tplInOtherDir', function* () {
yield this.render('tplInOtherDir');
});
router.get('/missingTemplate', function* () {
yield this.render('missingTemplate');
});
return app;
};
exports.create = create;