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

Commit

Permalink
Camel-case tag helper directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dougbu committed Feb 13, 2015
1 parent e14dbdf commit 1b9b78b
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
public class TagHelperDescriptorResolver : ITagHelperDescriptorResolver
{
private static readonly Dictionary<TagHelperDirectiveType, string> _directiveNames =
new Dictionary<TagHelperDirectiveType, string>
{
{ TagHelperDirectiveType.AddTagHelper, SyntaxConstants.CSharp.AddTagHelperKeyword },
{ TagHelperDirectiveType.RemoveTagHelper, SyntaxConstants.CSharp.RemoveTagHelperKeyword },
};

private readonly TagHelperTypeResolver _typeResolver;

// internal for testing
Expand Down Expand Up @@ -67,8 +74,7 @@ public IEnumerable<TagHelperDescriptor> Resolve([NotNull] TagHelperDescriptorRes
}
catch (Exception ex)
{
var directiveName = "@" + directiveDescriptor.DirectiveType.ToString().ToLowerInvariant();

var directiveName = "@" + _directiveNames[directiveDescriptor.DirectiveType];
context.ErrorSink.OnError(
directiveDescriptor.Location,
Resources.FormatTagHelperDescriptorResolver_EncounteredUnexpectedError(
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static class SyntaxConstants
public static class CSharp
{
public static readonly int UsingKeywordLength = 5;
public static readonly string AddTagHelperKeyword = "addtaghelper";
public static readonly string RemoveTagHelperKeyword = "removetaghelper";
public static readonly string AddTagHelperKeyword = "addTagHelper";
public static readonly string RemoveTagHelperKeyword = "removeTagHelper";
public static readonly string InheritsKeyword = "inherits";
public static readonly string FunctionsKeyword = "functions";
public static readonly string SectionKeyword = "section";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Microsoft.AspNet.Razor.TagHelpers
public enum TagHelperDirectiveType
{
/// <summary>
/// An @addtaghelper directive.
/// An @addTagHelper directive.
/// </summary>
AddTagHelper,

/// <summary>
/// A @removetaghelper directive.
/// A @removeTagHelper directive.
/// </summary>
RemoveTagHelper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ public void DescriptorResolver_UnderstandsUnexpectedExceptions_DoesNotThrow()
{
// Arrange
var expectedErrorMessage = "Encountered an unexpected error when attempting to resolve tag helper " +
"directive '@addtaghelper' with value 'A custom, lookup text'. Error: A " +
"directive '@addTagHelper' with value 'A custom, lookup text'. Error: A " +
"custom exception";
var documentLocation = new SourceLocation(1, 2, 3);
var directiveType = TagHelperDirectiveType.AddTagHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IEnumerable<TagHelperDescriptor> Resolve(TagHelperDescriptorResolutionCon
{
if (directiveDescriptor.DirectiveType == TagHelperDirectiveType.RemoveTagHelper)
{
// We don't yet support "typeName, assemblyName" for @removetaghelper in this test class. Will
// We don't yet support "typeName, assemblyName" for @removeTagHelper in this test class. Will
// add that ability and add the corresponding end-to-end test verification in:
// https://github.com/aspnet/Razor/issues/222
descriptors = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CSharpDirectivesTest : CsHtmlCodeParserTestBase
[Fact]
public void RemoveTagHelperDirective_Succeeds()
{
ParseBlockTest("@removetaghelper \"Foo\"",
ParseBlockTest("@removeTagHelper \"Foo\"",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -26,7 +26,7 @@ public void RemoveTagHelperDirective_Succeeds()
[Fact]
public void RemoveTagHelperDirective_SupportsSpaces()
{
ParseBlockTest("@removetaghelper \" Foo, Bar \" ",
ParseBlockTest("@removeTagHelper \" Foo, Bar \" ",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -37,7 +37,7 @@ public void RemoveTagHelperDirective_SupportsSpaces()
[Fact]
public void RemoveTagHelperDirective_RequiresValue()
{
ParseBlockTest("@removetaghelper ",
ParseBlockTest("@removeTagHelper ",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -52,7 +52,7 @@ public void RemoveTagHelperDirective_RequiresValue()
[Fact]
public void RemoveTagHelperDirective_StartQuoteRequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@removetaghelper \"Foo",
ParseBlockTest("@removeTagHelper \"Foo",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -70,7 +70,7 @@ public void RemoveTagHelperDirective_StartQuoteRequiresDoubleQuotesAroundValue()
[Fact]
public void RemoveTagHelperDirective_EndQuoteRequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@removetaghelper Foo\"",
ParseBlockTest("@removeTagHelper Foo\"",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -88,7 +88,7 @@ public void RemoveTagHelperDirective_EndQuoteRequiresDoubleQuotesAroundValue()
[Fact]
public void RemoveTagHelperDirective_RequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@removetaghelper Foo",
ParseBlockTest("@removeTagHelper Foo",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
Expand All @@ -103,7 +103,7 @@ public void RemoveTagHelperDirective_RequiresDoubleQuotesAroundValue()
[Fact]
public void AddTagHelperDirective_Succeeds()
{
ParseBlockTest("@addtaghelper \"Foo\"",
ParseBlockTest("@addTagHelper \"Foo\"",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand All @@ -114,7 +114,7 @@ public void AddTagHelperDirective_Succeeds()
[Fact]
public void AddTagHelperDirectiveSupportsSpaces()
{
ParseBlockTest("@addtaghelper \" Foo, Bar \" ",
ParseBlockTest("@addTagHelper \" Foo, Bar \" ",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand All @@ -125,7 +125,7 @@ public void AddTagHelperDirectiveSupportsSpaces()
[Fact]
public void AddTagHelperDirectiveRequiresValue()
{
ParseBlockTest("@addtaghelper ",
ParseBlockTest("@addTagHelper ",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand All @@ -139,7 +139,7 @@ public void AddTagHelperDirectiveRequiresValue()
[Fact]
public void AddTagHelperDirectiveWithStartQuoteRequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@addtaghelper \"Foo",
ParseBlockTest("@addTagHelper \"Foo",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand All @@ -157,7 +157,7 @@ public void AddTagHelperDirectiveWithStartQuoteRequiresDoubleQuotesAroundValue()
[Fact]
public void AddTagHelperDirectiveWithEndQuoteRequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@addtaghelper Foo\"",
ParseBlockTest("@addTagHelper Foo\"",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand All @@ -175,7 +175,7 @@ public void AddTagHelperDirectiveWithEndQuoteRequiresDoubleQuotesAroundValue()
[Fact]
public void AddTagHelperDirectiveRequiresDoubleQuotesAroundValue()
{
ParseBlockTest("@addtaghelper Foo",
ParseBlockTest("@addTagHelper Foo",
new DirectiveBlock(
Factory.CodeTransition(),
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15cf58241a278a7bfadfefa9ef44742b3fd1074e"
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ef59308f8b0456ad2f49a08604e8ba36ca11a4b2"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "BasicTagHelpers.RemoveTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15609cf7c0bff12794453caa4d04e6f5a562e6ed"
#pragma checksum "BasicTagHelpers.RemoveTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "48dc91408dc7bf6406139461afa4867d176adaf7"
namespace TestOutput
{
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15cf58241a278a7bfadfefa9ef44742b3fd1074e"
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ef59308f8b0456ad2f49a08604e8ba36ca11a4b2"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "b7d9a4dd63a71dcfc8c97a5ee7598214e387e1b6"
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "34039b21327142e9261c7acb3bcd0a4365e0cfa2"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "EmptyAttributeTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "828f744feb52d497814b7a018f817f31d92085ce"
#pragma checksum "EmptyAttributeTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "20e2b8804c3af56e185a59be9d21ab33fb33774f"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "EscapedTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f1f93dcc77691cc626112fe0475f5c350e5fa802"
#pragma checksum "EscapedTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "34a293044db8d18ae2c99fc1e4231e9e7ee96137"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "72db799463dab7865f759d0e3ed3660485d7871d"
#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "60ad52f4a16ebc0499d729dfd4b79358331907f4"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "daf9e656da8fef546fe782b39687a5029a852c48"
#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5f28fe84901bdeb20db8296b1da1e9a1f1da1023"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f7dda6348dbd0043f1421eacbbdce3d3c4f21d75"
#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f228c34bdcee3e7f64bc3de14469d11a61efb825"
namespace TestOutput
{
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@addtaghelper "something, nice"
@removetaghelper "doesntmatter, nice"
@addTagHelper "something, nice"
@removeTagHelper "doesntmatter, nice"

<div class="randomNonTagHelperAttribute">
<p class="Hello World">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"

<div class="randomNonTagHelperAttribute">
<p class="Hello World">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"

@if (true)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something"
@addTagHelper "something"

<div>
<input type= checked=""class="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something"
@addTagHelper "something"

<!div class="randomNonTagHelperAttribute">
<!p class="Hello World" @DateTime.Now>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@removetaghelper "something, nice"
@removeTagHelper "something, nice"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"

<p class="Hello World" age="1337">Body of Tag</p>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"

@helper MyHelper(string val)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@addtaghelper "something, nice"
@addTagHelper "something, nice"

@{
var code = "some code";
Expand Down

0 comments on commit 1b9b78b

Please sign in to comment.