Skip to content

Microsoft.AspNet.Razor.Runtime.TagHelpers renamed to Microsoft.AspNet.Razor.TagHelpers #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
NTaylorMullen opened this issue Oct 22, 2015 · 3 comments

Comments

@NTaylorMullen
Copy link

On the basis of an API review we've decided to move top level TagHelper elements from the Microsoft.AspNet.Razor.Runtime.TagHelpers namespace into the Microsoft.AspNet.Razor.TagHelpers namespace.

Types moved into Microsoft.AspNet.Razor.TagHelpers:

  • DefaultTagHelperContent
  • HtmlAttributeNameAttribute
  • HtmlAttributeNotBoundAttribute
  • HtmlTargetElementAttribute
  • IReadOnlyTagHelperAttribute
  • ITagHelper
  • OutputElementHintAttribute
  • ReadOnlyTagHelperAttributeList
  • RestrictChildrenAttribute
  • TagHelper
  • TagHelperAttribute
  • TagHelperAttributeList
  • TagHelperContent
  • TagHelperContext
  • TagHelperOutput
@NTaylorMullen NTaylorMullen added this to the 1.0.0-rc1 milestone Oct 22, 2015
@aspnet aspnet locked and limited conversation to collaborators Oct 22, 2015
@aspnet aspnet unlocked this conversation Oct 23, 2015
@dougbu
Copy link
Contributor

dougbu commented Oct 23, 2015

For discussion and feedback, please see the related discussion issue aspnet/Razor#583.

@aspnet aspnet locked and limited conversation to collaborators Oct 23, 2015
@dougbu
Copy link
Contributor

dougbu commented Oct 23, 2015

In the RC1 milestone we have also renamed a few IHtmlContentBuilder methods and extension methods. This primarily affects tag helper authors because TagHelperContent implements that interface and many TagHelperOutput properties are of that type.

The change may also affect HTML helper authors because the TagBuilder.InnerHtml property is of type IHtmlContentBuilder.

For example this trivial tag helper creates a correctly-encoded paragraph containing random quotes e.g.

<p><b>It&#39;s Friday!
&lt;!!&gt;
</b>
</p>

Before i.e. when using Beta 8

using System;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;

namespace TagHelperSample.Web.TagHelpers
{
    [HtmlTargetElement("reason", TagStructure = TagStructure.WithoutEndTag)]
    public class ReasonTagHelper : TagHelper
    {
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var possibleReasons = new[]
            {
                "It&#39;s Friday!",
                "I don&#39;t like Mondays.",
                "There&#39;s an &lt;r&gt; in the name of the Month.",
                "Just because."
            };

            var index = new Random().Next(0, possibleReasons.Length);
            var innerContent = new TagBuilder("b");
            innerContent.InnerHtml
                .AppendLineEncoded(possibleReasons[index])
                .AppendLine("<!!>");

            output.Content.SetContent(innerContent);
            output.PostContent.SetContentEncoded(Environment.NewLine);
            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = "p";
        }
    }
}

After

using System;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Razor.TagHelpers;

namespace TagHelperSample.Web.TagHelpers
{
    [HtmlTargetElement("reason", TagStructure = TagStructure.WithoutEndTag)]
    public class ReasonTagHelper : TagHelper
    {
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var possibleReasons = new[]
            {
                "It&#39;s Friday!",
                "I don&#39;t like Mondays.",
                "There&#39;s an &lt;r&gt; in the name of the Month.",
                "Just because."
            };

            var index = new Random().Next(0, possibleReasons.Length);
            var innerContent = new TagBuilder("b");
            innerContent.InnerHtml
                .AppendHtmlLine(possibleReasons[index])
                .AppendLine("<!!>");

            output.Content.SetContent(innerContent);
            output.PostContent.SetHtmlContent(Environment.NewLine);
            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = "p";
        }
    }
}

See aspnet/Mvc#3225 for details of this portion of the RC1 tag helper changes. As before please discuss the changes in aspnet/Razor#583.

@dougbu
Copy link
Contributor

dougbu commented Oct 23, 2015

Updated comment above to correct linked issue. Should be aspnet/Mvc#3225.

Also left out the specific changes to IHtmlContentBuilder:

  • AppendEncoded() renamed to AppendHtml()
  • AppendLineEncoded renamed to AppendHtmlLine()
  • SetContentEncoded() renamed to SetHtmlContent()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants