Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
handlebartender
Advanced tools
Readme
Allows you to render Handlebar templates anywhere in your backend logic.
npm i handlebartender
//require handlebartender
var HBT = require('handlebartender');
//tell handlebartender where the templates are to compile
var templates = HBT.compile({
templatePath: __dirname + '/some/template/path/'
});
//you now have two ways to render your templates with data
var myData = { title: 'Hey!'}
//You should omit the extension name
templates.render('templateName', myData);
//the above is the equivalent to
templates['templateName'](myData);
By default handlebartender will look in your templatePath under the subdirectory 'partials'. For this reason avoid storing templates that are not intended to be partials in this directory. You also have the option to pass your partialsPath to the compile method if you decide to store them somewhere else.
var templates = HBT.compile({
templatePath: __dirname + '/some/template/path/',
partialsPath: __dirname + '/another/path/'
});
You can also register a partial the old fashioned way by accessing the handlebartenders internal Handlebars instance. If you choose to do this, make sure you do it BEFORE you compile templates, otherwise the partial will not be available for use in your templates and you will error out.
var HBT = require('handlebartender');
HBT.Handlebars.registerPartial('header', '<h2>{{title}}</h2>');
Adding helpers to handlebartenders is also simple. You can pass a key value pair of a helper name and function as the 'helper' option to the compile method. For example:
//make a helper we can use
var jsonHelper = function(context) {
return JSON.stringify(context);
};
var templates = HBT.compile({
templatePath: __dirname + '/some/template/path/',
helpers: {
json: jsonHelper
}
});
As with partials, you can register a helper with handlebartenders internal Handlebars instance as well. When registering a partial via the built in Handlebars instance, you need to do this before compiling templates otherwise you will get an error when using it.
HBT.Handlebars.registerHelper('link', function(text, url) {
text = HBT.Handlebars.Utils.escapeExpression(text);
url = HBT.Handlebars.Utils.escapeExpression(url);
var result = '<a href="' + url + '">' + text + '</a>';
return new HBT.Handlebars.SafeString(result);
});
partialsPath - defaults to templatePath + '/partials'
helpers - defaults to {}
extension - defaults to .hbs
npm test
There aren't a ton of tests right. But any contributions on this front are welcome.
I have created a 0.0.8x branch for anyone interested in the old usage (https://github.com/battlejj/handlebartender/tree/v0.0.8), however, I will not be supporting it.
FAQs
Allows you to render Handlebar templates anywhere in your backend logic.
The npm package handlebartender receives a total of 1 weekly downloads. As such, handlebartender popularity was classified as not popular.
We found that handlebartender demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.