index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var hbs = require('../../index');
  2. var koa = require('koa');
  3. var router = require('koa-router');
  4. var create = function(opts) {
  5. var app = koa();
  6. var _hbs = hbs.create();
  7. app.on('error', function(err) {
  8. console.error(err.stack);
  9. });
  10. app.use(_hbs.middleware(opts));
  11. app.use(router(app));
  12. app.get('/', function*() {
  13. yield this.render('main', {title: 'test'});
  14. });
  15. app.get('/partials', function*() {
  16. yield this.render('mainWithPartials', {
  17. title: 'test',
  18. anchorList:[
  19. {url: 'https://google.com', name: 'google'},
  20. {url: 'https://github.com', name: 'github'}
  21. ]
  22. });
  23. });
  24. app.get('/nestedPartials', function*() {
  25. yield this.render('nestedPartials' );
  26. });
  27. app.get('/layout', function *() {
  28. yield this.render('useDefaultLayout');
  29. });
  30. app.get('/altLayout', function *() {
  31. yield this.render('useAlternativeLayout');
  32. });
  33. app.get('/block', function *() {
  34. yield this.render('usesBlockLayout');
  35. });
  36. app.get('/blockNoReplace', function *() {
  37. yield this.render('usesBlockLayoutNoBlock');
  38. });
  39. app.get('/empty', function *() {
  40. yield this.render('empty');
  41. });
  42. app.get('/locals', function *() {
  43. yield this.render('locals');
  44. });
  45. app.get('/localsOverride', function *() {
  46. yield this.render('locals', {
  47. title: 'Bar'
  48. });
  49. });
  50. app.get('/localsRecursive', function *() {
  51. var obj = {};
  52. obj.title = 'Bar';
  53. obj.recursive = obj;
  54. yield this.render('locals', obj);
  55. });
  56. return app;
  57. };
  58. exports.create = create;