Remove layout directive.
- Removed all instances of the layout directive from src and test projects. #359
This commit is contained in:
parent
dcee0d2ff7
commit
2d20063ba5
|
|
@ -23,10 +23,5 @@ namespace Microsoft.AspNet.Razor.Editor
|
|||
/// if they do not support it.
|
||||
/// </summary>
|
||||
VirtualPath = 1, // 0000 0001
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that this span's content contains the path to the layout page for this document.
|
||||
/// </summary>
|
||||
LayoutPage = 2, // 0000 0010
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,17 +79,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
Accept(chunk.Children);
|
||||
}
|
||||
|
||||
protected override void Visit(SetLayoutChunk chunk)
|
||||
{
|
||||
if (!Context.Host.DesignTimeMode && !string.IsNullOrEmpty(Context.Host.GeneratedClassContext.LayoutPropertyName))
|
||||
{
|
||||
Writer.Write(Context.Host.GeneratedClassContext.LayoutPropertyName)
|
||||
.Write(" = ")
|
||||
.WriteStringLiteral(chunk.Layout)
|
||||
.WriteLine(";");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Visit(TemplateChunk chunk)
|
||||
{
|
||||
Writer.Write(ItemParameterName).Write(" => ")
|
||||
|
|
|
|||
|
|
@ -119,22 +119,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
chunk.Association.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes code for the given <paramref name="chunk"/>.
|
||||
/// </summary>
|
||||
/// <param name="chunk">The <see cref="SetLayoutChunk"/> to render.</param>
|
||||
/// <remarks>
|
||||
/// Unconditionally adds a <see cref="RazorError"/> to inform user of unexpected <c>@layout</c> directive.
|
||||
/// </remarks>
|
||||
protected override void Visit(SetLayoutChunk chunk)
|
||||
{
|
||||
Context.ErrorSink.OnError(
|
||||
chunk.Association.Start,
|
||||
RazorResources.FormatTagHelpers_Directives_NotSupported_InAttributes(
|
||||
SyntaxConstants.CSharp.LayoutKeyword),
|
||||
chunk.Association.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes code for the given <paramref name="chunk"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -69,10 +69,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
{
|
||||
Visit((RemoveTagHelperChunk)chunk);
|
||||
}
|
||||
else if (chunk is SetLayoutChunk)
|
||||
{
|
||||
Visit((SetLayoutChunk)chunk);
|
||||
}
|
||||
else if (chunk is ResolveUrlChunk)
|
||||
{
|
||||
Visit((ResolveUrlChunk)chunk);
|
||||
|
|
@ -132,7 +128,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
protected abstract void Visit(ResolveUrlChunk chunk);
|
||||
protected abstract void Visit(SetBaseTypeChunk chunk);
|
||||
protected abstract void Visit(TemplateChunk chunk);
|
||||
protected abstract void Visit(SetLayoutChunk chunk);
|
||||
protected abstract void Visit(ExpressionBlockChunk chunk);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
protected override void Visit(TemplateChunk chunk)
|
||||
{
|
||||
}
|
||||
protected override void Visit(SetLayoutChunk chunk)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
{
|
||||
public class SetLayoutChunk : Chunk
|
||||
{
|
||||
public string Layout { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -140,14 +140,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
}, association);
|
||||
}
|
||||
|
||||
public void AddSetLayoutChunk(string layout, SyntaxTreeNode association)
|
||||
{
|
||||
AddChunk(new SetLayoutChunk
|
||||
{
|
||||
Layout = layout
|
||||
}, association);
|
||||
}
|
||||
|
||||
public void AddSetBaseTypeChunk(string typeName, SyntaxTreeNode association)
|
||||
{
|
||||
AddChunk(new SetBaseTypeChunk
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
public static readonly string DefaultWriteMethodName = "Write";
|
||||
public static readonly string DefaultWriteLiteralMethodName = "WriteLiteral";
|
||||
public static readonly string DefaultExecuteMethodName = "ExecuteAsync";
|
||||
public static readonly string DefaultLayoutPropertyName = "Layout";
|
||||
public static readonly string DefaultWriteAttributeMethodName = "WriteAttribute";
|
||||
public static readonly string DefaultWriteAttributeToMethodName = "WriteAttributeTo";
|
||||
|
||||
|
|
@ -57,7 +56,6 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
TemplateTypeName = null;
|
||||
DefineSectionMethodName = null;
|
||||
|
||||
LayoutPropertyName = DefaultLayoutPropertyName;
|
||||
WriteAttributeMethodName = DefaultWriteAttributeMethodName;
|
||||
WriteAttributeToMethodName = DefaultWriteAttributeToMethodName;
|
||||
}
|
||||
|
|
@ -132,7 +130,6 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
// Optional Items
|
||||
public string BeginContextMethodName { get; set; }
|
||||
public string EndContextMethodName { get; set; }
|
||||
public string LayoutPropertyName { get; set; }
|
||||
public string DefineSectionMethodName { get; set; }
|
||||
public string TemplateTypeName { get; set; }
|
||||
public string WriteAttributeMethodName { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
{
|
||||
public class SetLayoutCodeGenerator : SpanCodeGenerator
|
||||
{
|
||||
public SetLayoutCodeGenerator(string layoutPath)
|
||||
{
|
||||
LayoutPath = layoutPath;
|
||||
}
|
||||
|
||||
public string LayoutPath { get; set; }
|
||||
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
{
|
||||
context.CodeTreeBuilder.AddSetLayoutChunk(LayoutPath, target);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Layout: " + LayoutPath;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as SetLayoutCodeGenerator;
|
||||
return other != null && string.Equals(other.LayoutPath, LayoutPath, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return LayoutPath.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
MapDirectives(InheritsDirective, SyntaxConstants.CSharp.InheritsKeyword);
|
||||
MapDirectives(FunctionsDirective, SyntaxConstants.CSharp.FunctionsKeyword);
|
||||
MapDirectives(SectionDirective, SyntaxConstants.CSharp.SectionKeyword);
|
||||
MapDirectives(LayoutDirective, SyntaxConstants.CSharp.LayoutKeyword);
|
||||
}
|
||||
|
||||
protected virtual void TagHelperPrefixDirective()
|
||||
|
|
@ -43,31 +42,11 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
protected virtual void RemoveTagHelperDirective()
|
||||
{
|
||||
TagHelperDirective(
|
||||
SyntaxConstants.CSharp.RemoveTagHelperKeyword,
|
||||
SyntaxConstants.CSharp.RemoveTagHelperKeyword,
|
||||
lookupText =>
|
||||
new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: true, lookupText: lookupText));
|
||||
}
|
||||
|
||||
protected virtual void LayoutDirective()
|
||||
{
|
||||
AssertDirective(SyntaxConstants.CSharp.LayoutKeyword);
|
||||
AcceptAndMoveNext();
|
||||
Context.CurrentBlock.Type = BlockType.Directive;
|
||||
|
||||
// Accept spaces, but not newlines
|
||||
var foundSomeWhitespace = At(CSharpSymbolType.WhiteSpace);
|
||||
AcceptWhile(CSharpSymbolType.WhiteSpace);
|
||||
Output(SpanKind.MetaCode, foundSomeWhitespace ? AcceptedCharacters.None : AcceptedCharacters.Any);
|
||||
|
||||
// First non-whitespace character starts the Layout Page, then newline ends it
|
||||
AcceptUntil(CSharpSymbolType.NewLine);
|
||||
Span.CodeGenerator = new SetLayoutCodeGenerator(Span.GetContent());
|
||||
Span.EditHandler.EditorHints = EditorHints.LayoutPage | EditorHints.VirtualPath;
|
||||
var foundNewline = Optional(CSharpSymbolType.NewLine);
|
||||
AddMarkerSymbolIfNecessary();
|
||||
Output(SpanKind.MetaCode, foundNewline ? AcceptedCharacters.None : AcceptedCharacters.AnyExceptNewline);
|
||||
}
|
||||
|
||||
protected virtual void SectionDirective()
|
||||
{
|
||||
var nested = Context.IsWithin(BlockType.Section);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
"functions",
|
||||
"namespace",
|
||||
"class",
|
||||
"layout",
|
||||
};
|
||||
|
||||
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
public static readonly string ElseIfKeyword = "else if";
|
||||
public static readonly string NamespaceKeyword = "namespace";
|
||||
public static readonly string ClassKeyword = "class";
|
||||
public static readonly string LayoutKeyword = "layout";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
|||
[InlineData("Sections")]
|
||||
[InlineData("RazorComments")]
|
||||
[InlineData("InlineBlocks")]
|
||||
[InlineData("LayoutDirective")]
|
||||
[InlineData("ConditionalAttributes")]
|
||||
[InlineData("ResolveUrl")]
|
||||
[InlineData("Await")]
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
|||
inputStream.Position = 0;
|
||||
var reader = new StreamReader(inputStream);
|
||||
|
||||
// Normalize newlines to be \r\n. This is to ensure when running tests cross plat the final test output
|
||||
// Normalize newlines to be \r\n. This is to ensure when running tests cross plat the final test output
|
||||
// is compared against test files in a normalized fashion.
|
||||
var fileContents = reader.ReadToEnd().Replace(Environment.NewLine, "\r\n");
|
||||
|
||||
|
|
@ -150,7 +150,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
|||
"Instrumentation.EndContext",
|
||||
new GeneratedTagHelperContext())
|
||||
{
|
||||
LayoutPropertyName = "Layout",
|
||||
ResolveUrlMethodName = "Href"
|
||||
};
|
||||
if (hostConfig != null)
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Editor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Test.Framework;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||
{
|
||||
public class CSharpLayoutDirectiveTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Layout")]
|
||||
[InlineData("LAYOUT")]
|
||||
[InlineData("layOut")]
|
||||
[InlineData("LayOut")]
|
||||
private void LayoutKeywordIsCaseSensitive(string word)
|
||||
{
|
||||
ParseBlockTest(word,
|
||||
new ExpressionBlock(
|
||||
Factory.Code(word)
|
||||
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
|
||||
.Accepts(AcceptedCharacters.NonWhiteSpace)
|
||||
));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutDirectiveAcceptsAllTextToEndOfLine()
|
||||
{
|
||||
ParseBlockTest("@layout Foo Bar Baz",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
||||
Factory.MetaCode("Foo Bar Baz")
|
||||
.With(new SetLayoutCodeGenerator("Foo Bar Baz"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline)
|
||||
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutDirectiveAcceptsAnyIfNoWhitespaceFollowingLayoutKeyword()
|
||||
{
|
||||
ParseBlockTest("@layout",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("layout")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutDirectiveOutputsMarkerSpanIfAnyWhitespaceAfterLayoutKeyword()
|
||||
{
|
||||
ParseBlockTest("@layout ",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
||||
Factory.EmptyCSharp()
|
||||
.AsMetaCode()
|
||||
.With(new SetLayoutCodeGenerator(string.Empty))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline)
|
||||
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutDirectiveAcceptsTrailingNewlineButDoesNotIncludeItInLayoutPath()
|
||||
{
|
||||
ParseBlockTest("@layout Foo" + Environment.NewLine,
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
||||
Factory.MetaCode("Foo" + Environment.NewLine)
|
||||
.With(new SetLayoutCodeGenerator("Foo"))
|
||||
.Accepts(AcceptedCharacters.None)
|
||||
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutDirectiveCorrectlyRestoresContextAfterCompleting()
|
||||
{
|
||||
ParseDocumentTest("@layout Foo" + Environment.NewLine
|
||||
+ "@foo",
|
||||
new MarkupBlock(
|
||||
Factory.EmptyHtml(),
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
||||
Factory.MetaCode("Foo" + Environment.NewLine)
|
||||
.With(new SetLayoutCodeGenerator("Foo"))
|
||||
.Accepts(AcceptedCharacters.None)
|
||||
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
||||
),
|
||||
Factory.EmptyHtml(),
|
||||
new ExpressionBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.Code("foo")
|
||||
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)
|
||||
.Accepts(AcceptedCharacters.NonWhiteSpace)),
|
||||
Factory.EmptyHtml()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -653,11 +653,5 @@ namespace Microsoft.AspNet.Razor.Test.Parser.PartialParsing
|
|||
{
|
||||
RunTypeKeywordTest("class");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImplicitExpressionCorrectlyTriggersReparseIfLayoutKeywordTyped()
|
||||
{
|
||||
RunTypeKeywordTest("layout");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
#pragma checksum "LayoutDirective.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "018a686988146d5eb7d51f83c22f820e66b276e0"
|
||||
namespace TestOutput
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class LayoutDirective
|
||||
{
|
||||
#line hidden
|
||||
public LayoutDirective()
|
||||
{
|
||||
}
|
||||
|
||||
#pragma warning disable 1998
|
||||
public override async Task ExecuteAsync()
|
||||
{
|
||||
Layout = "~/Foo/Bar/Baz";
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
@layout ~/Foo/Bar/Baz
|
||||
Loading…
Reference in New Issue