Skip to content

Commit

Permalink
Merge pull request #14 from LazZiya/DotNetFive
Browse files Browse the repository at this point in the history
Dot net five
  • Loading branch information
LazZiya committed Nov 5, 2020
2 parents 5d8ec3c + 5fe0e26 commit ff7d40d
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 296 deletions.
14 changes: 11 additions & 3 deletions LazZiya.TagHelpers/AlertTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using LazZiya.TagHelpers.Utilities;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Localization;

namespace LazZiya.TagHelpers
{
Expand All @@ -27,6 +28,11 @@ public class AlertTagHelper : TagHelper
/// </summary>
public bool Dismissable { get; set; } = true;

/// <summary>
/// Parse localizer instance to localize alert message
/// </summary>
public IStringLocalizer Localizer { get; set; }

/// <summary>
/// <para>ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper.</para>
/// <para>View context is required to access TempData dictionary that contains the alerts coming from backend</para>
Expand Down Expand Up @@ -75,7 +81,7 @@ private TagBuilder AddAlert(Alert alert)
{
var _alert = new TagBuilder("div");

var alertStyle = Enum.GetName(typeof(AlertStyle), alert.AlertStyle).ToLower();
var alertStyle = Enum.GetName(typeof(AlertStyle), alert.AlertStyle).ToLowerInvariant();
_alert.AddCssClass($"alert alert-{alertStyle}");
_alert.Attributes.Add("role", "alert");

Expand All @@ -86,12 +92,14 @@ private TagBuilder AddAlert(Alert alert)

if (!string.IsNullOrWhiteSpace(alert.AlertHeading))
{
_alert.InnerHtml.AppendHtml($"<h4 class='alert-heading'>{alert.AlertHeading}</h4>");
var heading = Localizer == null ? alert.AlertHeading : Localizer[alert.AlertHeading];
_alert.InnerHtml.AppendHtml($"<h4 class='alert-heading'>{heading}</h4>");
}

if (!string.IsNullOrWhiteSpace(alert.AlertMessage))
{
_alert.InnerHtml.AppendHtml($"<p class='mb-0'>{alert.AlertMessage}</p>");
var msg = Localizer == null ? alert.AlertMessage : Localizer[alert.AlertMessage];
_alert.InnerHtml.AppendHtml($"<p class='mb-0'>{msg}</p>");
}

return _alert;
Expand Down
2 changes: 1 addition & 1 deletion LazZiya.TagHelpers/Alerts/AlertModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal enum AlertStyle {
}

/// <summary>
/// Alert item that can be created in the backend manually for pushing alert to themp data
/// Alert item that can be created in the backend manually for pushing alert to the temp data
/// </summary>
internal class Alert
{
Expand Down
12 changes: 6 additions & 6 deletions LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using LazZiya.TagHelpers.Utilities;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#if NETCOREAPP3_0 || NETCOREAPP3_1
using System.Text.Json;
#else
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2
using Newtonsoft.Json;
#else
using System.Text.Json;
#endif

namespace LazZiya.TagHelpers.Alerts
Expand Down Expand Up @@ -112,13 +112,13 @@ public static void Dark(this ITempDataDictionary tempData, string alertMessage,

private static void AddAlert(ITempDataDictionary tempData, AlertStyle alertStyle, string message, string header, bool dismissable)
{
#if NETCOREAPP3_0 || NETCOREAPP3_1
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2
var alerts = tempData.ContainsKey(Alert.TempDataKey)
? JsonSerializer.Deserialize<List<Alert>>(tempData[Alert.TempDataKey].ToString())
? JsonConvert.DeserializeObject<List<Alert>>(tempData[Alert.TempDataKey].ToString())
: new List<Alert>();
#else
var alerts = tempData.ContainsKey(Alert.TempDataKey)
? JsonConvert.DeserializeObject<List<Alert>>(tempData[Alert.TempDataKey].ToString())
? JsonSerializer.Deserialize<List<Alert>>(tempData[Alert.TempDataKey].ToString())
: new List<Alert>();
#endif
alerts.Add(new Alert
Expand Down
29 changes: 6 additions & 23 deletions LazZiya.TagHelpers/LanguageNavModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ public enum LanguageLabel
TwoLetterISOLanguageName
}

/// <summary>
/// Defines where to redirect when language is changes
/// </summary>
[Obsolete("This property is deprected. Use redirect-to-url instead.")]
public enum RedirectTo
{
/// <summary>
/// redirects to home page in the project root
/// </summary>
HomePage,

/// <summary>
/// redirects to the same page and keep all filter like search
/// </summary>
SamePage,

/// <summary>
/// redirect to the same page and clear all filters (QueryString) values
/// </summary>
SamePageNoQueryString
}

/// <summary>
/// choose render mode style,
/// <para>classic: regular dropdown select list</para>
Expand All @@ -70,7 +48,12 @@ public enum RenderMode
/// <summary>
/// HTML5 div with Bootstrap 4 support
/// </summary>
Bootstrap
Bootstrap,

/// <summary>
/// Render as form control
/// </summary>
FormControl
}

internal class LanguageItem
Expand Down
68 changes: 38 additions & 30 deletions LazZiya.TagHelpers/LanguageNavTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ namespace LazZiya.TagHelpers
/// </summary>
public class LanguageNavTagHelper : TagHelper
{
/// <summary>
/// optional: route data key name for culture, default "culture"
/// default: cultute
/// </summary>
[Obsolete("This property is deprected. Use redirect-to-url instead.")]
public string CultureKeyName { get; set; } = "culture";

/// <summary>
/// optional: manually specify list of supported cultures
/// <example>
Expand All @@ -36,19 +29,6 @@ public class LanguageNavTagHelper : TagHelper
/// </summary>
public LanguageLabel LanguageLabel { get; set; } = LanguageLabel.EnglishName;

/// <summary>
/// optional: specify where to redirect when the language is changed
/// <para>default value: RedirectTo.SamePage</para>
/// </summary>
[Obsolete("This property is deprected. Use redirect-to-url instead.")]
public RedirectTo RedirectTo { get; set; } = RedirectTo.SamePage;

/// <summary>
/// optinal: name of the home page to redirect to when RedirectTo is HomePage
/// </summary>
[Obsolete("This property is deprected. Use redirect-to-url instead.")]
public string HomePageName { get; set; } = "Index";

/// <summary>
/// <para>ViewContext property is not required to be passed as parameter, it will be auto assigned by the tag helpoer.</para>
/// <para>current view context to access RouteData.Values and Request.Query collection</para>
Expand Down Expand Up @@ -112,13 +92,17 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
{
var langDictionary = CreateNavDictionary();

if (RenderMode == RenderMode.Bootstrap)
switch(RenderMode)
{
CreateBootstrapItems(ref output, langDictionary);
}
else
{
CreateClassicItems(ref output, langDictionary);
case RenderMode.Bootstrap:
CreateBootstrapItems(ref output, langDictionary);
break;
case RenderMode.Classic:
CreateClassicItems(ref output, langDictionary);
break;
case RenderMode.FormControl:
CreateFormControlItems(ref output, langDictionary);
break;
}
}

Expand Down Expand Up @@ -147,6 +131,30 @@ private void CreateClassicItems(ref TagHelperOutput output, List<LanguageItem> l
}
}

/// <summary>
/// create a dropdown form control
/// <example><![CDATA[<option value="/en-US/Index">English</option>]]></example>
/// </summary>
/// <param name="langDictionary">language name-URL dictionary</param>
/// <param name="output">reference to TagHelperOuput</param>
/// <returns></returns>
private void CreateFormControlItems(ref TagHelperOutput output, List<LanguageItem> langDictionary)
{
output.TagName = "select";

foreach (var lang in langDictionary.OrderBy(x => x.DisplayText))
{
var option = new TagBuilder("option");
option.Attributes.Add("value", lang.Name);
option.InnerHtml.AppendHtml(lang.DisplayText);

if (CultureInfo.CurrentCulture.Name == lang.Name)
option.Attributes.Add("selected", "selected");

output.Content.AppendHtml(option);
}
}

/// <summary>
/// create classic list items list
/// <example><![CDATA[<a href="/en-US/Index" class="itemxyz">English</a>]]></example>
Expand Down Expand Up @@ -179,9 +187,9 @@ private void CreateBootstrapItems(ref TagHelperOutput output, List<LanguageItem>
{

if (FlagsSquared)
a.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLower()} flag-icon-squared\"></span>&nbsp;");
a.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLowerInvariant()} flag-icon-squared\"></span>&nbsp;");
else
a.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLower()}\"></span>&nbsp;");
a.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLowerInvariant()}\"></span>&nbsp;");
}
}

Expand Down Expand Up @@ -281,9 +289,9 @@ private TagBuilder CreateToggle()
if (flagName.Length == 2)
{
if (FlagsSquared)
toggle.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLower()} flag-icon-squared\"></span>&nbsp;");
toggle.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLowerInvariant()} flag-icon-squared\"></span>&nbsp;");
else
toggle.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLower()}\"></span>&nbsp;");
toggle.InnerHtml.AppendHtml($"<span class=\"flag-icon flag-icon-{flagName[1].ToLowerInvariant()}\"></span>&nbsp;");
}
}

Expand Down
130 changes: 72 additions & 58 deletions LazZiya.TagHelpers/LazZiya.TagHelpers.csproj
Original file line number Diff line number Diff line change
@@ -1,69 +1,83 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<ApplicationIcon>files\icon.ico</ApplicationIcon>
<Authors>Ziya Mollamahmut</Authors>
<Company>Ziyad.info</Company>
<Description>Collection of tag helpers for ASP.NET Core web applications, like Paging, SelectEnum and LanguageNav dropdown tag helpers for MVC and Razor Pages.</Description>
<Copyright>Ziyad.info</Copyright>
<PackageProjectUrl>https://github.com/LazZiya/TagHelpers/wiki</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>asp.net, core, razor, mvc, taghelpers, taghelper,tag,helper,language,culture,dropdown, pagination, select, enum</PackageTags>
<PackageReleaseNotes>
- Performance improvments for creating urls in paging taghelper
- See all release notes in https://github.com/LazZiya/TagHelpers/releases
</PackageReleaseNotes>
<Version>4.1.0</Version>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<FileVersion>4.1.0.0</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/LazZiya/TagHelpers/master/LazZiya.TagHelpers/files/icon.png</PackageIconUrl>
<RepositoryUrl>https://github.com/LazZiya/TagHelpers</RepositoryUrl>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>
<ApplicationIcon>files\icon.ico</ApplicationIcon>
<Authors>Ziya Mollamahmut</Authors>
<Company>Ziyad.info</Company>
<Description>Collection of tag helpers for ASP.NET Core web applications, like Paging, SelectEnum and LanguageNav dropdown tag helpers for MVC and Razor Pages.</Description>
<Copyright>Ziyad.info</Copyright>
<PackageProjectUrl>https://docs.ziyad.info/en/LazZiya.TagHelpers/v5.0/index.md</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>asp.net, core, razor, mvc, taghelpers, taghelper,tag,helper,language,culture,dropdown, pagination, select, enum</PackageTags>
<PackageReleaseNotes>
- .net5 support
- PagingTagHelper: Improved styling as adding styles that fits into dark or light themes
- PagingTagHelper: New page size label with string format support
- Localization support for AlertTagHelper
- Performance improvments while creating urls in paging taghelper
- New render mode for LanguageNav: "FormControl" renders the language nav as a form control. This helps to use the culture navigation control as a dropdown inside any form.
- Bug fixe for alert-info
- See all release notes in https://github.com/LazZiya/TagHelpers/releases
</PackageReleaseNotes>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>rc.1</VersionSuffix>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/LazZiya/TagHelpers/master/LazZiya.TagHelpers/files/icon.png</PackageIconUrl>
<RepositoryUrl>https://github.com/LazZiya/TagHelpers</RepositoryUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug' OR '$(Configuration)'=='Release'">
<DocumentationFile>LazZiya.TagHelpers.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug' OR '$(Configuration)'=='Release'">
<DocumentationFile>LazZiya.TagHelpers.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.0.0" Exclude="build,analyzers" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.0.0" Exclude="build,analyzers" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.0.0" Exclude="build,analyzers" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.0.0" Exclude="build,analyzers" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0" Exclude="Build,Analyzers" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.0" Exclude="Build,Analyzers" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup>
<None Update="files\icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="files\icon.png" Pack="true" PackagePath="">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="files\license.txt" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="5.0.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="files\icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="files\icon.png" Pack="true" PackagePath="">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="files\license.txt" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<Target Name="AfterPack" AfterTargets="Pack">
<Exec Command="dotnet nuget push $(PackageOutputPath)*.nupkg --source Local" />
</Target>
</Project>
Loading

0 comments on commit ff7d40d

Please sign in to comment.