JSFiddle - React, Tailwind, and code Playground
by Daedalus
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.js"></script>
JavaScript
class TextFormatter {
constructor(colors) {
this.colors = colors;
}
register() {
Handlebars.registerHelper('color', this.color);
Handlebars.registerHelper('c', this.color);
}
color(colorName, text) {
let color = this.colors[colorName] || '';
return `${color}${text}`;
}
}
let tf = new TextFormatter({
action: 'blue'
});
let template = Handlebars.compile('{{color text}}');
console.log('test', template({
text: 'action'
}));