mirror of https://github.com/abpframework/abp.git
30 changed files with 219 additions and 209 deletions
@ -0,0 +1,5 @@ |
|||
namespace Volo.CmsKit.Polls; |
|||
public abstract class ContentFragment |
|||
{ |
|||
|
|||
} |
|||
@ -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 |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
namespace Volo.CmsKit.Public.Blogs; |
|||
namespace Volo.CmsKit.Polls; |
|||
|
|||
public class MarkdownContentFragment : ContentFragment |
|||
{ |
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
namespace Volo.CmsKit.Polls; |
|||
public static class PollConsts |
|||
{ |
|||
public static string Delimeter { get; } = "----"; |
|||
} |
|||
@ -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<string, ContentWidgetConfig> WidgetConfigs { get; } |
|||
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; } |
|||
|
|||
public CmsKitContentWidgetOptions() |
|||
{ |
|||
@ -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; |
|||
@ -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<List<ContentFragment>> ParseAsync(string content) |
|||
{ |
|||
return await ContentParser.ParseAsync(content); |
|||
} |
|||
|
|||
} |
|||
@ -1,6 +0,0 @@ |
|||
namespace Volo.CmsKit.Public.Blogs; |
|||
|
|||
public abstract class ContentFragment |
|||
{ |
|||
|
|||
} |
|||
@ -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<List<ContentFragment>> ParseAsync(string content); |
|||
} |
|||
@ -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<List<ContentFragment>> ParseAsync(string content) |
|||
{ |
|||
return await PollViewComponentManager.ParseAsync(content); |
|||
} |
|||
} |
|||
@ -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>, IPollViewComponentAppService |
|||
{ |
|||
public virtual async Task<List<ContentFragment>> ParseAsync(string content) |
|||
{ |
|||
return await RequestAsync<List<ContentFragment>>(nameof(ParseAsync), new ClientProxyRequestTypeValue |
|||
{ |
|||
{ typeof(string), content } |
|||
}); |
|||
} |
|||
} |
|||
@ -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 |
|||
{ |
|||
} |
|||
@ -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<List<ContentFragment>> ParseAsync(string content) |
|||
{ |
|||
return PollViewComponentAppService.ParseAsync(content); |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; |
|||
|
|||
public class CmsKitContentWidgetOptions |
|||
{ |
|||
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; } |
|||
|
|||
public CmsKitContentWidgetOptions() |
|||
{ |
|||
WidgetConfigs = new(); |
|||
} |
|||
|
|||
public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig) |
|||
{ |
|||
WidgetConfigs.Add(name, contentWidgetConfig); |
|||
} |
|||
} |
|||
@ -1,6 +0,0 @@ |
|||
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; |
|||
|
|||
public abstract class ContentFragment |
|||
{ |
|||
|
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -1,6 +0,0 @@ |
|||
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; |
|||
|
|||
public class MarkdownContentFragment : ContentFragment |
|||
{ |
|||
public string Content { get; set; } |
|||
} |
|||
@ -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<string, object> Properties { get; } |
|||
|
|||
public WidgetContentFragment(string name) |
|||
{ |
|||
Name = name; |
|||
Properties = new Dictionary<string, object>(); |
|||
} |
|||
} |
|||
@ -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<CmsKitContentWidgetOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
|
|||
public async Task<List<ContentFragment>> ParseAsync(string content) |
|||
{ |
|||
if (!_options.WidgetConfigs.Any()) |
|||
{ |
|||
return new List<ContentFragment>() |
|||
{ |
|||
new MarkdownContentFragment() { Content = content } |
|||
}; |
|||
} |
|||
|
|||
var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); |
|||
|
|||
var parsedList = new List<string>(); |
|||
|
|||
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<ContentFragment>(); |
|||
|
|||
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; |
|||
} |
|||
} |
|||
@ -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<List<ContentFragment>> ParseAsync(string content); |
|||
} |
|||
Loading…
Reference in new issue