mirror of https://github.com/abpframework/abp.git
11 changed files with 88 additions and 93 deletions
@ -0,0 +1,8 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.CmsKit.Contents; |
||||
|
|
||||
|
public class DefaultContentDto : IContent |
||||
|
{ |
||||
|
public List<ContentFragment> ContentFragments { get; set; } |
||||
|
} |
||||
@ -1,82 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.IO; |
|
||||
using System.Text.Encodings.Web; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Mvc; |
|
||||
using Microsoft.AspNetCore.Mvc.Rendering; |
|
||||
using Microsoft.AspNetCore.Mvc.ViewComponents; |
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines; |
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp; |
|
||||
using Volo.Abp.GlobalFeatures; |
|
||||
using Volo.CmsKit.GlobalFeatures; |
|
||||
|
|
||||
namespace Volo.CmsKit.Contents; |
|
||||
|
|
||||
[RequiresGlobalFeature(typeof(PagesFeature))] |
|
||||
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
|
||||
[Area(CmsKitCommonRemoteServiceConsts.ModuleName)] |
|
||||
[Route("api/cms-kit/contents")] |
|
||||
public class ContentController : Controller, IContentAppService |
|
||||
{ |
|
||||
protected IContentAppService ContentAppService { get; } |
|
||||
|
|
||||
public ContentController(IContentAppService contentAppService) |
|
||||
{ |
|
||||
ContentAppService = contentAppService; |
|
||||
} |
|
||||
|
|
||||
[HttpGet] |
|
||||
[Route("{parseashtml}")] |
|
||||
public virtual async Task<string> ParseAsHtmlAsync(string content) |
|
||||
{ |
|
||||
var fragments = await ParseAsync(content); |
|
||||
return await RenderViewComponent("ContentFragment", new PageDto() { ContentFragments = fragments }); |
|
||||
} |
|
||||
public virtual Task<List<ContentFragment>> ParseAsync(string content) |
|
||||
{ |
|
||||
return ContentAppService.ParseAsync(content); |
|
||||
} |
|
||||
|
|
||||
private async Task<string> RenderViewComponent(string viewComponent, object args) |
|
||||
{ |
|
||||
var sp = HttpContext.RequestServices; |
|
||||
|
|
||||
var helper = new DefaultViewComponentHelper( |
|
||||
sp.GetRequiredService<IViewComponentDescriptorCollectionProvider>(), |
|
||||
HtmlEncoder.Default, |
|
||||
sp.GetRequiredService<IViewComponentSelector>(), |
|
||||
sp.GetRequiredService<IViewComponentInvokerFactory>(), |
|
||||
sp.GetRequiredService<IViewBufferScope>()); |
|
||||
|
|
||||
using (var writer = new StringWriter()) |
|
||||
{ |
|
||||
var context = new ViewContext(ControllerContext, NullView.Instance, ViewData, TempData, writer, new HtmlHelperOptions()); |
|
||||
helper.Contextualize(context); |
|
||||
var result = await helper.InvokeAsync(viewComponent, args); |
|
||||
result.WriteTo(writer, HtmlEncoder.Default); |
|
||||
await writer.FlushAsync(); |
|
||||
return writer.ToString(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
internal class NullView : IView |
|
||||
{ |
|
||||
public static readonly NullView Instance = new(); |
|
||||
|
|
||||
public string Path => string.Empty; |
|
||||
|
|
||||
public Task RenderAsync(ViewContext context) |
|
||||
{ |
|
||||
if (context == null) |
|
||||
{ |
|
||||
throw new ArgumentNullException(nameof(context)); |
|
||||
} |
|
||||
|
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; |
||||
|
|
||||
|
namespace Volo.CmsKit.Web.Controllers; |
||||
|
|
||||
|
public class CmsKitCommonWidgetsController : AbpController |
||||
|
{ |
||||
|
[HttpPost] |
||||
|
public IActionResult ContentPreview(ContentPreviewDto dto) |
||||
|
{ |
||||
|
return ViewComponent(typeof(ContentPreviewViewComponent), new { content = dto.Content }); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class ContentPreviewDto |
||||
|
{ |
||||
|
public string Content { get; set; } |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.CmsKit.Contents; |
||||
|
|
||||
|
namespace Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; |
||||
|
|
||||
|
public class ContentPreviewViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
protected IContentAppService ContentAppService { get; } |
||||
|
|
||||
|
public ContentPreviewViewComponent(IContentAppService contentAppService) |
||||
|
{ |
||||
|
ContentAppService = contentAppService; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<IViewComponentResult> InvokeAsync(string content) |
||||
|
{ |
||||
|
var fragments = await ContentAppService.ParseAsync(content); |
||||
|
|
||||
|
return View("~/Pages/CmsKit/Components/ContentPreview/Default.cshtml", new DefaultContentDto |
||||
|
{ |
||||
|
ContentFragments = fragments |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
@using Volo.CmsKit.Contents |
||||
|
@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents |
||||
|
|
||||
|
@model DefaultContentDto |
||||
|
|
||||
|
<div class="content"> |
||||
|
|
||||
|
@await Component.InvokeAsync(typeof(ContentFragmentViewComponent), Model) |
||||
|
|
||||
|
</div> |
||||
@ -1,7 +1,7 @@ |
|||||
@using Volo.CmsKit.Web.Contents; |
@using System.Dynamic |
||||
@using System.Dynamic |
|
||||
@using Volo.Abp.Data |
@using Volo.Abp.Data |
||||
@using Volo.CmsKit.Web.Renderers; |
@using Volo.CmsKit.Web.Renderers; |
||||
|
@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; |
||||
|
|
||||
@model ContentFragmentViewComponent |
@model ContentFragmentViewComponent |
||||
|
|
||||
@ -1,6 +1,6 @@ |
|||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.CmsKit.Web.Contents; |
namespace Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; |
||||
|
|
||||
public interface IContentRenderer |
public interface IContentRenderer |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.CmsKit.Web.Contents; |
namespace Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; |
||||
|
|
||||
public class PlainTextContentRenderer : IContentRenderer, ITransientDependency |
public class PlainTextContentRenderer : IContentRenderer, ITransientDependency |
||||
{ |
{ |
||||
Loading…
Reference in new issue