Sha256: b03c70dfb41649f085124bae3f196920afff47cd11fb19cca9ce90a3092956f6
Contents?: true
Size: 1.09 KB
Versions: 3
Compression:
Stored size: 1.09 KB
Contents
JsUnitTest.Template = function(template, pattern) { this.template = template; //template.toString(); this.pattern = pattern || JsUnitTest.Template.Pattern; }; JsUnitTest.Template.prototype.evaluate = function(object) { if (typeof object.toTemplateReplacements == "function") object = object.toTemplateReplacements(); return JsUnitTest.gsub(this.template, this.pattern, function(match) { if (object == null) return ''; var before = match[1] || ''; if (before == '\\') return match[2]; var ctx = object, expr = match[3]; var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; match = pattern.exec(expr); if (match == null) return before; while (match != null) { var comp = (match[1].indexOf('[]') === 0) ? match[2].gsub('\\\\]', ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); match = pattern.exec(expr); } return before + JsUnitTest.String.interpret(ctx); }); } JsUnitTest.Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
newjs-1.7.0 | vendor/jsunittest/src/prototype/template.js |
newjs-1.7.1 | vendor/jsunittest/src/prototype/template.js |
newjs-1.7.2 | vendor/jsunittest/src/prototype/template.js |