Skip to content

Instantly share code, notes, and snippets.

@anutron
Created July 22, 2009 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anutron/151722 to your computer and use it in GitHub Desktop.
Save anutron/151722 to your computer and use it in GitHub Desktop.
Hash.implement({
substitute: function(template, regexp){
return template.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
if (match.charAt(0) == '\\') return match.slice(1);
if (this.get(name)) return this.get(name);
if (name.contains(".")) {
var found = this.getFromPath(name);
return found ? found : "";
}
}.bind(this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment