result method
Implementation
StubbleResult result(StubbleContext context) {
final result = StubbleResult();
if (_path.isEmpty) {
result.err = StubbleError(
text: '"EACH" block requires path as parameter',
code: errorPathNotSpecified);
} else {
try {
final data = context.get(_path);
if (data != null) {
if (data is List || data is Map) {
final fn = context.compile(_body);
var res = '';
if (fn != null) {
if (data is List) {
for (final item in data) {
res += fn(item);
}
} else {
data.forEach((key, item) {
res += fn(item);
});
}
}
return StubbleResult(
result: res,
pop: true,
);
} else {
result.err = StubbleError(
text: '"each" block data should have "List" or "Map" type',
code: errorWithDataMalformed,
);
}
} else {
result.err = StubbleError(
text: 'Can\'t get data from context by path "$_path"',
code: errorPathWrongSpecified,
);
}
} catch (e) {
result.err = StubbleError(
text: e.toString(),
code: errorCallingHelper,
);
}
}
return result;
}