Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created July 19, 2011 15:30
Show Gist options
  • Save ibolmo/1092786 to your computer and use it in GitHub Desktop.
Save ibolmo/1092786 to your computer and use it in GitHub Desktop.
Add support for paths in String.substitute
/*
---
name: String.substitute
description: Replaces Core/String.substitute with an augmented version that supports More/Object.Extras's getFromPath.
requires: [Core/String, More/Object.Extras]
provides: [String.substitute]
...
*/
String.implement({
substitute: function(object, regexp){
return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
if (match.charAt(0) == '\\') return match.slice(1);
return Object.getFromPath(object, name) || '';
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment