Created
March 14, 2016 04:18
-
-
Save kbrgl/02527eb0a073ae440a0c to your computer and use it in GitHub Desktop.
Simplistic node templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const render = function(template, mappings) { | |
for (let mapping in mappings) { | |
template = template.replace(new RegExp(`\\{\\{\\s?${mapping}\\s?\\}\\}`, 'g'), function (capture) { | |
if (typeof mappings[mapping] === 'function') { | |
return mappings[mapping](); | |
} else { | |
return mappings[mapping]; | |
} | |
}); | |
} | |
return template; | |
}; | |
module.exports = { | |
render: render | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment