Last active
December 21, 2015 03:09
-
-
Save stayradiated/6239816 to your computer and use it in GitHub Desktop.
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
# Super simple templating engine | |
tmpl = (template, namespace) -> | |
fn = (existing, fieldName) -> | |
content = namespace[fieldName] | |
content ?= existing | |
return content | |
template.replace(/\{\{([a-z0-9_]*)\}\}/ig, fn) | |
### | |
template = "Hello {{name}}!" | |
namespace = { | |
name: "world" | |
} | |
templ(template, namespace) | |
=> "Hello world!" | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment