Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Removing Generate*() methods. #321

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <summary>
/// Default concrete <see cref="TagHelperContent"/>.
/// </summary>
public class DefaultTagHelperContent : TagHelperContent, ITextWriterCopyable
public class DefaultTagHelperContent : TagHelperContent
{
private readonly BufferEntryCollection _buffer;

Expand Down Expand Up @@ -124,15 +124,6 @@ public override string GetContent()
return string.Join(string.Empty, _buffer);
}

/// <inheritdoc />
public void CopyTo([NotNull] TextWriter writer)
{
foreach (var value in _buffer)
{
writer.Write(value);
}
}

/// <inheritdoc />
public override string ToString()
{
Expand Down

This file was deleted.

126 changes: 3 additions & 123 deletions src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Globalization;
using System.Text;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;

namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
Expand All @@ -15,16 +14,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
public class TagHelperOutput
{
private bool _isTagNameNullOrWhitespace;
private string _tagName;
private readonly IHtmlEncoder _htmlEncoder;
private readonly DefaultTagHelperContent _preContent;
private readonly DefaultTagHelperContent _content;
private readonly DefaultTagHelperContent _postContent;

// Internal for testing
internal TagHelperOutput(string tagName)
: this(tagName, new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase), null)
: this(tagName, new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase))
{
}

Expand All @@ -33,19 +29,15 @@ internal TagHelperOutput(string tagName)
/// </summary>
/// <param name="tagName">The HTML element's tag name.</param>
/// <param name="attributes">The HTML attributes.</param>
/// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/> used
/// to encode HTML attribute values.</param>
public TagHelperOutput(
string tagName,
[NotNull] IDictionary<string, string> attributes,
[NotNull] IHtmlEncoder htmlEncoder)
[NotNull] IDictionary<string, string> attributes)
{
TagName = tagName;
Attributes = new Dictionary<string, string>(attributes, StringComparer.OrdinalIgnoreCase);
_preContent = new DefaultTagHelperContent();
_content = new DefaultTagHelperContent();
_postContent = new DefaultTagHelperContent();
_htmlEncoder = htmlEncoder;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh awesome no longer need this.

You should also remove this: https://github.com/aspnet/Razor/blob/dev/src/Microsoft.AspNet.Razor.Runtime/project.json#L9


/// <summary>
Expand All @@ -54,18 +46,7 @@ public TagHelperOutput(
/// <remarks>
/// A whitespace or <c>null</c> value results in no start or end tag being rendered.
/// </remarks>
public string TagName
{
get
{
return _tagName;
}
set
{
_tagName = value;
_isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(_tagName);
}
}
public string TagName { get; set; }

/// <summary>
/// The HTML element's pre content.
Expand Down Expand Up @@ -125,107 +106,6 @@ public bool IsContentModified
/// </summary>
public IDictionary<string, string> Attributes { get; }

/// <summary>
/// Generates the <see cref="TagHelperOutput"/>'s start tag.
/// </summary>
/// <returns><c>string.Empty</c> if <see cref="TagName"/> is <c>null</c> or whitespace. Otherwise, the
/// <see cref="string"/> representation of the <see cref="TagHelperOutput"/>'s start tag.</returns>
public string GenerateStartTag()
{
// Only render a start tag if the tag name is not whitespace
if (_isTagNameNullOrWhitespace)
{
return string.Empty;
}

var sb = new StringBuilder();

sb.Append('<')
.Append(TagName);

foreach (var attribute in Attributes)
{
var value = _htmlEncoder.HtmlEncode(attribute.Value);
sb.Append(' ')
.Append(attribute.Key)
.Append("=\"")
.Append(value)
.Append('"');
}

if (SelfClosing)
{
sb.Append(" /");
}

sb.Append('>');

return sb.ToString();
}

/// <summary>
/// Generates the <see cref="TagHelperOutput"/>'s <see cref="PreContent"/>.
/// </summary>
/// <returns><c>null</c> if <see cref="TagName"/> is not <c>null</c> or whitespace
/// and <see cref="SelfClosing"/> is <c>true</c>.
/// Otherwise, an <see cref="ITextWriterCopyable"/> containing the <see cref="PreContent"/>.</returns>
public ITextWriterCopyable GeneratePreContent()
{
if (!_isTagNameNullOrWhitespace && SelfClosing)
{
return null;
}

return _preContent;
}

/// <summary>
/// Generates the <see cref="TagHelperOutput"/>'s body.
/// </summary>
/// <returns><c>null</c> if <see cref="TagName"/> is not <c>null</c> or whitespace
/// and <see cref="SelfClosing"/> is <c>true</c>.
/// Otherwise, an <see cref="ITextWriterCopyable"/> containing the <see cref="Content"/>.</returns>
public ITextWriterCopyable GenerateContent()
{
if (!_isTagNameNullOrWhitespace && SelfClosing)
{
return null;
}

return _content;
}

/// <summary>
/// Generates the <see cref="TagHelperOutput"/>'s <see cref="PostContent"/>.
/// </summary>
/// <returns><c>null</c> if <see cref="TagName"/> is not <c>null</c> or whitespace
/// and <see cref="SelfClosing"/> is <c>true</c>.
/// Otherwise, an <see cref="ITextWriterCopyable"/> containing the <see cref="PostContent"/>.</returns>
public ITextWriterCopyable GeneratePostContent()
{
if (!_isTagNameNullOrWhitespace && SelfClosing)
{
return null;
}

return _postContent;
}

/// <summary>
/// Generates the <see cref="TagHelperOutput"/>'s end tag.
/// </summary>
/// <returns><c>string.Empty</c> if <see cref="TagName"/> is <c>null</c> or whitespace. Otherwise, the
/// <see cref="string"/> representation of the <see cref="TagHelperOutput"/>'s end tag.</returns>
public string GenerateEndTag()
{
if (SelfClosing || _isTagNameNullOrWhitespace)
{
return string.Empty;
}

return string.Format(CultureInfo.InvariantCulture, "</{0}>", TagName);
}

/// <summary>
/// Changes <see cref="TagHelperOutput"/> to generate nothing.
/// </summary>
Expand Down
15 changes: 1 addition & 14 deletions src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;

namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
Expand All @@ -13,17 +12,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
public class TagHelperRunner
{
private readonly IHtmlEncoder _htmlEncoder;

/// <summary>
/// Instantiates a new instance of <see cref="TagHelperRunner"/>.
/// </summary>
/// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/> used to encode HTML.</param>
public TagHelperRunner([NotNull] IHtmlEncoder htmlEncoder)
{
_htmlEncoder = htmlEncoder;
}

/// <summary>
/// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s.
/// </summary>
Expand All @@ -40,8 +28,7 @@ public async Task<TagHelperOutput> RunAsync([NotNull] TagHelperExecutionContext
executionContext.GetChildContentAsync);
var tagHelperOutput = new TagHelperOutput(
executionContext.TagName,
executionContext.HTMLAttributes,
_htmlEncoder)
executionContext.HTMLAttributes)
{
SelfClosing = executionContext.SelfClosing,
};
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.AspNet.Razor.Runtime/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"Microsoft.AspNet.Razor": "4.0.0-*",
"Microsoft.Framework.BufferEntryCollection.Internal": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Framework.CopyOnWriteDictionary.Internal": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Framework.WebEncoders.Core": "1.0.0-*"
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
},
"frameworks": {
"net45": { },
Expand Down
Loading