Browse Source

Created AbpDemoSectionTagHelper

pull/2921/head
Halil İbrahim Kalkan 6 years ago
parent
commit
f2e27e7541
  1. 61
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/Demos/ButtonsDemo/ButtonsDemoViewComponent.cs
  2. 25
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/Demos/ButtonsDemo/Default.cshtml
  3. 84
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpDemoSectionTagHelper.cs
  4. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/_ViewImports.cshtml

61
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/Demos/ButtonsDemo/ButtonsDemoViewComponent.cs

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.Shared.Demos.ButtonsDemo
{
@ -13,61 +8,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.S
{
public const string ViewPath = "/Views/Components/Themes/Shared/Demos/ButtonsDemo/Default.cshtml";
private const string DemoSectionOpeningTag = "<DemoSection:";
private const string DemoSectionClosingTag = "</DemoSection:";
private readonly IVirtualFileProvider _virtualFileProvider;
public ButtonsDemoViewComponent(IVirtualFileProvider virtualFileProvider)
{
_virtualFileProvider = virtualFileProvider;
}
public IViewComponentResult Invoke()
{
var model = new DemoViewModel();
var viewFileInfo = _virtualFileProvider.GetFileInfo(ViewPath);
var viewFileContent = viewFileInfo.ReadAsString();
var lines = viewFileContent.SplitToLines();
StringBuilder sb = null;
foreach (var line in lines)
{
if (line.Contains(DemoSectionOpeningTag))
{
sb = new StringBuilder();
}
else if (line.Contains(DemoSectionClosingTag, StringComparison.InvariantCultureIgnoreCase))
{
var demoName = line.Substring(line.IndexOf(DemoSectionClosingTag, StringComparison.InvariantCultureIgnoreCase) + DemoSectionClosingTag.Length);
if (demoName.Contains(">"))
{
demoName = demoName.Left(demoName.IndexOf(">", StringComparison.InvariantCultureIgnoreCase));
}
model.SourceCodes[demoName] = sb.ToString();
sb = new StringBuilder();
}
else if(sb != null)
{
sb.AppendLine(line);
}
}
return View(ViewPath, model);
}
}
public class DemoViewModel
{
public Dictionary<string, string> SourceCodes { get; set; }
public DemoViewModel()
{
SourceCodes = new Dictionary<string, string>();
return View(ViewPath);
}
}
}

25
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/Demos/ButtonsDemo/Default.cshtml

@ -1,17 +1,8 @@
@model Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.Shared.Demos.ButtonsDemo.DemoViewModel
<div class="abp-theme-demo-section">
<h2>
Basic Buttons
</h2>
<div class="abp-theme-demo-section-body">
<!-- <DemoSection:Buttons.Basic> -->
<abp-button button-type="Primary" text="Primary button" />
<abp-button button-type="Secondary" text="Secondary button" />
<!-- </DemoSection:Buttons.Basic> -->
</div>
<div>
<pre>
@Model.SourceCodes["Buttons.Basic"]
</pre>
</div>
</div>
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.Shared.Demos.ButtonsDemo
<h2>
Basic Buttons
</h2>
<abp-demo-section name="Buttons.Basic" view-path="@ButtonsDemoViewComponent.ViewPath">
<abp-button button-type="Primary" text="Primary button" />
<abp-button button-type="Secondary" text="Secondary button" />
</abp-demo-section>

84
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpDemoSectionTagHelper.cs

@ -0,0 +1,84 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.FileProviders;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.Shared.TagHelpers
{
public class AbpDemoSectionTagHelper : AbpTagHelper
{
private const string DemoSectionOpeningTag = "<abp-demo-section";
private const string DemoSectionClosingTag = "</abp-demo-section";
public string ViewPath { get; set; }
public string Name { get; set; }
private readonly IVirtualFileProvider _virtualFileProvider;
public AbpDemoSectionTagHelper(IVirtualFileProvider virtualFileProvider)
{
_virtualFileProvider = virtualFileProvider;
}
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var content = await output.GetChildContentAsync();
output.PostContent.AppendHtml("<h3>ABP Tag Helpers</h3>");
output.PostContent.AppendHtml("<pre>");
output.PostContent.Append(GetRawDemoSource());
output.PostContent.AppendHtml("</pre>");
output.PostContent.AppendHtml("<hr />");
output.PostContent.AppendHtml("<h3>Bootstrap</h3>");
output.PostContent.AppendHtml("<pre>");
output.PostContent.Append(content.GetContent());
output.PostContent.AppendHtml("</pre>");
}
private string GetRawDemoSource()
{
var viewFileInfo = _virtualFileProvider.GetFileInfo(ViewPath);
var viewFileContent = viewFileInfo.ReadAsString();
var lines = viewFileContent.SplitToLines();
StringBuilder sb = null;
foreach (var line in lines)
{
if (line.Contains(DemoSectionOpeningTag))
{
if (GetName(line) == Name)
{
sb = new StringBuilder();
}
}
else if (line.Contains(DemoSectionClosingTag, StringComparison.InvariantCultureIgnoreCase))
{
if (sb == null)
{
continue;
}
return sb.ToString();
}
else if (sb != null)
{
sb.AppendLine(line);
}
}
return "";
}
private string GetName(string line)
{
var str = line.Substring(line.IndexOf("name=\"", StringComparison.OrdinalIgnoreCase) + "name=\"".Length);
str = str.Left(str.IndexOf("\"", StringComparison.OrdinalIgnoreCase));
return str;
}
}
}

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/Demos/_ViewImports.cshtml → framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/_ViewImports.cshtml

@ -1,4 +1,5 @@
@using System.Globalization
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo
Loading…
Cancel
Save