From a07eaf4c4536b23e37a3692990d27acbec80e1bd Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 14:45:42 +0300 Subject: [PATCH] Used dynamic values instead of hard-coded in ContentParser --- .../Volo/CmsKit/Contents/ContentParser.cs | 31 +++++++------------ .../Shared/Components/Pages/Default.cshtml | 14 ++++----- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index c4da64a986..3b34c66346 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -21,18 +21,11 @@ public class ContentParser : ITransientDependency public async Task> ParseAsync(string content) { - return new List { - new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *a markdown* text."), - new ContentFragment() { Type = "Widget" }.SetProperty("Type", "Poll").SetProperty("Code", "6dhah8dd"), - new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *another markdown* text.") - }; - - /* if (!_options.WidgetConfigs.Any()) { - return new List() + return new List { - new MarkdownContentFragment() { Content = content } + new ContentFragment() { Type = "Markdown" }.SetProperty("Content", content), }; } @@ -87,31 +80,31 @@ public class ContentParser : ITransientDependency if (parsedWidgets.Count > k) { - var name = _options.WidgetConfigs.Where(p => p.Key == values[0]).Select(p => p.Value.Name).FirstOrDefault(); + var widgetType = values[0]; + var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault(); if (name is not null && parsedWidgets.Count > k) { - var properties = new Dictionary(); + values[0] = name; + var contentFragment = new ContentFragment() { Type = "Widget" }; + contentFragments.Add(contentFragment); for (int kv = 0; kv < values.Count; kv++) { - properties.Add(keys[kv], values[kv]); + + contentFragments.FindLast(p=>p == contentFragment) + .SetProperty(keys[kv], values[kv]); } - - contentFragments.Add(new WidgetContentFragment(name) - { - Properties = properties - }); } } k++; } else { - contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); + contentFragments.Add(new ContentFragment() { Type = "Markdown" } + .SetProperty("Content", parsedList[i])); } } return contentFragments; - */ } private void ParseWidgets(string content, Dictionary>> parsedWidgets) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index edb6f1dbec..396628ae66 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -17,13 +17,13 @@ @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } else if (contentFragment.Type == "Widget") //TODO: Constant - { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new - { - extraProperties = contentFragment.ExtraProperties - } - ) - } + { + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new + { + extraProperties = contentFragment.ExtraProperties + } + ) } + }