From fad8890047eab7ca5df7e1cb3fe77fe352644cb8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?=
Date: Mon, 30 May 2022 11:57:21 +0300
Subject: [PATCH 01/36] First draft implementation for widgets
---
.../Pages/CmsKitContentWidgetOptions.cs | 8 +++++
.../Components/Pages/ContentFragment.cs | 6 ++++
.../Shared/Components/Pages/ContentParser.cs | 21 +++++++++++
.../Components/Pages/ContentWidgetConfig.cs | 14 ++++++++
.../Shared/Components/Pages/Default.cshtml | 17 +++++++--
.../Pages/DefaultPageViewComponent.cs | 36 ++++++++-----------
.../Shared/Components/Pages/IContentParser.cs | 9 +++++
.../Pages/MarkdownContentFragment.cs | 6 ++++
.../Shared/Components/Pages/PageViewModel.cs | 13 +++++++
.../Components/Pages/WidgetContentFragment.cs | 18 ++++++++++
10 files changed, 124 insertions(+), 24 deletions(-)
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
new file mode 100644
index 0000000000..a4aedbc158
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
@@ -0,0 +1,8 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class CmsKitContentWidgetOptions
+{
+ public Dictionary WidgetConfigs { get; } = new();
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
new file mode 100644
index 0000000000..c5486903dd
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public abstract class ContentFragment
+{
+
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
new file mode 100644
index 0000000000..bfc0828821
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class ContentParser : IContentParser, ITransientDependency
+{
+ public async Task> ParseAsync(string content)
+ {
+ return new List {
+ new MarkdownContentFragment {
+ Content = "**ABP Framework** is completely open source and developed in a community-driven manner."
+ },
+ new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } },
+ new MarkdownContentFragment {
+ Content = "Thanks _for_ *your* feedback."
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
new file mode 100644
index 0000000000..647427b330
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class ContentWidgetConfig
+{
+ public string Name { get; }
+ public Type ViewComponentType { get; set; }
+
+ public ContentWidgetConfig(string name)
+ {
+ Name = name;
+ }
+}
\ No newline at end of file
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 50104515c9..3ca57d6a05 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
@@ -2,6 +2,7 @@
@using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs
+@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@inject IMarkdownToHtmlRenderer MarkdownRenderer
@@ -9,9 +10,19 @@
- @if (!Model.Content.IsNullOrEmpty())
- {
- @Html.Raw(await MarkdownRenderer.RenderAsync(Model.Content))
+ @foreach (var contentFragment in Model.ContentFragments)
+ {
+ if (contentFragment is MarkdownContentFragment markdownContentFragment)
+ {
+ @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
+ }
+ else if(contentFragment is WidgetContentFragment widgetContentFragment)
+ {
+ @await Component.InvokeAsync(widgetContentFragment.Name, new
+ {
+ widgetName = "poll-right"
+ })
+ }
}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
index c5427af114..914001b073 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
@@ -2,8 +2,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
-using Volo.CmsKit.Public.Pages;
-using Volo.CmsKit.Public.Web.Renderers;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
@@ -12,43 +10,39 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
[Widget(
StyleTypes = new[]
{
- typeof(HighlightJsStyleContributor)
+ typeof(HighlightJsStyleContributor)
},
ScriptTypes = new[]
{
- typeof(HighlightJsScriptContributor)
+ typeof(HighlightJsScriptContributor)
},
ScriptFiles = new[]
{
- "/Pages/Public/CmsKit/highlightOnLoad.js"
+ "/Pages/Public/CmsKit/highlightOnLoad.js"
})]
public class DefaultPageViewComponent : AbpViewComponent
{
- protected IPagePublicAppService PagePublicAppService { get; }
+ private readonly IContentParser _contentParser;
- public DefaultPageViewComponent(IPagePublicAppService pagePublicAppService)
+ public DefaultPageViewComponent(IContentParser contentParser)
{
- PagePublicAppService = pagePublicAppService;
+ _contentParser = contentParser;
}
-
- public virtual async Task InvokeAsync(Guid pageId, string title, string content)
+
+ public virtual async Task InvokeAsync(
+ Guid pageId,
+ string title,
+ string content)
{
+ var contentFragments = await _contentParser.ParseAsync(content);
+
var model = new PageViewModel
{
Id = pageId,
Title = title,
- Content = content
+ ContentFragments = contentFragments
};
return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model);
}
-}
-
-public class PageViewModel
-{
- public Guid Id { get; set; }
-
- public string Title { get; set; }
-
- public string Content { get; set; }
-}
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
new file mode 100644
index 0000000000..03e54ea4bb
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public interface IContentParser
+{
+ Task> ParseAsync(string content);
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
new file mode 100644
index 0000000000..361a4b3973
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class MarkdownContentFragment : ContentFragment
+{
+ public string Content { get; set; }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
new file mode 100644
index 0000000000..eae24aeae4
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class PageViewModel
+{
+ public Guid Id { get; set; }
+
+ public string Title { get; set; }
+
+ public List ContentFragments { get; set; }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
new file mode 100644
index 0000000000..125c48a72e
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+
+public class WidgetContentFragment : ContentFragment
+{
+ public string Name { get; }
+
+ public string ViewComponentName { get; set; }
+
+ public Dictionary Properties { get; }
+
+ public WidgetContentFragment(string name)
+ {
+ Name = name;
+ Properties = new Dictionary();
+ }
+}
\ No newline at end of file
From c86db705397afb526eaf1f5f16cd24b37149c8b0 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Thu, 2 Jun 2022 16:46:58 +0300
Subject: [PATCH 02/36] Improved example
---
.../Shared/Components/Pages/ContentParser.cs | 1 +
.../Shared/Components/Pages/Default.cshtml | 19 +++++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index bfc0828821..ebea7cfa7e 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -13,6 +13,7 @@ public class ContentParser : IContentParser, ITransientDependency
Content = "**ABP Framework** is completely open source and developed in a community-driven manner."
},
new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } },
+ new WidgetContentFragment("CmsPollByName") { Properties = { { "name", "poll-name" } } },
new MarkdownContentFragment {
Content = "Thanks _for_ *your* feedback."
}
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 3ca57d6a05..17ac619aa3 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
@@ -16,12 +16,23 @@
{
@Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
}
- else if(contentFragment is WidgetContentFragment widgetContentFragment)
+ else if (contentFragment is WidgetContentFragment widgetContentFragment)
{
- @await Component.InvokeAsync(widgetContentFragment.Name, new
+ //TODO
+ if (widgetContentFragment.Name == "CmsPoll")
{
- widgetName = "poll-right"
- })
+ @await Component.InvokeAsync(widgetContentFragment.Name, new
+ {
+ widgetName = "poll-right"
+ })
+ }
+ else
+ {
+ @await Component.InvokeAsync(widgetContentFragment.Name,new
+ {
+ name = "poll-name"
+ })
+ }
}
}
From 200ec20190c1eb1c1e0be9fa9b7760c9ebe6e0ab Mon Sep 17 00:00:00 2001
From: malik masis
Date: Sat, 4 Jun 2022 18:41:16 +0300
Subject: [PATCH 03/36] Implemented widget options
---
.../Components/Pages/CmsKitContentWidgetOptions.cs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
index a4aedbc158..d782299026 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
@@ -4,5 +4,15 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class CmsKitContentWidgetOptions
{
- public Dictionary WidgetConfigs { get; } = new();
+ public Dictionary WidgetConfigs { get; }
+
+ public CmsKitContentWidgetOptions()
+ {
+ WidgetConfigs = new();
+ }
+
+ public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig)
+ {
+ WidgetConfigs.Add(name, contentWidgetConfig);
+ }
}
\ No newline at end of file
From 6057f2a12d272c6eec13588eb525256139e02337 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Mon, 6 Jun 2022 12:04:16 +0300
Subject: [PATCH 04/36] Converted widget name to the actual vc
---
.../Shared/Components/Pages/ContentParser.cs | 16 ++++++++++++++--
.../Shared/Components/Pages/Default.cshtml | 17 +++--------------
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index ebea7cfa7e..d9156e5a58 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -1,19 +1,31 @@
using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class ContentParser : IContentParser, ITransientDependency
{
+ private readonly CmsKitContentWidgetOptions _options;
+ public ContentParser(IOptions options)
+ {
+ _options = options.Value;
+ }
+
public async Task> ParseAsync(string content)
{
+ var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
return new List {
new MarkdownContentFragment {
Content = "**ABP Framework** is completely open source and developed in a community-driven manner."
},
- new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } },
- new WidgetContentFragment("CmsPollByName") { Properties = { { "name", "poll-name" } } },
+ new WidgetContentFragment(name) {
+ Properties = {
+ { "name", "poll-name" }
+ }
+ },
new MarkdownContentFragment {
Content = "Thanks _for_ *your* feedback."
}
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 17ac619aa3..ece75e5422 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
@@ -18,21 +18,10 @@
}
else if (contentFragment is WidgetContentFragment widgetContentFragment)
{
- //TODO
- if (widgetContentFragment.Name == "CmsPoll")
+ @await Component.InvokeAsync(widgetContentFragment.Name, new
{
- @await Component.InvokeAsync(widgetContentFragment.Name, new
- {
- widgetName = "poll-right"
- })
- }
- else
- {
- @await Component.InvokeAsync(widgetContentFragment.Name,new
- {
- name = "poll-name"
- })
- }
+ name = "poll-name"
+ })
}
}
From 53b8669d3dad837ee883757486bc349af66d9936 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Mon, 6 Jun 2022 13:20:20 +0300
Subject: [PATCH 05/36] Added missed fact attribute
---
.../Pages/PageManager_Test.cs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs
index 92dac10caf..208de3817f 100644
--- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs
+++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs
@@ -1,9 +1,6 @@
-using Shouldly;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
+using Shouldly;
+using Xunit;
namespace Volo.CmsKit.Pages;
@@ -20,6 +17,7 @@ public class PageManager_Test : CmsKitDomainTestBase
pageRepository = GetRequiredService();
}
+ [Fact]
public async Task CreateAsync_ShouldWorkProperly_WithNonExistingSlug()
{
var title = "My awesome page";
@@ -34,6 +32,7 @@ public class PageManager_Test : CmsKitDomainTestBase
page.Content.ShouldBe(content);
}
+ [Fact]
public async Task CreateAsync_ShouldThrowException_WithExistingSlug()
{
var title = "My awesome page";
@@ -46,6 +45,7 @@ public class PageManager_Test : CmsKitDomainTestBase
exception.ShouldNotBeNull();
}
+ [Fact]
public async Task SetSlugAsync_ShouldWorkProperly_WithNonExistingSlug()
{
var newSlug = "freshly-generated-new-slug";
@@ -56,6 +56,7 @@ public class PageManager_Test : CmsKitDomainTestBase
page.Slug.ShouldBe(newSlug);
}
+ [Fact]
public async Task SetSlugAsync_ShouldThrowException_WithExistingSlug()
{
var newSlug = testData.Page_2_Slug;
From c3eef7a06a9495d5d0c860911ea0e916faafbcd2 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Mon, 6 Jun 2022 18:34:40 +0300
Subject: [PATCH 06/36] Splitted MarkdownContentFragment
still need development
---
.../Shared/Components/Pages/ContentParser.cs | 51 ++++++++++++++-----
1 file changed, 39 insertions(+), 12 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index d9156e5a58..f91e6d22b7 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -1,5 +1,7 @@
+using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@@ -16,19 +18,44 @@ public class ContentParser : IContentParser, ITransientDependency
public async Task> ParseAsync(string content)
{
+ if (!_options.WidgetConfigs.Any())
+ {
+ return new List()
+ {
+ new MarkdownContentFragment() { Content = content }
+ };
+ }
+
+ MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y)
+
+ string split = "-----";
+
+ var polls = new List();
+ foreach (Match m in mc)
+ {
+ polls.Add("[Wid" + m + "]");
+ content = content.Replace("[Wid" + m + "]", split);
+ }
+
+ var splittedContent = content.Split(split, StringSplitOptions.RemoveEmptyEntries);
+
+ var contentFragments = new List();
var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
- return new List {
- new MarkdownContentFragment {
- Content = "**ABP Framework** is completely open source and developed in a community-driven manner."
- },
- new WidgetContentFragment(name) {
- Properties = {
- { "name", "poll-name" }
- }
- },
- new MarkdownContentFragment {
- Content = "Thanks _for_ *your* feedback."
+ for (int b = 0; b < splittedContent.Length; b++)
+ {
+ contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[b] });
+ if (b != splittedContent.Length - 1)
+ {
+ contentFragments.Add(new WidgetContentFragment(name)
+ {
+ Properties =
+ {
+ { "name", "poll-name" }
+ }
+ });
}
- };
+ }
+
+ return contentFragments;
}
}
\ No newline at end of file
From a2d9f457fc3cbca52f17859ea4b7da8db8af05bc Mon Sep 17 00:00:00 2001
From: malik masis
Date: Tue, 7 Jun 2022 23:06:33 +0300
Subject: [PATCH 07/36] created the first dynamic poll
---
.../CmsKit/Shared/Components/Pages/ContentParser.cs | 11 +++++++----
.../CmsKit/Shared/Components/Pages/Default.cshtml | 2 +-
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index f91e6d22b7..7c84b75917 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -28,6 +28,9 @@ public class ContentParser : IContentParser, ITransientDependency
MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y)
+ MatchCollection mcPollName = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")");
+ var pollNames = mcPollName.Select(p => p.Value).ToList();
+
string split = "-----";
var polls = new List();
@@ -41,16 +44,16 @@ public class ContentParser : IContentParser, ITransientDependency
var contentFragments = new List();
var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
- for (int b = 0; b < splittedContent.Length; b++)
+ for (int i = 0; i < splittedContent.Length; i++)
{
- contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[b] });
- if (b != splittedContent.Length - 1)
+ contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[i] });
+ if (i != splittedContent.Length - 1)
{
contentFragments.Add(new WidgetContentFragment(name)
{
Properties =
{
- { "name", "poll-name" }
+ { "name", pollNames[i] }
}
});
}
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 ece75e5422..45720013b6 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
@@ -20,7 +20,7 @@
{
@await Component.InvokeAsync(widgetContentFragment.Name, new
{
- name = "poll-name"
+ name = widgetContentFragment.Properties.FirstOrDefault().Value
})
}
}
From 6edfcdf0e0931e131f97fdb4bc21b3aa78e20dc2 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Wed, 8 Jun 2022 10:39:44 +0300
Subject: [PATCH 08/36] Improved parsing the poll widget for the different
cases
---
.../Shared/Components/Pages/ContentParser.cs | 56 ++++++++++++++-----
1 file changed, 42 insertions(+), 14 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index 7c84b75917..8019ae3ac2 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -26,37 +26,65 @@ public class ContentParser : IContentParser, ITransientDependency
};
}
- MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y)
+ string delimeter = "----";
+ var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
- MatchCollection mcPollName = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")");
- var pollNames = mcPollName.Select(p => p.Value).ToList();
+ var parsedList = new List();
- string split = "-----";
+ if (!replacedText.Contains(delimeter))
+ {
+ parsedList.Add(replacedText);
+ }
- var polls = new List();
- foreach (Match m in mc)
+ while (replacedText.Contains(delimeter))
{
- polls.Add("[Wid" + m + "]");
- content = content.Replace("[Wid" + m + "]", split);
+ //For parsing delimeter
+ var index = replacedText.IndexOf(delimeter);
+ if (index != 0)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+ index = 0;
+ }
+
+ parsedList.Add(replacedText.Substring(index, delimeter.Length));
+ replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length);
+
+ //for parsing the other side
+ index = replacedText.IndexOf(delimeter);
+ if (index != -1)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+
+ }
+ else
+ {
+ parsedList.Add(replacedText);
+ }
}
- var splittedContent = content.Split(split, StringSplitOptions.RemoveEmptyEntries);
+ var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
+
+ var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
var contentFragments = new List();
- var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
- for (int i = 0; i < splittedContent.Length; i++)
+ for (int i = 0, k = 0; i < parsedList.Count; i++)
{
- contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[i] });
- if (i != splittedContent.Length - 1)
+ if (parsedList[i] == delimeter)
{
contentFragments.Add(new WidgetContentFragment(name)
{
Properties =
{
- { "name", pollNames[i] }
+ { "name", pollNames[k++] }
}
});
}
+ else
+ {
+ contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] });
+ }
}
return contentFragments;
From d48a0715310b99aab44d19fb5cd36edebd05b7dc Mon Sep 17 00:00:00 2001
From: malik masis
Date: Wed, 8 Jun 2022 16:04:17 +0300
Subject: [PATCH 09/36] set properties dynamically
---
.../Shared/Components/Pages/ContentParser.cs | 23 +++++++++++--------
.../Shared/Components/Pages/Default.cshtml | 5 +---
.../Components/Pages/WidgetContentFragment.cs | 4 ++--
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
index 8019ae3ac2..e0d53e1b6e 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
@@ -10,6 +9,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class ContentParser : IContentParser, ITransientDependency
{
+ private const string delimeter = "----";
private readonly CmsKitContentWidgetOptions _options;
public ContentParser(IOptions options)
{
@@ -26,7 +26,6 @@ public class ContentParser : IContentParser, ITransientDependency
};
}
- string delimeter = "----";
var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
var parsedList = new List();
@@ -56,7 +55,6 @@ public class ContentParser : IContentParser, ITransientDependency
{
parsedList.Add(replacedText.Substring(0, index));
replacedText = replacedText.Substring(index, replacedText.Length - index);
-
}
else
{
@@ -64,22 +62,27 @@ public class ContentParser : IContentParser, ITransientDependency
}
}
- var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name;
-
var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
+ var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
var contentFragments = new List();
+
for (int i = 0, k = 0; i < parsedList.Count; i++)
{
if (parsedList[i] == delimeter)
{
- contentFragments.Add(new WidgetContentFragment(name)
+ var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
+ if (name is not null)
{
- Properties =
+ contentFragments.Add(new WidgetContentFragment(name)
{
- { "name", pollNames[k++] }
- }
- });
+ Properties =
+ {
+ { "Name", pollNames[k]}
+ }
+ });
+ }
+ k++;
}
else
{
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 45720013b6..3b6e6f0f8c 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
@@ -18,10 +18,7 @@
}
else if (contentFragment is WidgetContentFragment widgetContentFragment)
{
- @await Component.InvokeAsync(widgetContentFragment.Name, new
- {
- name = widgetContentFragment.Properties.FirstOrDefault().Value
- })
+ @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties)
}
}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
index 125c48a72e..8dea303b0e 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
@@ -8,11 +8,11 @@ public class WidgetContentFragment : ContentFragment
public string ViewComponentName { get; set; }
- public Dictionary Properties { get; }
+ public IDictionary Properties { get; }
public WidgetContentFragment(string name)
{
Name = name;
- Properties = new Dictionary();
+ Properties = new Dictionary();
}
}
\ No newline at end of file
From 349471af5eed33320eac502c4cf6bdbe5dd261d0 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Thu, 9 Jun 2022 13:39:08 +0300
Subject: [PATCH 10/36] Added poll for blogpost as well
It will be made refactor
---
.../CmsKit/Public/Blogs/BlogPostPublicDto.cs | 3 +
.../CmsKit/Public/Blogs/ContentFragment.cs | 6 ++
.../Public/Blogs/MarkdownContentFragment.cs | 6 ++
.../Public/Blogs/WidgetContentFragment.cs | 18 ++++
.../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 14 ++-
.../Public/CmsKit/Blogs/BlogPost.cshtml.cs | 17 ++--
.../Blogs/CmsKitContentWidgetOptions.cs | 18 ++++
.../Public/CmsKit/Blogs/ContentParser.cs | 96 +++++++++++++++++++
.../CmsKit/Blogs/ContentWidgetConfig.cs | 15 +++
.../Public/CmsKit/Blogs/IContentParser.cs | 10 ++
10 files changed, 192 insertions(+), 11 deletions(-)
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
index 8c6a6a01e9..3ce3c3457a 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Users;
@@ -15,6 +16,8 @@ public class BlogPostPublicDto : AuditedEntityDto
public string ShortDescription { get; set; }
+ public List ContentFragments { get; set; }
+
public string Content { get; set; }
public Guid? CoverImageMediaId { get; set; }
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
new file mode 100644
index 0000000000..e46316399c
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Blogs;
+
+public abstract class ContentFragment
+{
+
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
new file mode 100644
index 0000000000..79cacf4575
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Blogs;
+
+public class MarkdownContentFragment : ContentFragment
+{
+ public string Content { get; set; }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
new file mode 100644
index 0000000000..11acbf4324
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Blogs;
+
+public class WidgetContentFragment : ContentFragment
+{
+ public string Name { get; }
+
+ public string ViewComponentName { get; set; }
+
+ public IDictionary Properties { get; }
+
+ public WidgetContentFragment(string name)
+ {
+ Name = name;
+ Properties = new Dictionary();
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
index 9d8680e96c..2347e1cfc4 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
@@ -1,5 +1,6 @@
@page
+@using Volo.CmsKit.Public.Blogs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment
@using Volo.CmsKit.Public.Web.Pages
@using Volo.Abp.GlobalFeatures
@@ -65,11 +66,18 @@
@Model.BlogPost.CreationTime
- @if (!Model.BlogPost.Content.IsNullOrEmpty())
+ @foreach (var contentFragment in Model.BlogPost.ContentFragments)
{
- @Html.Raw(await MarkdownRenderer.RenderAsync(Model.BlogPost.Content))
+ if (contentFragment is MarkdownContentFragment markdownContentFragment)
+ {
+ @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
+ }
+ else if (contentFragment is WidgetContentFragment widgetContentFragment)
+ {
+ @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties)
+ }
}
-
+
@if (Model.BlogPost.LastModificationTime != null)
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
index dcefb976a4..e1eda83bb7 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
@@ -1,11 +1,5 @@
-using Markdig;
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using System.Threading.Tasks;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
@@ -37,17 +31,24 @@ public class BlogPostModel : CmsKitPublicPageModelBase
protected IBlogFeatureAppService BlogFeatureAppService { get; }
+ private readonly IContentParser _contentParser;
+
+
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
- IBlogFeatureAppService blogFeaturePublicAppService)
+ IBlogFeatureAppService blogFeaturePublicAppService
+,
+ IContentParser contentParser)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeatureAppService = blogFeaturePublicAppService;
+ _contentParser = contentParser;
}
public virtual async Task OnGetAsync()
{
BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug);
+ BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content);
if (GlobalFeatureManager.Instance.IsEnabled())
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
new file mode 100644
index 0000000000..7a8cc195be
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class CmsKitContentWidgetOptions
+{
+ public Dictionary WidgetConfigs { get; }
+
+ public CmsKitContentWidgetOptions()
+ {
+ WidgetConfigs = new();
+ }
+
+ public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig)
+ {
+ WidgetConfigs.Add(name, contentWidgetConfig);
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
new file mode 100644
index 0000000000..56439d9d7b
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
@@ -0,0 +1,96 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
+using Volo.Abp.DependencyInjection;
+using Volo.CmsKit.Public.Blogs;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class ContentParser : IContentParser, ITransientDependency
+{
+ private const string delimeter = "----";
+ private readonly CmsKitContentWidgetOptions _options;
+ public ContentParser(IOptions options)
+ {
+ _options = options.Value;
+ }
+
+ public async Task> ParseAsync(string content)
+ {
+ if (!_options.WidgetConfigs.Any())
+ {
+ return new List()
+ {
+ new MarkdownContentFragment() { Content = content }
+ };
+ }
+
+ var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
+
+ var parsedList = new List();
+
+ if (!replacedText.Contains(delimeter))
+ {
+ parsedList.Add(replacedText);
+ }
+
+ while (replacedText.Contains(delimeter))
+ {
+ //For parsing delimeter
+ var index = replacedText.IndexOf(delimeter);
+ if (index != 0)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+ index = 0;
+ }
+
+ parsedList.Add(replacedText.Substring(index, delimeter.Length));
+ replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length);
+
+ //for parsing the other side
+ index = replacedText.IndexOf(delimeter);
+ if (index != -1)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+ }
+ else
+ {
+ parsedList.Add(replacedText);
+ }
+ }
+
+ var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
+ var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
+
+ var contentFragments = new List();
+
+ for (int i = 0, k = 0; i < parsedList.Count; i++)
+ {
+ if (parsedList[i] == delimeter)
+ {
+ var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
+ if (name is not null)
+ {
+ contentFragments.Add(new WidgetContentFragment(name)
+ {
+ Properties =
+ {
+ { "Name", pollNames[k]}
+ }
+ });
+ }
+ k++;
+ }
+ else
+ {
+ contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] });
+ }
+ }
+
+ return contentFragments;
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
new file mode 100644
index 0000000000..7f3e40eac4
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
@@ -0,0 +1,15 @@
+using System;
+
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class ContentWidgetConfig
+{
+ public string Name { get; }
+ public Type ViewComponentType { get; set; }
+
+ public ContentWidgetConfig(string name)
+ {
+ Name = name;
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
new file mode 100644
index 0000000000..6ea786f70f
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.CmsKit.Public.Blogs;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public interface IContentParser
+{
+ Task> ParseAsync(string content);
+}
\ No newline at end of file
From 7b3442ae5fb4a5c591d5e4b542c31c4cca25c33b Mon Sep 17 00:00:00 2001
From: malik masis
Date: Thu, 9 Jun 2022 17:43:48 +0300
Subject: [PATCH 11/36] Removed duplication and moved to the domain
---
.../Volo/CmsKit/Blogs/BlogPostConsts.cs | 4 +-
.../Volo/CmsKit/Polls/ContentFragment.cs | 5 +
.../Volo/CmsKit/Polls}/IContentParser.cs | 4 +-
.../CmsKit/Polls}/MarkdownContentFragment.cs | 4 +-
.../Volo/CmsKit/Polls/PollConsts.cs | 5 +
.../CmsKit/Polls}/WidgetContentFragment.cs | 9 +-
.../Polls}/CmsKitContentWidgetOptions.cs | 4 +-
.../Volo/CmsKit/Polls}/ContentParser.cs | 8 +-
.../Volo/CmsKit/Polls}/ContentWidgetConfig.cs | 7 +-
.../CmsKit/Polls/PollViewComponentManager.cs | 19 ++++
.../CmsKit/Public/Blogs/BlogPostPublicDto.cs | 1 +
.../CmsKit/Public/Blogs/ContentFragment.cs | 6 --
.../Polls/IPollViewComponentAppService.cs | 11 +++
.../Polls/PollViewComponentAppService.cs | 20 ++++
.../PollViewComponentClientProxy.Generated.cs | 27 ++++++
.../PollViewComponentClientProxy.cs | 7 ++
.../ClientProxies/cms-kit-generate-proxy.json | 63 ++++++++++++
.../Polls/PollViewComponentController.cs | 27 ++++++
.../Pages/CmsKitContentWidgetOptions.cs | 18 ----
.../Components/Pages/ContentFragment.cs | 6 --
.../Components/Pages/ContentWidgetConfig.cs | 14 ---
.../Shared/Components/Pages/Default.cshtml | 2 +-
.../Pages/DefaultPageViewComponent.cs | 13 +--
.../Pages/MarkdownContentFragment.cs | 6 --
.../Shared/Components/Pages/PageViewModel.cs | 1 +
.../Components/Pages/WidgetContentFragment.cs | 18 ----
.../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 1 +
.../Public/CmsKit/Blogs/BlogPost.cshtml.cs | 12 +--
.../Public/CmsKit/Blogs/ContentParser.cs | 96 -------------------
.../Public/CmsKit/Blogs/IContentParser.cs | 10 --
30 files changed, 219 insertions(+), 209 deletions(-)
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs
rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/IContentParser.cs (54%)
rename modules/cms-kit/src/{Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/MarkdownContentFragment.cs (72%)
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs
rename modules/cms-kit/src/{Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/WidgetContentFragment.cs (81%)
rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/CmsKitContentWidgetOptions.cs (84%)
rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/ContentParser.cs (93%)
rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/ContentWidgetConfig.cs (70%)
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs
create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
index 94a0456c66..99e6ed5b34 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
@@ -1,6 +1,4 @@
-using Volo.CmsKit.GlobalFeatures;
-
-namespace Volo.CmsKit.Blogs;
+namespace Volo.CmsKit.Blogs;
public static class BlogPostConsts
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs
new file mode 100644
index 0000000000..403bff4f64
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs
@@ -0,0 +1,5 @@
+namespace Volo.CmsKit.Polls;
+public abstract class ContentFragment
+{
+
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs
similarity index 54%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs
index 03e54ea4bb..25bc2e8f64 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Threading.Tasks;
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+namespace Volo.CmsKit.Polls;
public interface IContentParser
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs
similarity index 72%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs
index 79cacf4575..0768f325f2 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs
@@ -1,6 +1,6 @@
-namespace Volo.CmsKit.Public.Blogs;
+namespace Volo.CmsKit.Polls;
public class MarkdownContentFragment : ContentFragment
{
public string Content { get; set; }
-}
\ No newline at end of file
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs
new file mode 100644
index 0000000000..8f8ab97073
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs
@@ -0,0 +1,5 @@
+namespace Volo.CmsKit.Polls;
+public static class PollConsts
+{
+ public static string Delimeter { get; } = "----";
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs
similarity index 81%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs
index 11acbf4324..9d0d8c9761 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs
@@ -1,11 +1,10 @@
-using System.Collections.Generic;
-
-namespace Volo.CmsKit.Public.Blogs;
+using System.Collections.Generic;
+namespace Volo.CmsKit.Polls;
public class WidgetContentFragment : ContentFragment
{
public string Name { get; }
-
+
public string ViewComponentName { get; set; }
public IDictionary Properties { get; }
@@ -15,4 +14,4 @@ public class WidgetContentFragment : ContentFragment
Name = name;
Properties = new Dictionary();
}
-}
\ No newline at end of file
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs
similarity index 84%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs
index 7a8cc195be..251cbe463c 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs
@@ -1,10 +1,10 @@
using System.Collections.Generic;
-namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+namespace Volo.CmsKit.Polls;
public class CmsKitContentWidgetOptions
{
- public Dictionary WidgetConfigs { get; }
+ public Dictionary WidgetConfigs { get; }
public CmsKitContentWidgetOptions()
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
similarity index 93%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
index e0d53e1b6e..09bc778021 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
@@ -1,11 +1,11 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
+namespace Volo.CmsKit.Polls;
public class ContentParser : IContentParser, ITransientDependency
{
@@ -62,8 +62,8 @@ public class ContentParser : IContentParser, ITransientDependency
}
}
- var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
- var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
+ var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
+ var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
var contentFragments = new List();
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs
similarity index 70%
rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs
index 7f3e40eac4..eb9c6a0656 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs
@@ -1,13 +1,12 @@
-using System;
+using System;
-
-namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+namespace Volo.CmsKit.Polls;
public class ContentWidgetConfig
{
public string Name { get; }
public Type ViewComponentType { get; set; }
-
+
public ContentWidgetConfig(string name)
{
Name = name;
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs
new file mode 100644
index 0000000000..f110597702
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs
@@ -0,0 +1,19 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.Abp.Domain.Services;
+
+namespace Volo.CmsKit.Polls;
+public class PollViewComponentManager : DomainService
+{
+ protected IContentParser ContentParser { get; set; }
+ public PollViewComponentManager(IContentParser contentParser)
+ {
+ ContentParser = contentParser;
+ }
+
+ public virtual async Task> ParseAsync(string content)
+ {
+ return await ContentParser.ParseAsync(content);
+ }
+
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
index 3ce3c3457a..22fb257d62 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
+using Volo.CmsKit.Polls;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs;
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
deleted file mode 100644
index e46316399c..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace Volo.CmsKit.Public.Blogs;
-
-public abstract class ContentFragment
-{
-
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs
new file mode 100644
index 0000000000..994158e008
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Services;
+using Volo.CmsKit.Polls;
+
+namespace Volo.CmsKit.Public.Polls;
+
+public interface IPollViewComponentAppService : IApplicationService
+{
+ Task> ParseAsync(string content);
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs
new file mode 100644
index 0000000000..24f30d6173
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.CmsKit.Polls;
+
+namespace Volo.CmsKit.Public.Polls;
+
+public class PollViewComponentAppService : CmsKitPublicAppServiceBase, IPollViewComponentAppService
+{
+ protected PollViewComponentManager PollViewComponentManager { get; set; }
+
+ public PollViewComponentAppService(PollViewComponentManager pollViewComponentManager)
+ {
+ PollViewComponentManager = pollViewComponentManager;
+ }
+
+ public virtual async Task> ParseAsync(string content)
+ {
+ return await PollViewComponentManager.ParseAsync(content);
+ }
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs
new file mode 100644
index 0000000000..cb841663e7
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs
@@ -0,0 +1,27 @@
+// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
+using System;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Dtos;
+using Volo.Abp.Http.Client;
+using Volo.Abp.Http.Modeling;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Http.Client.ClientProxying;
+using Volo.CmsKit.Public.Polls;
+using System.Collections.Generic;
+using Volo.CmsKit.Polls;
+
+// ReSharper disable once CheckNamespace
+namespace Volo.CmsKit.Public.Polls.ClientProxies;
+
+[Dependency(ReplaceServices = true)]
+[ExposeServices(typeof(IPollViewComponentAppService), typeof(PollViewComponentClientProxy))]
+public partial class PollViewComponentClientProxy : ClientProxyBase, IPollViewComponentAppService
+{
+ public virtual async Task> ParseAsync(string content)
+ {
+ return await RequestAsync>(nameof(ParseAsync), new ClientProxyRequestTypeValue
+ {
+ { typeof(string), content }
+ });
+ }
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs
new file mode 100644
index 0000000000..b3ba894b58
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs
@@ -0,0 +1,7 @@
+// This file is part of PollViewComponentClientProxy, you can customize it here
+// ReSharper disable once CheckNamespace
+namespace Volo.CmsKit.Public.Polls.ClientProxies;
+
+public partial class PollViewComponentClientProxy
+{
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json
index d39e795845..626dce7ff2 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json
@@ -505,6 +505,57 @@
}
}
},
+ "Volo.CmsKit.Public.Polls.PollViewComponentController": {
+ "controllerName": "PollViewComponent",
+ "controllerGroupName": "PollViewComponent",
+ "isRemoteService": true,
+ "apiVersion": null,
+ "type": "Volo.CmsKit.Public.Polls.PollViewComponentController",
+ "interfaces": [
+ {
+ "type": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService"
+ }
+ ],
+ "actions": {
+ "ParseAsyncByContent": {
+ "uniqueName": "ParseAsyncByContent",
+ "name": "ParseAsync",
+ "httpMethod": "GET",
+ "url": "api/cms-kit-public/polls/{content}",
+ "supportedVersions": [],
+ "parametersOnMethod": [
+ {
+ "name": "content",
+ "typeAsString": "System.String, System.Private.CoreLib",
+ "type": "System.String",
+ "typeSimple": "string",
+ "isOptional": false,
+ "defaultValue": null
+ }
+ ],
+ "parameters": [
+ {
+ "nameOnMethod": "content",
+ "name": "content",
+ "jsonName": null,
+ "type": "System.String",
+ "typeSimple": "string",
+ "isOptional": false,
+ "defaultValue": null,
+ "constraintTypes": [],
+ "bindingSourceId": "Path",
+ "descriptorName": ""
+ }
+ ],
+ "returnValue": {
+ "type": "System.Collections.Generic.List",
+ "typeSimple": "[Volo.CmsKit.Polls.ContentFragment]"
+ },
+ "allowAnonymous": null,
+ "implementFrom": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService"
+ }
+ }
+ },
"Volo.CmsKit.Public.Pages.PagesPublicController": {
"controllerName": "PagesPublic",
"controllerGroupName": "PagesPublic",
@@ -989,6 +1040,18 @@
"bindingSourceId": "ModelBinding",
"descriptorName": "input"
},
+ {
+ "nameOnMethod": "input",
+ "name": "TagId",
+ "jsonName": null,
+ "type": "System.Guid?",
+ "typeSimple": "string?",
+ "isOptional": false,
+ "defaultValue": null,
+ "constraintTypes": null,
+ "bindingSourceId": "ModelBinding",
+ "descriptorName": "input"
+ },
{
"nameOnMethod": "input",
"name": "Sorting",
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs
new file mode 100644
index 0000000000..021040fee6
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Volo.Abp;
+using Volo.CmsKit.Polls;
+
+namespace Volo.CmsKit.Public.Polls;
+
+[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)]
+[Area(CmsKitPublicRemoteServiceConsts.ModuleName)]
+[Route("api/cms-kit-public/polls")]
+public class PollViewComponentController : CmsKitPublicControllerBase, IPollViewComponentAppService
+{
+ protected IPollViewComponentAppService PollViewComponentAppService { get; }
+
+ public PollViewComponentController(IPollViewComponentAppService pollViewComponentAppService)
+ {
+ PollViewComponentAppService = pollViewComponentAppService;
+ }
+
+ [HttpGet]
+ [Route("{content}")]
+ public virtual Task> ParseAsync(string content)
+ {
+ return PollViewComponentAppService.ParseAsync(content);
+ }
+}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
deleted file mode 100644
index d782299026..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System.Collections.Generic;
-
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
-
-public class CmsKitContentWidgetOptions
-{
- public Dictionary WidgetConfigs { get; }
-
- public CmsKitContentWidgetOptions()
- {
- WidgetConfigs = new();
- }
-
- public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig)
- {
- WidgetConfigs.Add(name, contentWidgetConfig);
- }
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
deleted file mode 100644
index c5486903dd..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
-
-public abstract class ContentFragment
-{
-
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
deleted file mode 100644
index 647427b330..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
-
-public class ContentWidgetConfig
-{
- public string Name { get; }
- public Type ViewComponentType { get; set; }
-
- public ContentWidgetConfig(string name)
- {
- Name = name;
- }
-}
\ No newline at end of file
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 3b6e6f0f8c..2a437dd8fb 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
@@ -1,8 +1,8 @@
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
+@using Volo.CmsKit.Polls
@using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs
-@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@inject IMarkdownToHtmlRenderer MarkdownRenderer
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
index 914001b073..7449d0329e 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
+using Volo.CmsKit.Public.Polls;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
@@ -22,20 +23,20 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
})]
public class DefaultPageViewComponent : AbpViewComponent
{
- private readonly IContentParser _contentParser;
+ protected IPollViewComponentAppService PollViewComponentAppService { get; set; }
- public DefaultPageViewComponent(IContentParser contentParser)
+ public DefaultPageViewComponent(IPollViewComponentAppService pollViewComponentAppService)
{
- _contentParser = contentParser;
+ PollViewComponentAppService = pollViewComponentAppService;
}
-
+
public virtual async Task InvokeAsync(
Guid pageId,
string title,
string content)
{
- var contentFragments = await _contentParser.ParseAsync(content);
-
+ var contentFragments = await PollViewComponentAppService.ParseAsync(content);
+
var model = new PageViewModel
{
Id = pageId,
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
deleted file mode 100644
index 361a4b3973..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
-
-public class MarkdownContentFragment : ContentFragment
-{
- public string Content { get; set; }
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
index eae24aeae4..a8dfd40458 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Volo.CmsKit.Polls;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
deleted file mode 100644
index 8dea303b0e..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System.Collections.Generic;
-
-namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
-
-public class WidgetContentFragment : ContentFragment
-{
- public string Name { get; }
-
- public string ViewComponentName { get; set; }
-
- public IDictionary Properties { get; }
-
- public WidgetContentFragment(string name)
- {
- Name = name;
- Properties = new Dictionary();
- }
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
index 2347e1cfc4..6115f33676 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
@@ -1,5 +1,6 @@
@page
+@using Volo.CmsKit.Polls
@using Volo.CmsKit.Public.Blogs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment
@using Volo.CmsKit.Public.Web.Pages
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
index e1eda83bb7..beea823f79 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
@@ -4,6 +4,7 @@ using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Public.Blogs;
+using Volo.CmsKit.Public.Polls;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
@@ -31,24 +32,23 @@ public class BlogPostModel : CmsKitPublicPageModelBase
protected IBlogFeatureAppService BlogFeatureAppService { get; }
- private readonly IContentParser _contentParser;
+ protected IPollViewComponentAppService PollViewComponentAppService { get; }
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
- IBlogFeatureAppService blogFeaturePublicAppService
-,
- IContentParser contentParser)
+ IBlogFeatureAppService blogFeaturePublicAppService,
+ IPollViewComponentAppService pollViewComponentAppService)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeatureAppService = blogFeaturePublicAppService;
- _contentParser = contentParser;
+ PollViewComponentAppService = pollViewComponentAppService;
}
public virtual async Task OnGetAsync()
{
BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug);
- BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content);
+ BlogPost.ContentFragments = await PollViewComponentAppService.ParseAsync(BlogPost.Content);
if (GlobalFeatureManager.Instance.IsEnabled())
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
deleted file mode 100644
index 56439d9d7b..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Options;
-using Volo.Abp.DependencyInjection;
-using Volo.CmsKit.Public.Blogs;
-
-namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
-
-public class ContentParser : IContentParser, ITransientDependency
-{
- private const string delimeter = "----";
- private readonly CmsKitContentWidgetOptions _options;
- public ContentParser(IOptions options)
- {
- _options = options.Value;
- }
-
- public async Task> ParseAsync(string content)
- {
- if (!_options.WidgetConfigs.Any())
- {
- return new List()
- {
- new MarkdownContentFragment() { Content = content }
- };
- }
-
- var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
-
- var parsedList = new List();
-
- if (!replacedText.Contains(delimeter))
- {
- parsedList.Add(replacedText);
- }
-
- while (replacedText.Contains(delimeter))
- {
- //For parsing delimeter
- var index = replacedText.IndexOf(delimeter);
- if (index != 0)
- {
- parsedList.Add(replacedText.Substring(0, index));
- replacedText = replacedText.Substring(index, replacedText.Length - index);
- index = 0;
- }
-
- parsedList.Add(replacedText.Substring(index, delimeter.Length));
- replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length);
-
- //for parsing the other side
- index = replacedText.IndexOf(delimeter);
- if (index != -1)
- {
- parsedList.Add(replacedText.Substring(0, index));
- replacedText = replacedText.Substring(index, replacedText.Length - index);
- }
- else
- {
- parsedList.Add(replacedText);
- }
- }
-
- var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
- var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
-
- var contentFragments = new List();
-
- for (int i = 0, k = 0; i < parsedList.Count; i++)
- {
- if (parsedList[i] == delimeter)
- {
- var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
- if (name is not null)
- {
- contentFragments.Add(new WidgetContentFragment(name)
- {
- Properties =
- {
- { "Name", pollNames[k]}
- }
- });
- }
- k++;
- }
- else
- {
- contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] });
- }
- }
-
- return contentFragments;
- }
-}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
deleted file mode 100644
index 6ea786f70f..0000000000
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Volo.CmsKit.Public.Blogs;
-
-namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
-
-public interface IContentParser
-{
- Task> ParseAsync(string content);
-}
\ No newline at end of file
From 4ad65e239af718c2712ebd87867847927e1f0953 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Fri, 10 Jun 2022 09:56:18 +0300
Subject: [PATCH 12/36] Fixed optional whitespace char issue
---
.../src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
index 09bc778021..b586ff80fa 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
@@ -62,8 +62,8 @@ public class ContentParser : IContentParser, ITransientDependency
}
}
- var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
- var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
+ var pollNames = Regex.Matches(content, @"(?<=PollName\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
+ var polls = Regex.Matches(content, @"(?<=Widget Type\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList();
var contentFragments = new List();
From f727afaa093c4b6dae4a192c20e3539cee8562b9 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Fri, 10 Jun 2022 14:36:24 +0300
Subject: [PATCH 13/36] Checked string length
---
.../src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
index b586ff80fa..5bbd5a9b24 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
@@ -56,7 +56,7 @@ public class ContentParser : IContentParser, ITransientDependency
parsedList.Add(replacedText.Substring(0, index));
replacedText = replacedText.Substring(index, replacedText.Length - index);
}
- else
+ else if (replacedText.Length > 0)
{
parsedList.Add(replacedText);
}
From 47c809885dcc14c248f74b256a4f89f0132caeec Mon Sep 17 00:00:00 2001
From: malik masis
Date: Fri, 10 Jun 2022 14:56:19 +0300
Subject: [PATCH 14/36] Checked range of arrays
---
.../Volo/CmsKit/Polls/ContentParser.cs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
index 5bbd5a9b24..38c0737012 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
@@ -71,16 +71,19 @@ public class ContentParser : IContentParser, ITransientDependency
{
if (parsedList[i] == delimeter)
{
- var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
- if (name is not null)
+ if (polls.Count > k)
{
- contentFragments.Add(new WidgetContentFragment(name)
+ var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
+ if (name is not null && pollNames.Count > k)
{
- Properties =
+ contentFragments.Add(new WidgetContentFragment(name)
{
- { "Name", pollNames[k]}
- }
- });
+ Properties =
+ {
+ { "Name", pollNames[k]}
+ }
+ });
+ }
}
k++;
}
From 5aca43a2b58ca441c7ff8e568786c8c9c7efb151 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Fri, 10 Jun 2022 14:58:51 +0300
Subject: [PATCH 15/36] Added PollViewComponentManager_Test
---
.../Polls/PollViewComponentManager_Test.cs | 123 ++++++++++++++++++
.../Volo.CmsKit.TestBase/CmsKitTestData.cs | 4 +
2 files changed, 127 insertions(+)
create mode 100644 modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs
diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs
new file mode 100644
index 0000000000..67ae5982f1
--- /dev/null
+++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs
@@ -0,0 +1,123 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
+using Shouldly;
+using Xunit;
+
+namespace Volo.CmsKit.Polls;
+
+public class PollViewComponentManager_Test : CmsKitDomainTestBase
+{
+ private readonly PollViewComponentManager pollManager;
+ private readonly CmsKitTestData testData;
+ private readonly IOptions _options;
+
+ public PollViewComponentManager_Test()
+ {
+ pollManager = GetRequiredService();
+ testData = GetRequiredService();
+ _options = GetRequiredService>();
+ }
+
+ [Fact]
+ public async Task ParseAsync_ShouldWorkWithoutConfigOptions()
+ {
+ var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
+ [Widget Type= ""Poll"" PollName =""poll-name""]
+ Thanks _for_ *your * feedback.";
+
+ var page = await pollManager.ParseAsync(content);
+
+ page.ShouldNotBeNull();
+ page.Count.ShouldBe(1);//Ignored Widget
+ }
+
+ [Fact]
+ public async Task ParseAsync_ShouldWorkWithWrongConfigOptions()
+ {
+ _options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName));
+
+ var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
+ [Widget Type= ""Poll"" PollName =""poll-name""]
+ Thanks _for_ *your * feedback.";
+
+ var page = await pollManager.ParseAsync(content);
+
+ page.ShouldNotBeNull();
+ page.Count.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task ParseAsync_ShouldWorkWithWrongWidgetType()
+ {
+ _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+
+ var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
+ [Widget Wrong Type= ""Poll"" PollName =""poll-name""]
+ Thanks _for_ *your * feedback.";
+
+ var page = await pollManager.ParseAsync(content);
+
+ page.ShouldNotBeNull();
+ page.Count.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task ParseAsync_ShouldWorkWithWrongPollName()
+ {
+ _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+
+ var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
+ [Widget Type= ""Poll"" PollWrongName =""poll-name""]
+ Thanks _for_ *your * feedback.";
+
+ var page = await pollManager.ParseAsync(content);
+
+ page.ShouldNotBeNull();
+ page.Count.ShouldBe(2);
+ }
+
+ [Theory]
+ [MemberData(nameof(ExampleData))]
+ public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine)
+ {
+ _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+
+ var page = await pollManager.ParseAsync(content);
+
+ page.ShouldNotBeNull();
+ page.Count.ShouldBe(expectedLine);
+ }
+
+ public static IEnumerable
@foreach (var contentFragment in Model.BlogPost.ContentFragments)
{
- if (contentFragment is MarkdownContentFragment markdownContentFragment)
+ if (contentFragment.Type == "Markdown") //TODO: Constant
{
- @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
+ @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content")))
}
- else if (contentFragment is WidgetContentFragment widgetContentFragment)
+ else if (contentFragment.Type == "Widget") //TODO: Constant
{
- @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties)
+ @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties)
}
}
From 9fba0fa717ee98839c13a6a6bb860f091eb0383b Mon Sep 17 00:00:00 2001
From: malik masis
Date: Tue, 14 Jun 2022 10:28:20 +0300
Subject: [PATCH 21/36] Fixed creating instance wrongly
---
.../Contents/ContentParser_Test.cs | 38 ++++++++++---------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs
index f1b877bac8..00dc4c184e 100644
--- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs
+++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs
@@ -10,13 +10,12 @@ public class ContentParser_Test : CmsKitDomainTestBase
{
private readonly CmsKitTestData testData;
private readonly IOptions _options;
- private readonly ContentParser contentParser;
+ private ContentParser contentParser;
public ContentParser_Test()
{
testData = GetRequiredService();
_options = GetRequiredService>();
- contentParser = GetRequiredService();
}
[Fact]
@@ -24,6 +23,7 @@ public class ContentParser_Test : CmsKitDomainTestBase
{
_options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
_options.Value.AddWidgetConfig("ImageGallery", new ContentWidgetConfig("ImageGallery"));//test
+ contentParser = new ContentParser(_options);
var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
[Widget Type=""Poll"" PollName =""poll-name""]
@@ -43,55 +43,58 @@ public class ContentParser_Test : CmsKitDomainTestBase
[Widget Type= ""Poll"" PollName =""poll-name""]
Thanks _for_ *your * feedback.";
- var poll = await contentParser.ParseAsync(content);
+ var widgets = await contentParser.ParseAsync(content);
- poll.ShouldNotBeNull();
- poll.Count.ShouldBe(1);//Ignored Widget
+ widgets.ShouldNotBeNull();
+ widgets.Count.ShouldBe(1);//Ignored Widget
}
[Fact]
public async Task ParseAsync_ShouldWorkWithWrongConfigOptions()
{
_options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName));
+ contentParser = new ContentParser(_options);
var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
[Widget Type= ""Poll"" PollName =""poll-name""]
Thanks _for_ *your * feedback.";
- var poll = await contentParser.ParseAsync(content);
+ var widgets = await contentParser.ParseAsync(content);
- poll.ShouldNotBeNull();
- poll.Count.ShouldBe(2);
+ widgets.ShouldNotBeNull();
+ widgets.Count.ShouldBe(2);
}
[Fact]
public async Task ParseAsync_ShouldWorkWithWrongWidgetType()
{
_options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+ contentParser = new ContentParser(_options);
var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
[Widget Wrong Type= ""Poll"" PollName =""poll-name""]
Thanks _for_ *your * feedback.";
- var poll = await contentParser.ParseAsync(content);
+ var widgets = await contentParser.ParseAsync(content);
- poll.ShouldNotBeNull();
- poll.Count.ShouldBe(2);
+ widgets.ShouldNotBeNull();
+ widgets.Count.ShouldBe(2);
}
[Fact]
public async Task ParseAsync_ShouldWorkWithWrongPollName()
{
_options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+ contentParser = new ContentParser(_options);
var content = @"**ABP Framework** is completely open source and developed in a community-driven manner.
[Widget Type= ""Poll"" PollWrongName =""poll-name""]
Thanks _for_ *your * feedback.";
- var poll = await contentParser.ParseAsync(content);
+ var widgets = await contentParser.ParseAsync(content);
- poll.ShouldNotBeNull();
- poll.Count.ShouldBe(2);
+ widgets.ShouldNotBeNull();
+ widgets.Count.ShouldBe(2);
}
[Theory]
@@ -99,11 +102,12 @@ public class ContentParser_Test : CmsKitDomainTestBase
public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine)
{
_options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName));
+ contentParser = new ContentParser(_options);
- var poll = await contentParser.ParseAsync(content);
+ var widgets = await contentParser.ParseAsync(content);
- poll.ShouldNotBeNull();
- poll.Count.ShouldBe(expectedLine);
+ widgets.ShouldNotBeNull();
+ widgets.Count.ShouldBe(expectedLine);
}
public static IEnumerable ExampleData =>
From 5058d57ec3839b99b127680b540671dd25ad56c8 Mon Sep 17 00:00:00 2001
From: malik masis
Date: Tue, 14 Jun 2022 10:37:45 +0300
Subject: [PATCH 22/36] Fixed the auto mapper issue
---
.../CmsKit/Public/PublicApplicationAutoMapperProfile.cs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
index a242e28c3b..704a03778c 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
@@ -30,10 +30,11 @@ public class PublicApplicationAutoMapperProfile : Profile
CreateMap();
- CreateMap();
+ CreateMap()
+ .Ignore(x => x.ContentFragments);
- CreateMap(MemberList.None) //TODO: Remove MemberList.None (enable validation)
- .Ignore(x => x.ContentFragments);
+ CreateMap()
+ .Ignore(x => x.ContentFragments);
CreateMap