Dist Render

This commit is contained in:
nicco 2018-02-21 12:30:59 +01:00
parent fcb136a708
commit cbf94c1fb6
2 changed files with 18 additions and 10 deletions

26
dist/actions.js vendored
View File

@ -84,7 +84,7 @@ exports.variables = (html, options, re) => {
case 'object': case 'object':
return JSON.stringify(output); return JSON.stringify(output);
default: default:
return output; return String(output);
} }
}], }],
length: end + re.ending.length length: end + re.ending.length
@ -102,9 +102,11 @@ exports.loop = (html, options, re) => {
}; };
if (current.found === null || current.found.index !== 0) if (current.found === null || current.found.index !== 0)
throw new Error(options_1.error.parse.default); throw new Error(options_1.error.parse.default);
const statement = current.found[0].slice(re.begin.length + re.if.length, -re.ending.length).trim().split(re.for_in); const statement = current.found[0]
current.variable = statement[0].trim(); .slice(re.begin.length + re.if.length, -re.ending.length).trim()
current.arr = statement[1].trim(); .split(new RegExp(` +${re.for_in} +`, 'g'));
current.variable = statement[0];
current.arr = statement[1];
let next; let next;
do { do {
next = { next = {
@ -115,14 +117,20 @@ exports.loop = (html, options, re) => {
throw new Error(options_1.error.parse.default); throw new Error(options_1.error.parse.default);
} while (next.start !== null && next.start.index < next.end.index); } while (next.start !== null && next.start.index < next.end.index);
html = html.substring(current.found[0].length, next.end.index); html = html.substring(current.found[0].length, next.end.index);
const content = compiler_1.compileBlock(html, options, re);
return { return {
parts: [(data) => { parts: [(data) => {
let ret = ''; const it = util_1.getFromObject(data, current.arr);
for (const variable of util_1.getFromObject(data, current.arr)) { if (!(Symbol.iterator in Object(it)))
const newData = Object.assign({ [current.variable]: variable }, data); return '';
ret += parser_1.computeParts(compiler_1.compileBlock(html, options, re).parts, newData); else {
let ret = '';
for (const variable of it) {
const newData = Object.assign({ [current.variable]: variable }, data);
ret += parser_1.computeParts(content.parts, newData);
}
return ret;
} }
return ret;
}], }],
length: next.end.index + next.end[0].length length: next.end.index + next.end[0].length
}; };

2
dist/options.js vendored
View File

@ -31,5 +31,5 @@ exports.re = {
for: '*', for: '*',
for_in: 'in', for_in: 'in',
closing_tag: '/', closing_tag: '/',
valid_variable: '[A-z](\\w|\\.)*?', valid_variable: '[A-z](\\w|\\.|\\[|\\])*?',
}; };