I thought I'd see how Handlebars and Node 6-compatible ES 2015 compare with a few examples.
module.exports = ({ premiumIndicator, premiumLabel }} => {
if (premiumIndicator) {
return `
<div>
${premiumLabel}
</div>
`;
}
};
module.exports = ({ adType }) => {
return require('./ads/top')(adType);
};
const indicators = ({ premiumIndicator }) => {
if (premiumIndicator) {
return `<div>${premiumLabel}</div>`
}
};
module.exports = ({ showIndicators, premiumIndicator }} => {
if (showIndicators) {
return `
<div>Indicators</div>
<ul>
${indicators(premiumIndicator)}
</ul>
`;
}
};
const fs = require('fs');
const Handlebars = require('handlebars');
const template = fs.readFileSync('ad.hbs', 'utf8');
const result = Handlebars.compile(template)({ adType: 'top' });
expect(result).to.be('<section>It does what it says on the tin</section>');
const result = require('ad')({ adType: 'top' });
expect(result).to.be('<section>It does what it says on the tin</section>');
@bjfletcher we can have some fun with symbols and tagged templates to create a template language substitute which gets us much closer to the handlebars code:
Now if we run
tmp
: