diff --git a/lib/ejs.js b/lib/ejs.js index ca304a13..863f1649 100644 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -95,6 +95,27 @@ function rethrow(err, str, filename, lineno){ throw err; } +/** + * parse an object notation string to object entities to retrieve value + * Example: + * var options = { group : [{ name: "The Marx Brothers", members : [{name: "Chico"}, {name : "Harpo"} , {name : "Groucho"}, {name : "Zeppo"}] }] } + * parseObjectNotationString('group[0].members[2]["name"]', options) + * Output: + * Groucho + * + * @param {String} str + * @param {Object} context + * @api private + */ +function parseObjectNotationString(str, context){ + var parts = str.match(/\w+/g), i, ref = context, undef; + for (i=0; i js.lastIndexOf('\n')) js += '\n'; buf += prefix;