Пример #1
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LiquidPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                try
                {
                    var model = new LiquidPartViewModel()
                    {
                        LiquidPart = part,
                        ContentItem = part.ContentItem
                    };

                    var result = await _liquidTemplateManager.RenderHtmlContentAsync(part.Liquid, _htmlEncoder, model,
                                                                                     new Dictionary <string, FluidValue>()
                    {
                        ["ContentItem"] = new ObjectValue(model.ContentItem)
                    });

                    bodyAspect.Body = result;
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LiquidPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                if (_bodyAspect != null)
                {
                    bodyAspect.Body = _bodyAspect;
                    return;
                }

                try
                {
                    var model = new LiquidPartViewModel()
                    {
                        LiquidPart = part,
                        ContentItem = part.ContentItem
                    };

                    var templateContext = new TemplateContext();
                    templateContext.SetValue("ContentItem", part.ContentItem);
                    templateContext.MemberAccessStrategy.Register <LiquidPartViewModel>();
                    templateContext.SetValue("Model", model);

                    var result = await _liquidTemplateManager.RenderAsync(part.Liquid, _htmlEncoder, templateContext);
                    bodyAspect.Body = _bodyAspect = new HtmlString(result);
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
Пример #3
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LiquidPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                if (_bodyAspect != null)
                {
                    bodyAspect.Body = _bodyAspect;
                    return;
                }

                try
                {
                    var model = new LiquidPartViewModel()
                    {
                        LiquidPart = part,
                        ContentItem = part.ContentItem
                    };

                    var result = await _liquidTemplateManager.RenderAsync(part.Liquid, _htmlEncoder, model,
                                                                          scope => scope.SetValue("ContentItem", model.ContentItem));

                    bodyAspect.Body = _bodyAspect = new HtmlString(result);
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
Пример #4
0
        public override async Task <IDisplayResult> UpdateAsync(LiquidPart model, IUpdateModel updater)
        {
            var viewModel = new LiquidPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Liquid))
            {
                if (!string.IsNullOrEmpty(viewModel.Liquid) && !_liquidTemplatemanager.Validate(viewModel.Liquid, out var errors))
                {
                    updater.ModelState.AddModelError(Prefix, nameof(viewModel.Liquid), S["The Liquid Body doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]);
                }
                else
                {
                    model.Liquid = viewModel.Liquid;
                }
            }

            return(Edit(model));
        }
Пример #5
0
 private void BuildViewModel(LiquidPartViewModel model, LiquidPart liquidPart)
 {
     model.Liquid      = liquidPart.Liquid;
     model.LiquidPart  = liquidPart;
     model.ContentItem = liquidPart.ContentItem;
 }
Пример #6
0
 private void BuildViewModel(LiquidPartViewModel model, LiquidPart liquidPart)
 {
     model.Liquid     = liquidPart.Liquid;
     model.LiquidPart = liquidPart;
 }