/// <inheritdoc /> protected override async Task <IEnumerable <IDocument> > ExecuteInputAsync(IDocument input, IExecutionContext context) { context.LogDebug( "Processing Handlebars {0} for {1}", string.IsNullOrEmpty(_sourceKey) ? string.Empty : ("in" + _sourceKey), input.ToSafeDisplayString()); string content; if (string.IsNullOrEmpty(_sourceKey)) { content = await input.GetContentStringAsync(); } else if (input.ContainsKey(_sourceKey)) { content = input.GetString(_sourceKey) ?? string.Empty; } else { // Don't do anything if the key doesn't exist return(input.Yield()); } IHandlebars handlebars = HandlebarsDotNet.Handlebars.Create(); // Configure if (_configure != null) { await _configure(context, input, handlebars); } // Register partials foreach ((string name, Config <string> partial) in _partials) { handlebars.RegisterTemplate(name, await partial.GetValueAsync(input, context)); } // Register helpers foreach ((string name, Config <HandlebarsHelper> helper) in _helpers) { handlebars.RegisterHelper(name, await helper.GetValueAsync(input, context)); } // Register block helpers foreach ((string name, Config <HandlebarsBlockHelper> blockHelper) in _blockHelpers) { handlebars.RegisterHelper(name, await blockHelper.GetValueAsync(input, context)); } string result = handlebars.Compile(content)(_model is null ? input.AsDynamic() : await _model.GetValueAsync(input, context)); return(string.IsNullOrEmpty(_sourceKey) ? input.Clone(await context.GetContentProviderAsync(result, MediaTypes.Html)).Yield() : input .Clone(new MetadataItems { { string.IsNullOrEmpty(_destinationKey) ? _sourceKey : _destinationKey, result } }) .Yield()); }