Skip to content

Commit b02728a

Browse files
committed
ch5-6: corrected regressions (missing 'section' Handlebars helper).
1 parent ce7c33d commit b02728a

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

ch05/meadowlark.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ var fortune = require('./lib/fortune.js');
44
var app = express();
55

66
// set up handlebars view engine
7-
var handlebars = require('express3-handlebars')
8-
.create({ defaultLayout:'main' });
7+
var handlebars = require('express3-handlebars').create({
8+
defaultLayout:'main',
9+
helpers: {
10+
section: function(name, options){
11+
if(!this._sections) this._sections = {};
12+
this._sections[name] = options.fn(this);
13+
return null;
14+
}
15+
}
16+
});
917
app.engine('handlebars', handlebars.engine);
1018
app.set('view engine', 'handlebars');
1119

ch05/views/layouts/main.handlebars

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
{{#if showTests}}
66
<link rel="stylesheet" href="/vendor/mocha.css">
77
{{/if}}
8-
<script src="//code.jquery.com/jquery-2.0.2.min.js"></script>
98
</head>
109
<body>
1110
<header><img src="/img/logo.png" alt="Meadowlark Travel Logo"></header>
1211
{{{body}}}
12+
13+
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
14+
<script>window.jQuery || document.write('<script src="/vendor/js/jquery-2.1.1.min.js"><\/script>')</script>
15+
{{{_sections.jquery}}}
16+
1317
{{#if showTests}}
1418
<div id="mocha"></div>
1519
<script src="/vendor/mocha.js"></script>

ch06/meadowlark.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ var fortune = require('./lib/fortune.js');
44
var app = express();
55

66
// set up handlebars view engine
7-
var handlebars = require('express3-handlebars')
8-
.create({ defaultLayout:'main' });
7+
var handlebars = require('express3-handlebars').create({
8+
defaultLayout:'main',
9+
helpers: {
10+
section: function(name, options){
11+
if(!this._sections) this._sections = {};
12+
this._sections[name] = options.fn(this);
13+
return null;
14+
}
15+
}
16+
});
917
app.engine('handlebars', handlebars.engine);
1018
app.set('view engine', 'handlebars');
1119

ch06/views/layouts/main.handlebars

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<body>
1111
<header><img src="/img/logo.png" alt="Meadowlark Travel Logo"></header>
1212
{{{body}}}
13+
14+
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
15+
<script>window.jQuery || document.write('<script src="/vendor/js/jquery-2.1.1.min.js"><\/script>')</script>
16+
{{{_sections.jquery}}}
17+
1318
{{#if showTests}}
1419
<div id="mocha"></div>
1520
<script src="/vendor/mocha.js"></script>

0 commit comments

Comments
 (0)