Browse Source

Merge pull request #10465 from abpframework/maliming/razor-page-patch

Fix Razor Page attribute issue.
pull/10467/head
liangshiwei 5 years ago
committed by GitHub
parent
commit
932309a14c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      framework/src/Volo.Abp.TextTemplating.Razor/Volo/Abp/TextTemplating/Razor/RazorTemplatePageBase.cs
  2. 4
      framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorTemplateRendererProvider_Tests.cs
  3. 8
      framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/RazorVirtualFileTemplateContributor_Tests.cs
  4. 5
      framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml

35
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) 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) 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); _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) 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); WriteUnprefixedAttributeValue(value, isLiteral);
} }
_stringBuilder.Append(prefix);
_stringBuilder.Append(value);
} }
public virtual void EndWriteAttribute() 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. // 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 private struct AttributeInfo

4
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, TestTemplates.ForgotPasswordEmail,
new ForgotPasswordEmailModel("John"), new ForgotPasswordEmailModel("John"),
cultureName: "en" 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!<a target=\"_blank\" href=\"https://abp.io/Account/ResetPassword\">Reset your password</a>*END*");
(await _templateRenderer.RenderAsync( (await _templateRenderer.RenderAsync(
TestTemplates.ForgotPasswordEmail, TestTemplates.ForgotPasswordEmail,
new ForgotPasswordEmailModel("John"), new ForgotPasswordEmailModel("John"),
cultureName: "tr" 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!<a target=\"_blank\" href=\"https://abp.io/Account/ResetPassword\">Reset your password</a>*END*");
} }
[Fact] [Fact]

8
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<Volo.Abp.TextTemplating.Razor.RazorTemplateRendererProvider_Tests.ForgotPasswordEmailModel>" + ForgotPasswordEmailEnglishContent = "@inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase<Volo.Abp.TextTemplating.Razor.RazorTemplateRendererProvider_Tests.ForgotPasswordEmailModel>" +
Environment.NewLine + 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!<a target=\"_blank\" href=\"@url\">Reset your password</a>";
} }
} }
} }

5
framework/test/Volo.Abp.TextTemplating.Razor.Tests/Volo/Abp/TextTemplating/Razor/SampleTemplates/ForgotPasswordEmail.cshtml

@ -1,2 +1,5 @@
@inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase<Volo.Abp.TextTemplating.Razor.RazorTemplateRendererProvider_Tests.ForgotPasswordEmailModel> @inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase<Volo.Abp.TextTemplating.Razor.RazorTemplateRendererProvider_Tests.ForgotPasswordEmailModel>
@Localizer["HelloText", Model.Name], @Localizer["HowAreYou"]. Please click to the following link to get an email to reset your password! @{
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!<a target="_blank" href="@url">Reset your password</a>
Loading…
Cancel
Save