Browse Source

Used dynamic values instead of hard-coded in ContentParser

pull/13082/head
malik masis 4 years ago
parent
commit
a07eaf4c45
  1. 31
      modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs
  2. 14
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml

31
modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs

@ -21,18 +21,11 @@ public class ContentParser : ITransientDependency
public async Task<List<ContentFragment>> ParseAsync(string content) public async Task<List<ContentFragment>> ParseAsync(string content)
{ {
return new List<ContentFragment> {
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()) if (!_options.WidgetConfigs.Any())
{ {
return new List<ContentFragment>() return new List<ContentFragment>
{ {
new MarkdownContentFragment() { Content = content } new ContentFragment() { Type = "Markdown" }.SetProperty("Content", content),
}; };
} }
@ -87,31 +80,31 @@ public class ContentParser : ITransientDependency
if (parsedWidgets.Count > k) 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) if (name is not null && parsedWidgets.Count > k)
{ {
var properties = new Dictionary<string, object>(); values[0] = name;
var contentFragment = new ContentFragment() { Type = "Widget" };
contentFragments.Add(contentFragment);
for (int kv = 0; kv < values.Count; kv++) 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++; k++;
} }
else else
{ {
contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); contentFragments.Add(new ContentFragment() { Type = "Markdown" }
.SetProperty("Content", parsedList[i]));
} }
} }
return contentFragments; return contentFragments;
*/
} }
private void ParseWidgets(string content, Dictionary<string, List<KeyValuePair<string, string>>> parsedWidgets) private void ParseWidgets(string content, Dictionary<string, List<KeyValuePair<string, string>>> parsedWidgets)

14
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<string>("Content"))) @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content")))
} }
else if (contentFragment.Type == "Widget") //TODO: Constant else if (contentFragment.Type == "Widget") //TODO: Constant
{ {
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), new @await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), new
{ {
extraProperties = contentFragment.ExtraProperties extraProperties = contentFragment.ExtraProperties
} }
) )
}
} }
}
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>

Loading…
Cancel
Save