Skip to content

Commit

Permalink
full revert re: #432
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin committed Aug 26, 2016
1 parent 1ef9eb5 commit 999c834
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
45 changes: 22 additions & 23 deletions dist/jsoneditor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jsoneditor.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/jsoneditor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jsoneditor.min.js.map

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions src/templates/default.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
JSONEditor.defaults.templates["default"] = function() {
function resolve(ref, context) {
var dot = ref.indexOf('.');
if (dot === -1)
return context[ref];
var predot = ref.slice(0, dot);
if (!predot)
return null;

if (context[predot] === undefined)
return null;

return resolve(ref.slice(dot + 1), context[predot]);
}
var expandVars = function(vars) {
var expanded = {};
$each(vars, function(i,el) {
if(typeof el === "object" && el !== null) {
var tmp = {};
$each(el, function(j,item) {
tmp[i+'.'+j] = item;
});
$extend(expanded,expandVars(tmp));
}
else {
expanded[i] = el;
}
});
return expanded;
};

return {
compile: function(template) {
return function (vars) {
var expanded = expandVars(vars);

var ret = template+"";
var re = /{{\s*([a-zA-Z0-9_.\-]+)\s*}}/g;
var m = re.exec(ret);
while (m) {
var t = resolve(m[1], vars);
if (t) {
ret = ret.replace(m[0], t);
re.lastIndex += (t.length - m[0].length); // handle short substitutions
}
m = re.exec(ret);
}
// Only supports basic {{var}} macro replacement
$each(expanded,function(key,value) {
ret = ret.replace(new RegExp('{{\\s*'+key+'\\s*}}','g'),value);
});
return ret;
};
}
Expand Down

0 comments on commit 999c834

Please sign in to comment.