mootools/mootools-more — pull request #1063 by DimitarChristoff (2011-11-03 09:15:37+00:00)
Title: String.Extras - .substitutePath

Hi chaps,

Just a little something that started off as an idea from Oskar and then got tweaked and finalised yesterday through work put in by myself, Daniel (csuwildcat) and Thiery Bela (who is using now in his template system plugin).

Basically, it's an extension of the `.substitute method` in core that works in a similar way but with an object path.

eg.

var result = "this user has {userDetails.posts.count} messages and has been a member since {userDetails.memberSince}".substitutePath({
userDetails: {
memberSince: "last Friday",
posts: {
count: 3
}
}
});

console.log(result); // this user has 3 messages and has been a member since last Friday

It affords pseudo-templating from objects that are not flat w/o having to combine/flatten/dereference them beforehand, which is probably cheaper and also more convenient.

It is backwards compatible with `.substitute` with simple objects as well.