forked from helpers/handlebars-helper-isActive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 800 Bytes
/
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
/**
* Handlebars Helpers: {{isActive}}
* Copyright (c) 2013 Jon Schlinkert
* Licensed under the MIT License (MIT).
*/
// Node.js
var _ = require('lodash');
// Export helpers
module.exports.register = function (Handlebars, options) {
'use strict';
var opts = options;
/**
* Add `active` class for current page.
* Customize the class in the options hash.
* @xample: {{isActive class="current"}}
*
* @usage: {{isActive}}
*/
Handlebars.registerHelper('isActive', function(context) {
context = _.extend(context, opts.data, this);
context.hash.class = context.hash.class || 'active';
var active = '';
if(context.isCurrentPage === true) {
active = ' class="' + context.hash.class + '"';
}
return new Handlebars.SafeString(active);
});
};