diff --git a/framework/src/Volo.Abp.TextTemplating.Razor/Volo/Abp/TextTemplating/Razor/RazorTemplatePageBase.cs b/framework/src/Volo.Abp.TextTemplating.Razor/Volo/Abp/TextTemplating/Razor/RazorTemplatePageBase.cs index 9854775a25..138d4c5366 100644 --- a/framework/src/Volo.Abp.TextTemplating.Razor/Volo/Abp/TextTemplating/Razor/RazorTemplatePageBase.cs +++ b/framework/src/Volo.Abp.TextTemplating.Razor/Volo/Abp/TextTemplating/Razor/RazorTemplatePageBase.cs @@ -34,18 +34,30 @@ namespace Volo.Abp.TextTemplating.Razor public virtual void WriteLiteral(string literal = null) { - _stringBuilder.Append(literal); + if (!literal.IsNullOrEmpty()) + { + _stringBuilder.Append(literal); + } } - public virtual void Write(object obj = null) + public virtual void Write(object value = null) { - _stringBuilder.Append(obj); + if (value is null) + { + return; + } + + _stringBuilder.Append(value.ToString()); } public virtual void BeginWriteAttribute(string name, string prefix, int prefixOffset, string suffix, int suffixOffset, int attributeValuesCount) { _attributeInfo = new AttributeInfo(name, prefix, prefixOffset, suffix, suffixOffset, attributeValuesCount); - WriteLiteral(prefix); + + if (attributeValuesCount != 1) + { + WriteLiteral(prefix); + } } public virtual void WriteAttributeValue(string prefix, int prefixOffset, object value, int valueOffset, int valueLength, bool isLiteral) @@ -81,9 +93,6 @@ namespace Volo.Abp.TextTemplating.Razor WriteUnprefixedAttributeValue(value, isLiteral); } - - _stringBuilder.Append(prefix); - _stringBuilder.Append(value); } public virtual void EndWriteAttribute() @@ -128,15 +137,19 @@ namespace Volo.Abp.TextTemplating.Razor } } - private bool IsBoolFalseOrNullValue(string prefix, object value) + + private static bool IsBoolFalseOrNullValue(string prefix, object value) { - return string.IsNullOrEmpty(prefix) && (value == null || (value is bool b && !b)); + return string.IsNullOrEmpty(prefix) && + (value is null || + (value is bool boolValue && !boolValue)); } - private bool IsBoolTrueWithEmptyPrefixValue(string prefix, object value) + private static bool IsBoolTrueWithEmptyPrefixValue(string prefix, object value) { // If the value is just the bool 'true', use the attribute name as the value. - return string.IsNullOrEmpty(prefix) && (value is bool b && b); + return string.IsNullOrEmpty(prefix) && + (value is bool boolValue && boolValue); } private struct AttributeInfo diff --git a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorTemplateRendererProvider_Tests.cs b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorTemplateRendererProvider_Tests.cs index 04e2d1b029..c5926c6ca5 100644 --- a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorTemplateRendererProvider_Tests.cs +++ b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorTemplateRendererProvider_Tests.cs @@ -72,13 +72,13 @@ namespace Volo.Abp.TextTemplating.Razor TestTemplates.ForgotPasswordEmail, new ForgotPasswordEmailModel("John"), cultureName: "en" - )).ShouldBe("*BEGIN*Hello John, how are you?. Please click to the following link to get an email to reset your password!*END*"); + )).ShouldBe("*BEGIN*Hello John, how are you?. Please click to the following link to get an email to reset your password!Reset your password*END*"); (await _templateRenderer.RenderAsync( TestTemplates.ForgotPasswordEmail, new ForgotPasswordEmailModel("John"), cultureName: "tr" - )).ShouldBe("*BEGIN*Merhaba John, nasılsın?. Please click to the following link to get an email to reset your password!*END*"); + )).ShouldBe("*BEGIN*Merhaba John, nasılsın?. Please click to the following link to get an email to reset your password!Reset your password*END*"); } [Fact] diff --git a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorVirtualFileTemplateContributor_Tests.cs b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorVirtualFileTemplateContributor_Tests.cs index 5bbb267613..62ac8392ee 100644 --- a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorVirtualFileTemplateContributor_Tests.cs +++ b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorVirtualFileTemplateContributor_Tests.cs @@ -17,7 +17,13 @@ namespace Volo.Abp.TextTemplating.Razor ForgotPasswordEmailEnglishContent = "@inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase" + Environment.NewLine + - "@Localizer[\"HelloText\", Model.Name], @Localizer[\"HowAreYou\"]. Please click to the following link to get an email to reset your password!"; + "@{" + + Environment.NewLine + + " var url = @\"https://abp.io/Account/ResetPassword\";" + + Environment.NewLine + + "}" + + Environment.NewLine + + "@Localizer[\"HelloText\", Model.Name], @Localizer[\"HowAreYou\"]. Please click to the following link to get an email to reset your password!Reset your password"; } } } diff --git a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml index 360e5b2a7c..b53c8f93fc 100644 --- a/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml +++ b/framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml @@ -1,2 +1,5 @@ @inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase -@Localizer["HelloText", Model.Name], @Localizer["HowAreYou"]. Please click to the following link to get an email to reset your password! \ No newline at end of file +@{ + var url = @"https://abp.io/Account/ResetPassword"; +} +@Localizer["HelloText", Model.Name], @Localizer["HowAreYou"]. Please click to the following link to get an email to reset your password!Reset your password \ No newline at end of file