Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Created November 3, 2011 01:27
Show Gist options
  • Save nijikokun/1335511 to your computer and use it in GitHub Desktop.
Save nijikokun/1335511 to your computer and use it in GitHub Desktop.
<= (chars 140) Javascript
// t (in CoffeeScript)
//
// Description: Quick Templating, optional customizing open/closing tags
//
// Author: Nijikokun <[email protected]>
//
// Usage:
//
// t('Hello {name}!', { name: 'World' });
//
t = (s,o,p = '{',e = '}') ->
for own i of o
s = s.replace(new RegExp(p+i+e,'g'),o[i])
return s
// t
//
// Description: Quick Templating, optional customizing open/closing tags
//
// Author: Nijikokun <[email protected]>
//
// Usage:
//
// t('Hello {name}!', { name: 'World' });
//
function t(s,o,p,e){p=p?p:'{';e=e?e:'}';for(var i in o)o.hasOwnProperty(i)&&(s=s.replace(new RegExp(p+i+e,'g'),o[i]));return s;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment