/// <inheritdoc /> public override async Task <IEnumerable <DocumentItemExecution> > Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData) { var index = 0; while (ContinueBuilding(outputStream, context)) { var collectionContext = new ContextCollection(index++, false, context.Options, context.Key, context.Parent) { Value = context.Value }; //TODO get a way how to execute this on the caller await MorestachioDocument.ProcessItemsAndChildren(Children, outputStream, collectionContext, scopeData); if (!await(await MorestachioExpression.GetValue(collectionContext, scopeData)).Exists()) { break; } } return(new DocumentItemExecution[0]); }
/// <summary> /// Compiles all <see cref="IDocumentItem"/> and their children. If the <see cref="IDocumentItem"/> supports the <see cref="ISupportCustomAsyncCompilation"/> it is used otherwise /// the items <see cref="IDocumentItem.Render"/> method is wrapped /// </summary> /// <param name="documentItems"></param> /// <returns></returns> public CompilationAsync CompileItemsAndChildren(IEnumerable <IDocumentItem> documentItems) { var docs = documentItems.ToArray(); var actions = new Delegate[docs.Length]; for (var index = 0; index < docs.Length; index++) { var documentItem = docs[index]; var document = documentItem; if (document is ISupportCustomAsyncCompilation customAsyncCompilation) { actions[index] = (customAsyncCompilation.Compile(this)); } else if (document is ISupportCustomCompilation customCompilation) { actions[index] = (customCompilation.Compile(this)); } else { actions[index] = new CompilationAsync((async(outputStream, context, scopeData) => { var children = await document.Render(outputStream, context, scopeData); foreach (var documentItemExecution in children) { await MorestachioDocument.ProcessItemsAndChildren(new[] { documentItemExecution.DocumentItem }, outputStream, documentItemExecution.ContextObject, scopeData); } })); } } return(async(stream, context, data) => { if (!data.IsOutputLimited) { for (int i = 0; i < docs.Length; i++) { var action = actions[i]; if (action is CompilationAsync ca) { await ca(stream, context, data); } else if (action is Compilation c) { c(stream, context, data); } } } else { for (int i = 0; i < docs.Length; i++) { if (!DocumentItemBase.ContinueBuilding(stream, data)) { return; } var action = actions[i]; if (action is CompilationAsync ca) { await ca(stream, context, data); } else if (action is Compilation c) { c(stream, context, data); } } } }); }