public override Task GetContentItemAspectAsync(ContentItemAspectContext context, FacebookPluginPart part) { return(context.ForAsync <BodyAspect>(async bodyAspect => { if (_bodyAspect != null) { bodyAspect.Body = _bodyAspect; return; } try { var model = new FacebookPluginPartViewModel() { Liquid = part.Liquid, FacebookPluginPart = 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; } })); }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, FacebookPluginPart part) { return(context.ForAsync <BodyAspect>(async bodyAspect => { try { var model = new FacebookPluginPartViewModel() { Liquid = part.Liquid, FacebookPluginPart = 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; } })); }
private void BuildViewModel(FacebookPluginPartViewModel model, FacebookPluginPart part) { if (model == null) { throw new ArgumentNullException(nameof(model)); } model.FacebookPluginPart = part ?? throw new ArgumentNullException(nameof(part)); model.Settings = GetFacebookPluginPartSettings(part); model.Liquid = part.Liquid; model.ContentItem = part.ContentItem; }
public override async Task <IDisplayResult> UpdateAsync(FacebookPluginPart model, IUpdateModel updater) { var viewModel = new FacebookPluginPartViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Liquid); model.Liquid = viewModel.Liquid; await ValidateAsync(model, updater); return(Edit(model)); }
public override async Task <IDisplayResult> UpdateAsync(FacebookPluginPart model, IUpdateModel updater) { var viewModel = new FacebookPluginPartViewModel(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Liquid)) { if (!string.IsNullOrEmpty(viewModel.Liquid) && !_liquidTemplatemanager.Validate(viewModel.Liquid, out var errors)) { updater.ModelState.AddModelError(nameof(model.Liquid), S["The FaceBook Body doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } else { model.Liquid = viewModel.Liquid; } } return(Edit(model)); }