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
|
Handlebars.registerHelper('groupChanged', function (context, nodeGroup, options) {
const group = nodeGroup || ''
if (context.group !== group) {
// reset the nesting context for the #nestingChanged block helper
delete context.nestedContext
context.group = group
return options.fn(this)
}
})
Handlebars.registerHelper('nestingChanged', function (context, node, options) {
// context.nestedContext is also reset each time a new group
// is encountered (the value is reset within the #groupChanged
// block helper)
if (node.nested_context && node.nested_context !== context.nestedContext) {
context.nestedContext = node.nested_context
if (context.lastModuleSeenInGroup !== node.nested_context) {
return options.fn(this)
}
} else {
// track the most recently seen module
// prevents emitting a duplicate entry for nesting when
// the nesting prefix matches an existing module
context.lastModuleSeenInGroup = node.title
}
})
Handlebars.registerHelper('showSections', function (node, options) {
if (node.sections.length > 0) {
return options.fn(this)
}
})
Handlebars.registerHelper('showSummary', function (node, options) {
if (node.nodeGroups) {
return options.fn(this)
}
})
Handlebars.registerHelper('isArray', function (entry, options) {
if (Array.isArray(entry)) {
return options.fn(this)
} else {
return options.inverse(this)
}
})
Handlebars.registerHelper('isNonEmptyArray', function (entry, options) {
if (Array.isArray(entry) && entry.length > 0) {
return options.fn(this)
} else {
return options.inverse(this)
}
})
Handlebars.registerHelper('isEmptyArray', function (entry, options) {
if (Array.isArray(entry) && entry.length === 0) {
return options.fn(this)
} else {
return options.inverse(this)
}
})
Handlebars.registerHelper('isLocal', function (nodeId, options) {
const pathSuffix = window.location.pathname.split('/').pop()
if (pathSuffix === nodeId + '.html' || pathSuffix === nodeId) {
return options.fn(this)
} else {
return options.inverse(this)
}
})
|