/// <inheritdoc/>
        public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
        {
            if (!context.TryGet(PublicationStateContextKey, out PublicationStateToRender stateToRender))
            {
                throw new InvalidOperationException($"The context must contain the '{PublicationStateContextKey}' property");
            }

            if (currentPayload is PublicationWorkflowContentPayload payload)
            {
                ContentState contentState = await this.contentStore.GetContentStateForWorkflowAsync(payload.Slug, WellKnownWorkflowId.ContentPublication).ConfigureAwait(false);

                if (CanRender(contentState, stateToRender))
                {
                    Content content = await this.contentStore.GetContentAsync(contentState.ContentId, contentState.Slug).ConfigureAwait(false);

                    IContentRenderer renderer = this.contentRendererFactory.GetRendererFor(content.ContentPayload);
                    await renderer.RenderAsync(output, content, content.ContentPayload, context).ConfigureAwait(false);
                }
                else
                {
                    // TODO: How are we rendering error/invalid/missing states?
                }
            }
            else
            {
                throw new ArgumentException(nameof(currentPayload));
            }
        }
 /// <inheritdoc/>
 public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
 {
     if (currentPayload is ContentFragmentPayload fragment)
     {
         await output.WriteAsync(fragment.Fragment).ConfigureAwait(false);
     }
     else
     {
         throw new ArgumentException(nameof(currentPayload));
     }
 }
Пример #3
0
        public static ContentPayload ContentPayloadAsCreateContentRequestPayload(IContentPayload payload)
        {
            if (payload == null)
            {
                return(null);
            }

            return(new ContentPayload
            {
                ContentType = payload?.ContentType,
            });
        }
        /// <inheritdoc/>
        public Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
        {
            if (currentPayload is MarkdownPayload markdown)
            {
                Markdown.ToHtml(markdown.Markdown, output, this.pipeline);
            }
            else
            {
                return(Task.FromException(new ArgumentException(nameof(currentPayload))));
            }

            return(Task.CompletedTask);
        }
Пример #5
0
        /// <inheritdoc/>
        public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
        {
            if (currentPayload is LiquidWithMarkdownPayload liquid)
            {
                var    template = Template.Parse(liquid.Template);
                string markdown = await template.RenderAsync(Hash.FromAnonymousObject(new { content = new ContentDrop(parentContent) })).ConfigureAwait(false);

                Markdown.ToHtml(markdown, output, this.pipeline);
            }
            else
            {
                throw new ArgumentException(nameof(currentPayload));
            }
        }
        /// <inheritdoc/>
        public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
        {
            if (currentPayload is LiquidPayload liquid)
            {
                var    template = Template.Parse(liquid.Template);
                string rendered = await template.RenderAsync(Hash.FromAnonymousObject(new { content = new ContentDrop(parentContent) })).ConfigureAwait(false);

                await output.WriteAsync(rendered).ConfigureAwait(false);
            }
            else
            {
                throw new ArgumentException(nameof(currentPayload));
            }
        }
Пример #7
0
 /// <inheritdoc/>
 public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
 {
     if (currentPayload is CompoundPayload compoundPayload)
     {
         foreach (IContentPayload child in compoundPayload.Children)
         {
             IContentRenderer renderer = this.contentRendererFactory.GetRendererFor(child);
             await renderer.RenderAsync(output, parentContent, child, context).ConfigureAwait(false);
         }
     }
     else
     {
         throw new ArgumentException(nameof(currentPayload));
     }
 }
Пример #8
0
        /// <inheritdoc/>
        public async Task RenderAsync(TextWriter output, Content parentContent, IContentPayload currentPayload, PropertyBag context)
        {
            if (!context.TryGet(AbTestIdContextKey, out string abTestId))
            {
                throw new InvalidOperationException($"The context must contain the '{AbTestIdContextKey}' property");
            }

            if (currentPayload is AbTestSetPayload testSet)
            {
                Content content = await testSet.GetContentForAbGroupAsync(abTestId).ConfigureAwait(false);

                IContentRenderer renderer = this.contentRendererFactory.GetRendererFor(content.ContentPayload);
                await renderer.RenderAsync(output, content, content.ContentPayload, context).ConfigureAwait(false);
            }
            else
            {
                throw new ArgumentException(nameof(currentPayload));
            }
        }
 /// <inheritdoc/>
 public IContentRenderer GetRendererFor(IContentPayload contentPayload)
 {
     return(this.serviceProvider.GetRequiredContent <IContentRenderer>(contentPayload.ContentType + RendererSuffix));
 }