Rename `HtmlEncodedString` => `HtmlString`.

- This rename makes the type more consistent with its `HtmlContentBuilder` counterparts (`AppendHtml`).

#25
This commit is contained in:
N. Taylor Mullen 2016-05-16 16:06:01 -07:00
parent 01e4265183
commit fe563b1459
8 changed files with 27 additions and 22 deletions

View File

@ -4,6 +4,6 @@ AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/cu9y78vsdp19e
Travis: [![Travis](https://travis-ci.org/aspnet/HtmlAbstractions.svg?branch=dev)](https://travis-ci.org/aspnet/HtmlAbstractions) Travis: [![Travis](https://travis-ci.org/aspnet/HtmlAbstractions.svg?branch=dev)](https://travis-ci.org/aspnet/HtmlAbstractions)
HTML abstractions used for building HTML content, including types such as `HtmlEncodedString` and `IHtmlContent`. HTML abstractions used for building HTML content, including types such as `HtmlString` and `IHtmlContent`.
This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo.

View File

@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Html
{ {
if (!string.IsNullOrEmpty(encoded)) if (!string.IsNullOrEmpty(encoded))
{ {
Entries.Add(new HtmlEncodedString(encoded)); Entries.Add(new HtmlString(encoded));
} }
return this; return this;

View File

@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Html
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.AppendHtml(HtmlEncodedString.NewLine); builder.AppendHtml(HtmlString.NewLine);
return builder; return builder;
} }
@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Html
} }
builder.Append(unencoded); builder.Append(unencoded);
builder.AppendHtml(HtmlEncodedString.NewLine); builder.AppendHtml(HtmlString.NewLine);
return builder; return builder;
} }
@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Html
} }
builder.AppendHtml(content); builder.AppendHtml(content);
builder.AppendHtml(HtmlEncodedString.NewLine); builder.AppendHtml(HtmlString.NewLine);
return builder; return builder;
} }
@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Html
} }
builder.AppendHtml(encoded); builder.AppendHtml(encoded);
builder.AppendHtml(HtmlEncodedString.NewLine); builder.AppendHtml(HtmlString.NewLine);
return builder; return builder;
} }

View File

@ -10,7 +10,7 @@ using System.Text.Encodings.Web;
namespace Microsoft.AspNetCore.Html namespace Microsoft.AspNetCore.Html
{ {
/// <summary> /// <summary>
/// An <see cref="IHtmlContent"/> implementation of composite string formatting /// An <see cref="IHtmlContent"/> implementation of composite string formatting
/// (see https://msdn.microsoft.com/en-us/library/txafckwd(v=vs.110).aspx) which HTML encodes /// (see https://msdn.microsoft.com/en-us/library/txafckwd(v=vs.110).aspx) which HTML encodes
/// formatted arguments. /// formatted arguments.
/// </summary> /// </summary>
@ -107,9 +107,9 @@ namespace Microsoft.AspNetCore.Html
public string Format(string format, object arg, IFormatProvider formatProvider) public string Format(string format, object arg, IFormatProvider formatProvider)
{ {
// These are the cases we need to special case. We trust the HtmlEncodedString or IHtmlContent instance // These are the cases we need to special case. We trust the HtmlString or IHtmlContent instance
// to do the right thing with encoding. // to do the right thing with encoding.
var htmlString = arg as HtmlEncodedString; var htmlString = arg as HtmlString;
if (htmlString != null) if (htmlString != null)
{ {
return htmlString.ToString(); return htmlString.ToString();

View File

@ -10,18 +10,23 @@ namespace Microsoft.AspNetCore.Html
/// <summary> /// <summary>
/// An <see cref="IHtmlContent"/> implementation that wraps an HTML encoded <see cref="string"/>. /// An <see cref="IHtmlContent"/> implementation that wraps an HTML encoded <see cref="string"/>.
/// </summary> /// </summary>
public class HtmlEncodedString : IHtmlContent public class HtmlString : IHtmlContent
{ {
/// <summary> /// <summary>
/// An <see cref="IHtmlContent"/> instance for <see cref="Environment.NewLine"/>. /// An <see cref="HtmlString"/> instance for <see cref="Environment.NewLine"/>.
/// </summary> /// </summary>
public static readonly IHtmlContent NewLine = new HtmlEncodedString(Environment.NewLine); public static readonly HtmlString NewLine = new HtmlString(Environment.NewLine);
/// <summary> /// <summary>
/// Creates a new <see cref="HtmlEncodedString"/>. /// An <see cref="HtmlString"/> instance for <see cref="string.Empty"/>.
/// </summary>
public static readonly HtmlString Empty = new HtmlString(string.Empty);
/// <summary>
/// Creates a new <see cref="HtmlString"/>.
/// </summary> /// </summary>
/// <param name="value">The HTML encoded value.</param> /// <param name="value">The HTML encoded value.</param>
public HtmlEncodedString(string value) public HtmlString(string value)
{ {
Value = value; Value = value;
} }

View File

@ -1,6 +1,6 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"description": "ASP.NET Core HTML abstractions used for building HTML content.\r\nCommonly used types:\r\nMicrosoft.AspNetCore.Html.HtmlEncodedString\r\nMicrosoft.AspNetCore.Html.IHtmlContent", "description": "ASP.NET Core HTML abstractions used for building HTML content.\r\nCommonly used types:\r\nMicrosoft.AspNetCore.Html.HtmlString\r\nMicrosoft.AspNetCore.Html.IHtmlContent",
"packOptions": { "packOptions": {
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -159,13 +159,13 @@ namespace Microsoft.AspNetCore.Html.Test
} }
[Fact] [Fact]
public void Builder_AppendFormat_HtmlEncodedString() public void Builder_AppendFormat_HtmlString()
{ {
// Arrange // Arrange
var builder = new TestHtmlContentBuilder(); var builder = new TestHtmlContentBuilder();
// Act // Act
builder.AppendFormat("{0}!", new HtmlEncodedString("First")); builder.AppendFormat("{0}!", new HtmlString("First"));
// Assert // Assert
Assert.Equal("First!", HtmlContentToString(builder)); Assert.Equal("First!", HtmlContentToString(builder));

View File

@ -54,10 +54,10 @@ namespace Microsoft.AspNetCore.Html
} }
[Fact] [Fact]
public void HtmlFormattableString_WithHtmlEncodedString() public void HtmlFormattableString_WithHtmlString()
{ {
// Arrange // Arrange
var formattableString = new HtmlFormattableString("{0}!", new HtmlEncodedString("First")); var formattableString = new HtmlFormattableString("{0}!", new HtmlString("First"));
// Act // Act
var result = HtmlContentToString(formattableString); var result = HtmlContentToString(formattableString);
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Html
// Arrange // Arrange
var formattableString = new HtmlFormattableString( var formattableString = new HtmlFormattableString(
"Happy {0}, {1}!", "Happy {0}, {1}!",
new HtmlEncodedString("Birthday"), new HtmlString("Birthday"),
new HtmlContentBuilder().Append("Billy")); new HtmlContentBuilder().Append("Billy"));
// Act // Act
@ -100,10 +100,10 @@ namespace Microsoft.AspNetCore.Html
} }
[Fact] [Fact]
public void HtmlFormattableString_WithHtmlEncodedString_AndOffset() public void HtmlFormattableString_WithHtmlString_AndOffset()
{ {
// Arrange // Arrange
var formattableString = new HtmlFormattableString("{0, 20}!", new HtmlEncodedString("First")); var formattableString = new HtmlFormattableString("{0, 20}!", new HtmlString("First"));
// Act // Act
var result = HtmlContentToString(formattableString); var result = HtmlContentToString(formattableString);