Skip to content

Instantly share code, notes, and snippets.

@suside
Created June 6, 2016 10:46
Show Gist options
  • Save suside/9a053cf63f6f02df3316009d9831fcf7 to your computer and use it in GitHub Desktop.
Save suside/9a053cf63f6f02df3316009d9831fcf7 to your computer and use it in GitHub Desktop.
One line RamdaJS template 'engine'
const R = require('ramda');
const _ = R.curry((tpl, data) => R.reduce((ac, k) => R.replace(`{{${k}}}`, data[k], ac), tpl, R.keys(data)));
_('Hello {{var}}', {var: 'world'}); // => Hello world
const compiled = _('{{var1}} {{var2}}');
compiled({var1: 'Hello', var2: 'world'}); // => Hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment