React to aspnet/Razor#140
- ICodeTreeCache => IChunkTreeCache - ModelCodeGenerator => ModelChunkGenerator - MvcCSharpCodeBuilder => MvcCSharpCodeGenerator - Updated files that used Razor resources that are now in different namespaces. - Updated variable names to account for Razor renames. aspnet/Razor#140
This commit is contained in:
parent
70b56f157c
commit
94553703a2
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Razor.Host;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// </summary>
|
||||
/// <typeparam name="TChunk">The type to cast to.</typeparam>
|
||||
/// <param name="chunk">The chunk to cast.</param>
|
||||
/// <returns>The <paramref name="Chunk"/> cast to <typeparamref name="TChunk"/>.</returns>
|
||||
/// <returns>The <paramref name="chunk"/> cast to <typeparamref name="TChunk"/>.</returns>
|
||||
/// <exception cref="ArgumentException"><paramref name="chunk"/> is not an instance of
|
||||
/// <typeparamref name="TChunk"/>.</exception>
|
||||
public static TChunk EnsureChunk<TChunk>([NotNull] Chunk chunk)
|
||||
|
|
@ -40,31 +40,32 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="ModelChunk"/> used to determine the model name for the page generated
|
||||
/// using the specified <paramref name="codeTree"/>
|
||||
/// using the specified <paramref name="chunkTree"/>
|
||||
/// </summary>
|
||||
/// <param name="codeTree">The <see cref="CodeTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
|
||||
/// <returns>The last <see cref="ModelChunk"/> in the <see cref="CodeTree"/> if found, null otherwise.
|
||||
/// <param name="chunkTree">The <see cref="ChunkTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
|
||||
/// <returns>The last <see cref="ModelChunk"/> in the <see cref="ChunkTree"/> if found, <c>null</c> otherwise.
|
||||
/// </returns>
|
||||
public static ModelChunk GetModelChunk([NotNull] CodeTree codeTree)
|
||||
public static ModelChunk GetModelChunk([NotNull] ChunkTree chunkTree)
|
||||
{
|
||||
// If there's more than 1 model chunk there will be a Razor error BUT we want intellisense to show up on
|
||||
// the current model chunk that the user is typing.
|
||||
return codeTree.Chunks
|
||||
return chunkTree.Chunks
|
||||
.OfType<ModelChunk>()
|
||||
.LastOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the type name of the Model specified via a <see cref="ModelChunk"/> in the
|
||||
/// <paramref name="codeTree"/> if specified or the default model type.
|
||||
/// <paramref name="chunkTree"/> if specified or the default model type.
|
||||
/// </summary>
|
||||
/// <param name="codeTree">The <see cref="CodeTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
|
||||
/// <param name="chunkTree">The <see cref="ChunkTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
|
||||
/// <param name="defaultModelName">The <see cref="Type"/> name of the default model.</param>
|
||||
/// <returns>The model type name for the generated page.</returns>
|
||||
public static string GetModelTypeName([NotNull] CodeTree codeTree,
|
||||
[NotNull] string defaultModelName)
|
||||
public static string GetModelTypeName(
|
||||
[NotNull] ChunkTree chunkTree,
|
||||
[NotNull] string defaultModelName)
|
||||
{
|
||||
var modelChunk = GetModelChunk(codeTree);
|
||||
var modelChunk = GetModelChunk(chunkTree);
|
||||
return modelChunk != null ? modelChunk.ModelType : defaultModelName;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
|
|
@ -20,36 +20,37 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
private readonly MvcRazorHost _razorHost;
|
||||
private readonly IReadOnlyList<Chunk> _defaultInheritedChunks;
|
||||
private readonly ICodeTreeCache _codeTreeCache;
|
||||
private readonly IChunkTreeCache _chunkTreeCache;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ChunkInheritanceUtility"/>.
|
||||
/// </summary>
|
||||
/// <param name="razorHost">The <see cref="MvcRazorHost"/> used to parse <c>_ViewImports</c> pages.</param>
|
||||
/// <param name="codeTreeCache"><see cref="ICodeTreeCache"/> that caches <see cref="CodeTree"/> instances.
|
||||
/// <param name="chunkTreeCache"><see cref="IChunkTreeCache"/> that caches <see cref="ChunkTree"/> instances.
|
||||
/// </param>
|
||||
/// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param>
|
||||
public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost,
|
||||
[NotNull] ICodeTreeCache codeTreeCache,
|
||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
public ChunkInheritanceUtility(
|
||||
[NotNull] MvcRazorHost razorHost,
|
||||
[NotNull] IChunkTreeCache chunkTreeCache,
|
||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
{
|
||||
_razorHost = razorHost;
|
||||
_defaultInheritedChunks = defaultInheritedChunks;
|
||||
_codeTreeCache = codeTreeCache;
|
||||
_chunkTreeCache = chunkTreeCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each
|
||||
/// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="ChunkTree"/> for each
|
||||
/// <c>_ViewImports</c> that is applicable to the page located at <paramref name="pagePath"/>. The list is
|
||||
/// ordered so that the <see cref="CodeTree"/> for the <c>_ViewImports</c> closest to the
|
||||
/// ordered so that the <see cref="ChunkTree"/> for the <c>_ViewImports</c> closest to the
|
||||
/// <paramref name="pagePath"/> in the file system appears first.
|
||||
/// </summary>
|
||||
/// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{CodeTree}"/> of parsed <c>_ViewImports</c>
|
||||
/// <see cref="CodeTree"/>s.</returns>
|
||||
public virtual IReadOnlyList<CodeTree> GetInheritedCodeTrees([NotNull] string pagePath)
|
||||
/// <returns>A <see cref="IReadOnlyList{ChunkTree}"/> of parsed <c>_ViewImports</c>
|
||||
/// <see cref="ChunkTree"/>s.</returns>
|
||||
public virtual IReadOnlyList<ChunkTree> GetInheritedChunkTrees([NotNull] string pagePath)
|
||||
{
|
||||
var inheritedCodeTrees = new List<CodeTree>();
|
||||
var inheritedChunkTrees = new List<ChunkTree>();
|
||||
var templateEngine = new RazorTemplateEngine(_razorHost);
|
||||
foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath))
|
||||
{
|
||||
|
|
@ -57,38 +58,41 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
// Since the parsing of a _ViewImports would cause parent _ViewImports to be parsed
|
||||
// we need to ensure the paths are app-relative to allow the GetGlobalFileLocations
|
||||
// for the current _ViewImports to succeed.
|
||||
var codeTree = _codeTreeCache.GetOrAdd(viewImportsPath,
|
||||
fileInfo => ParseViewFile(templateEngine,
|
||||
fileInfo,
|
||||
viewImportsPath));
|
||||
var chunkTree = _chunkTreeCache.GetOrAdd(
|
||||
viewImportsPath,
|
||||
fileInfo => ParseViewFile(
|
||||
templateEngine,
|
||||
fileInfo,
|
||||
viewImportsPath));
|
||||
|
||||
if (codeTree != null)
|
||||
if (chunkTree != null)
|
||||
{
|
||||
inheritedCodeTrees.Add(codeTree);
|
||||
inheritedChunkTrees.Add(chunkTree);
|
||||
}
|
||||
}
|
||||
|
||||
return inheritedCodeTrees;
|
||||
return inheritedChunkTrees;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges <see cref="Chunk"/> inherited by default and <see cref="CodeTree"/> instances produced by parsing
|
||||
/// <c>_ViewImports</c> files into the specified <paramref name="codeTree"/>.
|
||||
/// Merges <see cref="Chunk"/> inherited by default and <see cref="ChunkTree"/> instances produced by parsing
|
||||
/// <c>_ViewImports</c> files into the specified <paramref name="chunkTree"/>.
|
||||
/// </summary>
|
||||
/// <param name="codeTree">The <see cref="CodeTree"/> to merge in to.</param>
|
||||
/// <param name="inheritedCodeTrees"><see cref="IReadOnlyList{CodeTree}"/> inherited from <c>_ViewImports</c>
|
||||
/// <param name="chunkTree">The <see cref="ChunkTree"/> to merge in to.</param>
|
||||
/// <param name="inheritedChunkTrees"><see cref="IReadOnlyList{ChunkTree}"/> inherited from <c>_ViewImports</c>
|
||||
/// files.</param>
|
||||
/// <param name="defaultModel">The list of chunks to merge.</param>
|
||||
public void MergeInheritedCodeTrees([NotNull] CodeTree codeTree,
|
||||
[NotNull] IReadOnlyList<CodeTree> inheritedCodeTrees,
|
||||
string defaultModel)
|
||||
public void MergeInheritedChunkTrees(
|
||||
[NotNull] ChunkTree chunkTree,
|
||||
[NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
string defaultModel)
|
||||
{
|
||||
var mergerMappings = GetMergerMappings(codeTree, defaultModel);
|
||||
var mergerMappings = GetMergerMappings(chunkTree, defaultModel);
|
||||
IChunkMerger merger;
|
||||
|
||||
// We merge chunks into the codeTree in two passes. In the first pass, we traverse the CodeTree visiting
|
||||
// We merge chunks into the ChunkTree in two passes. In the first pass, we traverse the ChunkTree visiting
|
||||
// a mapped IChunkMerger for types that are registered.
|
||||
foreach (var chunk in codeTree.Chunks)
|
||||
foreach (var chunk in chunkTree.Chunks)
|
||||
{
|
||||
if (mergerMappings.TryGetValue(chunk.GetType(), out merger))
|
||||
{
|
||||
|
|
@ -97,25 +101,25 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
}
|
||||
|
||||
// In the second phase we invoke IChunkMerger.Merge for each chunk that has a mapped merger.
|
||||
// During this phase, the merger can either add to the CodeTree or ignore the chunk based on the merging
|
||||
// During this phase, the merger can either add to the ChunkTree or ignore the chunk based on the merging
|
||||
// rules.
|
||||
// Read the chunks outside in - that is chunks from the _ViewImports closest to the page get merged in first
|
||||
// and the furthest one last. This allows the merger to ignore a directive like @model that was previously
|
||||
// seen.
|
||||
var chunksToMerge = inheritedCodeTrees.SelectMany(tree => tree.Chunks)
|
||||
var chunksToMerge = inheritedChunkTrees.SelectMany(tree => tree.Chunks)
|
||||
.Concat(_defaultInheritedChunks);
|
||||
foreach (var chunk in chunksToMerge)
|
||||
{
|
||||
if (mergerMappings.TryGetValue(chunk.GetType(), out merger))
|
||||
{
|
||||
merger.Merge(codeTree, chunk);
|
||||
merger.Merge(chunkTree, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<Type, IChunkMerger> GetMergerMappings(CodeTree codeTree, string defaultModel)
|
||||
private static Dictionary<Type, IChunkMerger> GetMergerMappings(ChunkTree chunkTree, string defaultModel)
|
||||
{
|
||||
var modelType = ChunkHelper.GetModelTypeName(codeTree, defaultModel);
|
||||
var modelType = ChunkHelper.GetModelTypeName(chunkTree, defaultModel);
|
||||
return new Dictionary<Type, IChunkMerger>
|
||||
{
|
||||
{ typeof(UsingChunk), new UsingChunkMerger() },
|
||||
|
|
@ -124,9 +128,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
};
|
||||
}
|
||||
|
||||
private static CodeTree ParseViewFile(RazorTemplateEngine engine,
|
||||
IFileInfo fileInfo,
|
||||
string viewImportsPath)
|
||||
private static ChunkTree ParseViewFile(
|
||||
RazorTemplateEngine engine,
|
||||
IFileInfo fileInfo,
|
||||
string viewImportsPath)
|
||||
{
|
||||
using (var stream = fileInfo.CreateReadStream())
|
||||
{
|
||||
|
|
@ -135,15 +140,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
var parseResults = engine.ParseTemplate(streamReader, viewImportsPath);
|
||||
var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
|
||||
var language = engine.Host.CodeLanguage;
|
||||
var codeGenerator = language.CreateCodeGenerator(className,
|
||||
engine.Host.DefaultNamespace,
|
||||
viewImportsPath,
|
||||
engine.Host);
|
||||
codeGenerator.Visit(parseResults);
|
||||
var chunkGenerator = language.CreateChunkGenerator(
|
||||
className,
|
||||
engine.Host.DefaultNamespace,
|
||||
viewImportsPath,
|
||||
engine.Host);
|
||||
chunkGenerator.Visit(parseResults);
|
||||
|
||||
// Rewrite the location of inherited chunks so they point to the global import file.
|
||||
var codeTree = codeGenerator.Context.CodeTreeBuilder.CodeTree;
|
||||
foreach (var chunk in codeTree.Chunks)
|
||||
var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree;
|
||||
foreach (var chunk in chunkTree.Chunks)
|
||||
{
|
||||
chunk.Start = new SourceLocation(
|
||||
viewImportsPath,
|
||||
|
|
@ -152,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
chunk.Start.CharacterIndex);
|
||||
}
|
||||
|
||||
return codeTree;
|
||||
return chunkTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of <see cref="ICodeTreeCache"/>.
|
||||
/// Default implementation of <see cref="IChunkTreeCache"/>.
|
||||
/// </summary>
|
||||
public class DefaultCodeTreeCache : ICodeTreeCache
|
||||
public class DefaultChunkTreeCache : IChunkTreeCache
|
||||
{
|
||||
private static readonly MemoryCacheOptions MemoryCacheOptions = new MemoryCacheOptions
|
||||
{
|
||||
|
|
@ -20,31 +20,32 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
};
|
||||
private static readonly TimeSpan SlidingExpirationDuration = TimeSpan.FromMinutes(1);
|
||||
private readonly IFileProvider _fileProvider;
|
||||
private readonly IMemoryCache _codeTreeCache;
|
||||
private readonly IMemoryCache _chunkTreeCache;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="DefaultCodeTreeCache"/>.
|
||||
/// Initializes a new instance of <see cref="DefaultChunkTreeCache"/>.
|
||||
/// </summary>
|
||||
/// <param name="fileProvider">The application's <see cref="IFileProvider"/>.</param>
|
||||
public DefaultCodeTreeCache(IFileProvider fileProvider)
|
||||
public DefaultChunkTreeCache(IFileProvider fileProvider)
|
||||
: this(fileProvider, MemoryCacheOptions)
|
||||
{
|
||||
}
|
||||
|
||||
// Internal for unit testing
|
||||
internal DefaultCodeTreeCache(IFileProvider fileProvider,
|
||||
internal DefaultChunkTreeCache(IFileProvider fileProvider,
|
||||
MemoryCacheOptions options)
|
||||
{
|
||||
_fileProvider = fileProvider;
|
||||
_codeTreeCache = new MemoryCache(options);
|
||||
_chunkTreeCache = new MemoryCache(options);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeTree GetOrAdd([NotNull] string pagePath,
|
||||
[NotNull] Func<IFileInfo, CodeTree> getCodeTree)
|
||||
public ChunkTree GetOrAdd(
|
||||
[NotNull] string pagePath,
|
||||
[NotNull] Func<IFileInfo, ChunkTree> getChunkTree)
|
||||
{
|
||||
CodeTree codeTree;
|
||||
if (!_codeTreeCache.TryGetValue(pagePath, out codeTree))
|
||||
ChunkTree chunkTree;
|
||||
if (!_chunkTreeCache.TryGetValue(pagePath, out chunkTree))
|
||||
{
|
||||
// GetOrAdd is invoked for each _GlobalImport that might potentially exist in the path.
|
||||
// We can avoid performing file system lookups for files that do not exist by caching
|
||||
|
|
@ -55,13 +56,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
.SetSlidingExpiration(SlidingExpirationDuration);
|
||||
|
||||
var file = _fileProvider.GetFileInfo(pagePath);
|
||||
codeTree = file.Exists ? getCodeTree(file) : null;
|
||||
chunkTree = file.Exists ? getChunkTree(file) : null;
|
||||
|
||||
|
||||
_codeTreeCache.Set(pagePath, codeTree, options);
|
||||
_chunkTreeCache.Set(pagePath, chunkTree, options);
|
||||
}
|
||||
|
||||
return codeTree;
|
||||
return chunkTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -11,16 +11,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
public interface IChunkMerger
|
||||
{
|
||||
/// <summary>
|
||||
/// Visits a <see cref="Chunk"/> from the <see cref="CodeTree"/> to merge into.
|
||||
/// Visits a <see cref="Chunk"/> from the <see cref="ChunkTree"/> to merge into.
|
||||
/// </summary>
|
||||
/// <param name="chunk">A <see cref="Chunk"/> from the tree.</param>
|
||||
void VisitChunk(Chunk chunk);
|
||||
|
||||
/// <summary>
|
||||
/// Merges an inherited <see cref="Chunk"/> into the <see cref="CodeTree"/>.
|
||||
/// Merges an inherited <see cref="Chunk"/> into the <see cref="ChunkTree"/>.
|
||||
/// </summary>
|
||||
/// <param name="codeTree">The <see cref="CodeTree"/> to merge into.</param>
|
||||
/// <param name="ChunkTree">The <see cref="ChunkTree"/> to merge into.</param>
|
||||
/// <param name="chunk">The <see cref="Chunk"/> to merge.</param>
|
||||
void Merge(CodeTree codeTree, Chunk chunk);
|
||||
void Merge(ChunkTree chunkTree, Chunk chunk);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) .NET Foundation. 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.FileProviders;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
/// <summary>
|
||||
/// A cache for parsed <see cref="ChunkTree"/>s.
|
||||
/// </summary>
|
||||
public interface IChunkTreeCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Get an existing <see cref="ChunkTree"/>, or create and add a new one if it is
|
||||
/// not available in the cache or is expired.
|
||||
/// </summary>
|
||||
/// <param name="pagePath">The application relative path of the Razor page.</param>
|
||||
/// <param name="getChunkTree">A delegate that creates a new <see cref="ChunkTree"/>.</param>
|
||||
/// <returns>The <see cref="ChunkTree"/> if a file exists at <paramref name="pagePath"/>,
|
||||
/// <c>null</c> otherwise.</returns>
|
||||
/// <remarks>The resulting <see cref="ChunkTree"/> does not contain inherited chunks from _ViewStart or
|
||||
/// default inherited chunks.</remarks>
|
||||
ChunkTree GetOrAdd(string pagePath, Func<IFileInfo, ChunkTree> getChunkTree);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. 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.FileProviders;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
/// <summary>
|
||||
/// A cache for parsed <see cref="CodeTree"/>s.
|
||||
/// </summary>
|
||||
public interface ICodeTreeCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Get an existing <see cref="CodeTree"/>, or create and add a new one if it is
|
||||
/// not available in the cache or is expired.
|
||||
/// </summary>
|
||||
/// <param name="pagePath">The application relative path of the Razor page.</param>
|
||||
/// <param name="getCodeTree">A delegate that creates a new <see cref="CodeTree"/>.</param>
|
||||
/// <returns>The <see cref="CodeTree"/> if a file exists at <paramref name="pagePath"/>,
|
||||
/// <c>null</c> otherwise.</returns>
|
||||
/// <remarks>The resulting <see cref="CodeTree"/> does not contain inherited chunks from _ViewStart or
|
||||
/// default inherited chunks.</remarks>
|
||||
CodeTree GetOrAdd(string pagePath, Func<IFileInfo, CodeTree> getCodeTree);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
|
|
@ -34,13 +34,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk)
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
{
|
||||
var injectChunk = ChunkHelper.EnsureChunk<InjectChunk>(chunk);
|
||||
if (!_addedMemberNames.Contains(injectChunk.MemberName))
|
||||
{
|
||||
_addedMemberNames.Add(injectChunk.MemberName);
|
||||
codeTree.Chunks.Add(TransformChunk(injectChunk));
|
||||
chunkTree.Chunks.Add(TransformChunk(injectChunk));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk)
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
{
|
||||
if (!_isBaseTypeSet)
|
||||
{
|
||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
// The base type can set exactly once and the first one we encounter wins.
|
||||
_isBaseTypeSet = true;
|
||||
|
||||
codeTree.Chunks.Add(TransformChunk(baseTypeChunk));
|
||||
chunkTree.Chunks.Add(TransformChunk(baseTypeChunk));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
|
|
@ -23,14 +23,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk)
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
{
|
||||
var namespaceChunk = ChunkHelper.EnsureChunk<UsingChunk>(chunk);
|
||||
|
||||
if (!_currentUsings.Contains(namespaceChunk.Namespace))
|
||||
{
|
||||
_currentUsings.Add(namespaceChunk.Namespace);
|
||||
codeTree.Chunks.Add(namespaceChunk);
|
||||
chunkTree.Chunks.Add(namespaceChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -12,8 +12,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="typeName">The type name of the property to be injected</param>
|
||||
/// <param name="propertyName">The member name of the property to be injected.</param>
|
||||
public InjectChunk(string typeName,
|
||||
string propertyName)
|
||||
public InjectChunk(
|
||||
string typeName,
|
||||
string propertyName)
|
||||
{
|
||||
TypeName = typeName;
|
||||
MemberName = propertyName;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private readonly string _injectAttribute;
|
||||
|
||||
public InjectChunkVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext context,
|
||||
[NotNull] CodeGeneratorContext context,
|
||||
[NotNull] string injectAttributeName)
|
||||
: base(writer, context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public class InjectParameterGenerator : SpanCodeGenerator
|
||||
public class InjectParameterGenerator : SpanChunkGenerator
|
||||
{
|
||||
public InjectParameterGenerator(string typeName, string propertyName)
|
||||
{
|
||||
|
|
@ -20,10 +20,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
public string PropertyName { get; private set; }
|
||||
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
var injectChunk = new InjectChunk(TypeName, PropertyName);
|
||||
context.CodeTreeBuilder.AddChunk(injectChunk, target);
|
||||
context.ChunkTreeBuilder.AddChunk(injectChunk, target);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
{
|
||||
public class ModelCodeGenerator : SpanCodeGenerator
|
||||
public class ModelChunkGenerator : SpanChunkGenerator
|
||||
{
|
||||
public ModelCodeGenerator(string baseType, string modelType)
|
||||
public ModelChunkGenerator(string baseType, string modelType)
|
||||
{
|
||||
BaseType = baseType;
|
||||
ModelType = modelType;
|
||||
|
|
@ -18,10 +19,10 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
public string BaseType { get; private set; }
|
||||
public string ModelType { get; private set; }
|
||||
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
var modelChunk = new ModelChunk(BaseType, ModelType);
|
||||
context.CodeTreeBuilder.AddChunk(modelChunk, target, topLevel: true);
|
||||
context.ChunkTreeBuilder.AddChunk(modelChunk, target, topLevel: true);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as ModelCodeGenerator;
|
||||
var other = obj as ModelChunkGenerator;
|
||||
return other != null &&
|
||||
string.Equals(ModelType, other.ModelType, StringComparison.Ordinal);
|
||||
}
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public class ModelChunkVisitor : MvcCSharpCodeVisitor
|
||||
{
|
||||
public ModelChunkVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext context)
|
||||
public ModelChunkVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public abstract class MvcCSharpChunkVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
public MvcCSharpChunkVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext context)
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,23 @@
|
|||
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public class MvcCSharpCodeBuilder : CSharpCodeBuilder
|
||||
public class MvcCSharpCodeGenerator : CSharpCodeGenerator
|
||||
{
|
||||
private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext;
|
||||
private readonly string _defaultModel;
|
||||
private readonly string _injectAttribute;
|
||||
|
||||
public MvcCSharpCodeBuilder([NotNull] CodeBuilderContext context,
|
||||
[NotNull] string defaultModel,
|
||||
[NotNull] string injectAttribute,
|
||||
[NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
public MvcCSharpCodeGenerator(
|
||||
[NotNull] CodeGeneratorContext context,
|
||||
[NotNull] string defaultModel,
|
||||
[NotNull] string injectAttribute,
|
||||
[NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
: base(context)
|
||||
{
|
||||
_tagHelperAttributeContext = tagHelperAttributeContext;
|
||||
|
|
@ -29,8 +29,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
private string Model { get; set; }
|
||||
|
||||
protected override CSharpCodeVisitor CreateCSharpCodeVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext context)
|
||||
protected override CSharpCodeVisitor CreateCSharpCodeVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
{
|
||||
var csharpCodeVisitor = base.CreateCSharpCodeVisitor(writer, context);
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
protected override CSharpCodeWritingScope BuildClassDeclaration(CSharpCodeWriter writer)
|
||||
{
|
||||
// Grab the last model chunk so it gets intellisense.
|
||||
var modelChunk = ChunkHelper.GetModelChunk(Context.CodeTreeBuilder.CodeTree);
|
||||
var modelChunk = ChunkHelper.GetModelChunk(Context.ChunkTreeBuilder.ChunkTree);
|
||||
|
||||
Model = modelChunk != null ? modelChunk.ModelType : _defaultModel;
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
writer.WriteLineHiddenDirective();
|
||||
|
||||
var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
|
||||
injectVisitor.Accept(Context.CodeTreeBuilder.CodeTree.Chunks);
|
||||
injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteLineHiddenDirective();
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public abstract class MvcCSharpCodeVisitor : MvcCSharpChunkVisitor
|
||||
{
|
||||
public MvcCSharpCodeVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext context)
|
||||
public MvcCSharpCodeVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System.Diagnostics;
|
||||
using Microsoft.AspNet.Mvc.Razor.Host;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
|
@ -55,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
|
||||
BaseTypeDirective(Resources.FormatMvcRazorCodeParser_KeywordMustBeFollowedByTypeName(ModelKeyword),
|
||||
CreateModelCodeGenerator);
|
||||
CreateModelChunkGenerator);
|
||||
|
||||
if (_modelStatementFound)
|
||||
{
|
||||
|
|
@ -136,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
// ';' is optional
|
||||
propertyName = RemoveWhitespaceAndTrailingSemicolons(propertyName);
|
||||
Span.CodeGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName);
|
||||
Span.ChunkGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName);
|
||||
|
||||
// Output the span and finish the block
|
||||
CompleteBlock();
|
||||
Output(SpanKind.Code, AcceptedCharacters.AnyExceptNewline);
|
||||
}
|
||||
|
||||
private SpanCodeGenerator CreateModelCodeGenerator(string model)
|
||||
private SpanChunkGenerator CreateModelChunkGenerator(string model)
|
||||
{
|
||||
return new ModelCodeGenerator(_baseType, model);
|
||||
return new ModelChunkGenerator(_baseType, model);
|
||||
}
|
||||
|
||||
// Internal for unit testing
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ using Microsoft.AspNet.FileProviders;
|
|||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -41,16 +41,16 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>.
|
||||
// This field holds the type name without the generic decoration (MyBaseType)
|
||||
private readonly string _baseType;
|
||||
private readonly ICodeTreeCache _codeTreeCache;
|
||||
private readonly IChunkTreeCache _ChunkTreeCache;
|
||||
private readonly RazorPathNormalizer _pathNormalizer;
|
||||
private ChunkInheritanceUtility _chunkInheritanceUtility;
|
||||
|
||||
internal MvcRazorHost(ICodeTreeCache codeTreeCache, RazorPathNormalizer pathNormalizer)
|
||||
internal MvcRazorHost(IChunkTreeCache ChunkTreeCache, RazorPathNormalizer pathNormalizer)
|
||||
: base(new CSharpRazorCodeLanguage())
|
||||
{
|
||||
_pathNormalizer = pathNormalizer;
|
||||
_baseType = BaseType;
|
||||
_codeTreeCache = codeTreeCache;
|
||||
_ChunkTreeCache = ChunkTreeCache;
|
||||
|
||||
TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
|
||||
DefaultBaseClass = BaseType + "<" + DefaultModel + ">";
|
||||
|
|
@ -116,19 +116,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="root">The path to the application base.</param>
|
||||
// Note: This constructor is used by tooling and is created once for each
|
||||
// Razor page that is loaded. Consequently, each loaded page has its own copy of
|
||||
// the CodeTreeCache, but this ok - having a shared CodeTreeCache per application in tooling
|
||||
// the ChunkTreeCache, but this ok - having a shared ChunkTreeCache per application in tooling
|
||||
// is problematic to manage.
|
||||
public MvcRazorHost(string root)
|
||||
: this(new DefaultCodeTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root))
|
||||
: this(new DefaultChunkTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="codeTreeCache"/>.
|
||||
/// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="ChunkTreeCache"/>.
|
||||
/// </summary>
|
||||
/// <param name="codeTreeCache">An <see cref="ICodeTreeCache"/> rooted at the application base path.</param>
|
||||
public MvcRazorHost(ICodeTreeCache codeTreeCache)
|
||||
: this(codeTreeCache, new RazorPathNormalizer())
|
||||
/// <param name="ChunkTreeCache">An <see cref="IChunkTreeCache"/> rooted at the application base path.</param>
|
||||
public MvcRazorHost(IChunkTreeCache ChunkTreeCache)
|
||||
: this(ChunkTreeCache, new RazorPathNormalizer())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
if (_chunkInheritanceUtility == null)
|
||||
{
|
||||
// This needs to be lazily evaluated to support DefaultInheritedChunks being virtual.
|
||||
_chunkInheritanceUtility = new ChunkInheritanceUtility(this, _codeTreeCache, DefaultInheritedChunks);
|
||||
_chunkInheritanceUtility = new ChunkInheritanceUtility(this, _ChunkTreeCache, DefaultInheritedChunks);
|
||||
}
|
||||
|
||||
return _chunkInheritanceUtility;
|
||||
|
|
@ -213,8 +213,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
sourceFileName = _pathNormalizer.NormalizePath(sourceFileName);
|
||||
|
||||
var inheritedCodeTrees = ChunkInheritanceUtility.GetInheritedCodeTrees(sourceFileName);
|
||||
return new MvcRazorParser(razorParser, inheritedCodeTrees, DefaultInheritedChunks, ModelExpressionType);
|
||||
var inheritedChunkTrees = ChunkInheritanceUtility.GetInheritedChunkTrees(sourceFileName);
|
||||
return new MvcRazorParser(razorParser, inheritedChunkTrees, DefaultInheritedChunks, ModelExpressionType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -224,26 +224,29 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override CodeBuilder DecorateCodeBuilder([NotNull] CodeBuilder incomingBuilder,
|
||||
[NotNull] CodeBuilderContext context)
|
||||
public override CodeGenerator DecorateCodeGenerator(
|
||||
[NotNull] CodeGenerator incomingGenerator,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
{
|
||||
// Need the normalized path to resolve inherited chunks only. Full paths are needed for generated Razor
|
||||
// files checksum and line pragmas to enable DesignTime debugging.
|
||||
var normalizedPath = _pathNormalizer.NormalizePath(context.SourceFile);
|
||||
var inheritedChunks = ChunkInheritanceUtility.GetInheritedCodeTrees(normalizedPath);
|
||||
var inheritedChunks = ChunkInheritanceUtility.GetInheritedChunkTrees(normalizedPath);
|
||||
|
||||
ChunkInheritanceUtility.MergeInheritedCodeTrees(context.CodeTreeBuilder.CodeTree,
|
||||
inheritedChunks,
|
||||
DefaultModel);
|
||||
ChunkInheritanceUtility.MergeInheritedChunkTrees(
|
||||
context.ChunkTreeBuilder.ChunkTree,
|
||||
inheritedChunks,
|
||||
DefaultModel);
|
||||
|
||||
return new MvcCSharpCodeBuilder(context,
|
||||
DefaultModel,
|
||||
InjectAttribute,
|
||||
new GeneratedTagHelperAttributeContext
|
||||
{
|
||||
ModelExpressionTypeName = ModelExpressionType,
|
||||
CreateModelExpressionMethodName = CreateModelExpressionMethod
|
||||
});
|
||||
return new MvcCSharpCodeGenerator(
|
||||
context,
|
||||
DefaultModel,
|
||||
InjectAttribute,
|
||||
new GeneratedTagHelperAttributeContext
|
||||
{
|
||||
ModelExpressionTypeName = ModelExpressionType,
|
||||
CreateModelExpressionMethodName = CreateModelExpressionMethod
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Razor.Host;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Parser.TagHelpers;
|
||||
|
|
@ -28,20 +28,20 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// Initializes a new instance of <see cref="MvcRazorParser"/>.
|
||||
/// </summary>
|
||||
/// <param name="parser">The <see cref="RazorParser"/> to copy properties from.</param>
|
||||
/// <param name="inheritedCodeTrees">The <see cref="IReadOnlyList{CodeTree}"/>s that are inherited
|
||||
/// <param name="inheritedChunkTrees">The <see cref="IReadOnlyList{ChunkTree}"/>s that are inherited
|
||||
/// from parsed pages from _ViewImports files.</param>
|
||||
/// <param name="defaultInheritedChunks">The <see cref="IReadOnlyList{Chunk}"/> inherited by
|
||||
/// default by all Razor pages in the application.</param>
|
||||
public MvcRazorParser(
|
||||
[NotNull] RazorParser parser,
|
||||
[NotNull] IReadOnlyList<CodeTree> inheritedCodeTrees,
|
||||
[NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks,
|
||||
[NotNull] string modelExpressionTypeName)
|
||||
: base(parser)
|
||||
{
|
||||
// Construct tag helper descriptors from @addTagHelper, @removeTagHelper and @tagHelperPrefix chunks
|
||||
_viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors(
|
||||
inheritedCodeTrees,
|
||||
inheritedChunkTrees,
|
||||
defaultInheritedChunks);
|
||||
|
||||
_modelExpressionTypeName = modelExpressionTypeName;
|
||||
|
|
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
private static IEnumerable<TagHelperDirectiveDescriptor> GetTagHelperDirectiveDescriptors(
|
||||
IReadOnlyList<CodeTree> inheritedCodeTrees,
|
||||
IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
{
|
||||
var descriptors = new List<TagHelperDirectiveDescriptor>();
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// Consequently we must visit tag helpers outside-in - furthest _ViewImports first and nearest one last.
|
||||
// This is different from the behavior of chunk merging where we visit the nearest one first and ignore
|
||||
// chunks that were previously visited.
|
||||
var chunksFromViewImports = inheritedCodeTrees
|
||||
var chunksFromViewImports = inheritedChunkTrees
|
||||
.Reverse()
|
||||
.SelectMany(tree => tree.Chunks);
|
||||
var chunksInOrder = defaultInheritedChunks.Concat(chunksFromViewImports);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
|
|
@ -30,11 +29,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <see cref="GeneratedTagHelperAttributeContext.ModelExpressionTypeName"/>, then a model expression will be
|
||||
/// created by calling into <see cref="GeneratedTagHelperAttributeContext.CreateModelExpressionMethodName"/>.
|
||||
/// </remarks>
|
||||
public override void RenderAttributeValue([NotNull] TagHelperAttributeDescriptor attributeDescriptor,
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeBuilderContext codeBuilderContext,
|
||||
[NotNull] Action<CSharpCodeWriter> renderAttributeValue,
|
||||
bool complexValue)
|
||||
public override void RenderAttributeValue(
|
||||
[NotNull] TagHelperAttributeDescriptor attributeDescriptor,
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext CodeGeneratorContext,
|
||||
[NotNull] Action<CSharpCodeWriter> renderAttributeValue,
|
||||
bool complexValue)
|
||||
{
|
||||
if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal))
|
||||
{
|
||||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
base.RenderAttributeValue(
|
||||
attributeDescriptor,
|
||||
writer,
|
||||
codeBuilderContext,
|
||||
CodeGeneratorContext,
|
||||
renderAttributeValue,
|
||||
complexValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
protected IMvcRazorHost GetRazorHost()
|
||||
{
|
||||
var descriptorResolver = new TagHelperDescriptorResolver(TagHelperTypeResolver);
|
||||
return new MvcRazorHost(new DefaultCodeTreeCache(FileProvider))
|
||||
return new MvcRazorHost(new DefaultChunkTreeCache(FileProvider))
|
||||
{
|
||||
TagHelperDescriptorResolver = descriptorResolver
|
||||
};
|
||||
|
|
|
|||
|
|
@ -117,10 +117,10 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
|
||||
// Caches view locations that are valid for the lifetime of the application.
|
||||
services.TryAdd(ServiceDescriptor.Singleton<IViewLocationCache, DefaultViewLocationCache>());
|
||||
services.TryAdd(ServiceDescriptor.Singleton<ICodeTreeCache>(serviceProvider =>
|
||||
services.TryAdd(ServiceDescriptor.Singleton<IChunkTreeCache>(serviceProvider =>
|
||||
{
|
||||
var cachedFileProvider = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
|
||||
return new DefaultCodeTreeCache(cachedFileProvider.Options.FileProvider);
|
||||
return new DefaultChunkTreeCache(cachedFileProvider.Options.FileProvider);
|
||||
}));
|
||||
|
||||
// The host is designed to be discarded after consumption and is very inexpensive to initialize.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
|
|
@ -30,19 +30,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
new InjectChunk("MyTestHtmlHelper", "Html"),
|
||||
new UsingChunk { Namespace = "AppNamespace.Model" },
|
||||
};
|
||||
var cache = new DefaultCodeTreeCache(fileProvider);
|
||||
var cache = new DefaultChunkTreeCache(fileProvider);
|
||||
var host = new MvcRazorHost(cache);
|
||||
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
|
||||
|
||||
// Act
|
||||
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
||||
var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml");
|
||||
|
||||
// Assert
|
||||
Assert.Collection(codeTrees,
|
||||
codeTree =>
|
||||
Assert.Collection(chunkTrees,
|
||||
ChunkTree =>
|
||||
{
|
||||
var viewImportsPath = @"Views\home\_ViewImports.cshtml";
|
||||
Assert.Collection(codeTree.Chunks,
|
||||
Assert.Collection(ChunkTree.Chunks,
|
||||
chunk =>
|
||||
{
|
||||
Assert.IsType<LiteralChunk>(chunk);
|
||||
|
|
@ -60,10 +60,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
|
||||
});
|
||||
},
|
||||
codeTree =>
|
||||
ChunkTree =>
|
||||
{
|
||||
var viewImportsPath = @"Views\_ViewImports.cshtml";
|
||||
Assert.Collection(codeTree.Chunks,
|
||||
Assert.Collection(ChunkTree.Chunks,
|
||||
chunk =>
|
||||
{
|
||||
Assert.IsType<LiteralChunk>(chunk);
|
||||
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
fileProvider.AddFile(@"_ViewImports.cs", string.Empty);
|
||||
fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty);
|
||||
fileProvider.AddFile(@"Views\home\_not-viewimports.cshtml", string.Empty);
|
||||
var cache = new DefaultCodeTreeCache(fileProvider);
|
||||
var cache = new DefaultChunkTreeCache(fileProvider);
|
||||
var host = new MvcRazorHost(cache);
|
||||
var defaultChunks = new Chunk[]
|
||||
{
|
||||
|
|
@ -124,10 +124,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
|
||||
|
||||
// Act
|
||||
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
||||
var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml");
|
||||
|
||||
// Assert
|
||||
Assert.Empty(codeTrees);
|
||||
Assert.Empty(chunkTrees);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -137,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
var fileProvider = new TestFileProvider();
|
||||
fileProvider.AddFile(@"Views\_ViewImports.cshtml",
|
||||
"@inject DifferentHelper<TModel> Html");
|
||||
var cache = new DefaultCodeTreeCache(fileProvider);
|
||||
var cache = new DefaultChunkTreeCache(fileProvider);
|
||||
var host = new MvcRazorHost(cache);
|
||||
var defaultChunks = new Chunk[]
|
||||
{
|
||||
new InjectChunk("MyTestHtmlHelper", "Html"),
|
||||
new UsingChunk { Namespace = "AppNamespace.Model" },
|
||||
};
|
||||
var inheritedCodeTrees = new CodeTree[]
|
||||
var inheritedChunkTrees = new ChunkTree[]
|
||||
{
|
||||
new CodeTree
|
||||
new ChunkTree
|
||||
{
|
||||
Chunks = new Chunk[]
|
||||
{
|
||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
new LiteralChunk { Text = "some text" }
|
||||
}
|
||||
},
|
||||
new CodeTree
|
||||
new ChunkTree
|
||||
{
|
||||
Chunks = new Chunk[]
|
||||
{
|
||||
|
|
@ -164,18 +164,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
};
|
||||
|
||||
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
utility.MergeInheritedCodeTrees(codeTree,
|
||||
inheritedCodeTrees,
|
||||
utility.MergeInheritedChunkTrees(chunkTree,
|
||||
inheritedChunkTrees,
|
||||
"dynamic");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, codeTree.Chunks.Count);
|
||||
Assert.Same(inheritedCodeTrees[0].Chunks[0], codeTree.Chunks[0]);
|
||||
Assert.Same(inheritedCodeTrees[1].Chunks[0], codeTree.Chunks[1]);
|
||||
Assert.Same(defaultChunks[0], codeTree.Chunks[2]);
|
||||
Assert.Equal(3, chunkTree.Chunks.Count);
|
||||
Assert.Same(inheritedChunkTrees[0].Chunks[0], chunkTree.Chunks[0]);
|
||||
Assert.Same(inheritedChunkTrees[1].Chunks[0], chunkTree.Chunks[1]);
|
||||
Assert.Same(defaultChunks[0], chunkTree.Chunks[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Moq;
|
||||
|
|
@ -11,7 +11,7 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
||||
{
|
||||
public class CodeTreeCacheTest
|
||||
public class ChunkTreeCacheTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetOrAdd_ReturnsCachedEntriesOnSubsequentCalls()
|
||||
|
|
@ -21,12 +21,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
var mockFileProvider = new Mock<TestFileProvider> { CallBase = true };
|
||||
var fileProvider = mockFileProvider.Object;
|
||||
fileProvider.AddFile(path, "test content");
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider);
|
||||
var expected = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
|
||||
var expected = new ChunkTree();
|
||||
|
||||
// Act
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
|
||||
// Assert
|
||||
Assert.Same(expected, result1);
|
||||
|
|
@ -41,12 +41,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
var path = @"Views\_ViewStart.cshtml";
|
||||
var mockFileProvider = new Mock<TestFileProvider> { CallBase = true };
|
||||
var fileProvider = mockFileProvider.Object;
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider);
|
||||
var expected = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
|
||||
var expected = new ChunkTree();
|
||||
|
||||
// Act
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
|
||||
// Assert
|
||||
Assert.Null(result1);
|
||||
|
|
@ -61,19 +61,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
var path = @"Views\Home\_ViewStart.cshtml";
|
||||
var fileProvider = new TestFileProvider();
|
||||
fileProvider.AddFile(path, "test content");
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider);
|
||||
var expected1 = new CodeTree();
|
||||
var expected2 = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
|
||||
var expected1 = new ChunkTree();
|
||||
var expected2 = new ChunkTree();
|
||||
|
||||
// Act 1
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1);
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1);
|
||||
|
||||
// Assert 1
|
||||
Assert.Same(expected1, result1);
|
||||
|
||||
// Act 2
|
||||
fileProvider.GetTrigger(path).IsExpired = true;
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected2);
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected2);
|
||||
|
||||
// Assert 2
|
||||
Assert.Same(expected2, result2);
|
||||
|
|
@ -86,11 +86,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
var path = @"Views\Home\_ViewStart.cshtml";
|
||||
var fileProvider = new TestFileProvider();
|
||||
fileProvider.AddFile(path, "test content");
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider);
|
||||
var expected1 = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
|
||||
var expected1 = new ChunkTree();
|
||||
|
||||
// Act 1
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1);
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1);
|
||||
|
||||
// Assert 1
|
||||
Assert.Same(expected1, result1);
|
||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
// Act 2
|
||||
fileProvider.DeleteFile(path);
|
||||
fileProvider.GetTrigger(path).IsExpired = true;
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
|
||||
// Assert 2
|
||||
Assert.Null(result2);
|
||||
|
|
@ -110,11 +110,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
// Arrange
|
||||
var path = @"Views\Home\_ViewStart.cshtml";
|
||||
var fileProvider = new TestFileProvider();
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider);
|
||||
var expected = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
|
||||
var expected = new ChunkTree();
|
||||
|
||||
// Act 1
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
|
||||
// Assert 1
|
||||
Assert.Null(result1);
|
||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
// Act 2
|
||||
fileProvider.AddFile(path, "test content");
|
||||
fileProvider.GetTrigger(path).IsExpired = true;
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
|
||||
|
||||
// Assert 2
|
||||
Assert.Same(expected, result2);
|
||||
|
|
@ -140,29 +140,29 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
|
|||
clock.SetupGet(c => c.UtcNow)
|
||||
.Returns(() => utcNow);
|
||||
var options = new MemoryCacheOptions { Clock = clock.Object };
|
||||
var codeTreeCache = new DefaultCodeTreeCache(fileProvider, options);
|
||||
var codeTree1 = new CodeTree();
|
||||
var codeTree2 = new CodeTree();
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(fileProvider, options);
|
||||
var chunkTree1 = new ChunkTree();
|
||||
var chunkTree2 = new ChunkTree();
|
||||
|
||||
// Act 1
|
||||
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree1);
|
||||
var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree1);
|
||||
|
||||
// Assert 1
|
||||
Assert.Same(codeTree1, result1);
|
||||
Assert.Same(chunkTree1, result1);
|
||||
|
||||
// Act 2
|
||||
utcNow = utcNow.AddSeconds(59);
|
||||
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); });
|
||||
|
||||
// Assert 2
|
||||
Assert.Same(codeTree1, result2);
|
||||
Assert.Same(chunkTree1, result2);
|
||||
|
||||
// Act 3
|
||||
utcNow = utcNow.AddSeconds(65);
|
||||
var result3 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree2);
|
||||
var result3 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree2);
|
||||
|
||||
// Assert 3
|
||||
Assert.Same(codeTree2, result3);
|
||||
Assert.Same(chunkTree2, result3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -45,41 +45,41 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
var merger = new InjectChunkMerger("dynamic");
|
||||
|
||||
// Act and Assert
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected);
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInCodeTree()
|
||||
public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInChunkTree()
|
||||
{
|
||||
// Arrange
|
||||
var expectedType = "MyApp.MyHelperType";
|
||||
var expectedProperty = "MyHelper";
|
||||
var merger = new InjectChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new InjectChunk(expectedType, expectedProperty));
|
||||
merger.Merge(chunkTree, new InjectChunk(expectedType, expectedProperty));
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||
Assert.Equal(expectedType, injectChunk.TypeName);
|
||||
Assert.Equal(expectedProperty, injectChunk.MemberName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInCodeTree()
|
||||
public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInChunkTree()
|
||||
{
|
||||
// Arrange
|
||||
var merger = new InjectChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.VisitChunk(new InjectChunk("MyTypeA", "MyProperty"));
|
||||
merger.Merge(codeTree, new InjectChunk("MyTypeB", "MyProperty"));
|
||||
merger.Merge(chunkTree, new InjectChunk("MyTypeB", "MyProperty"));
|
||||
|
||||
// Assert
|
||||
Assert.Empty(codeTree.Chunks);
|
||||
Assert.Empty(chunkTree.Chunks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -87,20 +87,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new InjectChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.VisitChunk(new InjectChunk("MyType", "MyProperty"));
|
||||
merger.Merge(codeTree, new InjectChunk("MyType", "myproperty"));
|
||||
merger.Merge(codeTree, new InjectChunk("MyTypeB", "different-property"));
|
||||
merger.Merge(chunkTree, new InjectChunk("MyType", "myproperty"));
|
||||
merger.Merge(chunkTree, new InjectChunk("MyTypeB", "different-property"));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, codeTree.Chunks.Count);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(codeTree.Chunks[0]);
|
||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[0]);
|
||||
Assert.Equal("MyType", injectChunk.TypeName);
|
||||
Assert.Equal("myproperty", injectChunk.MemberName);
|
||||
|
||||
injectChunk = Assert.IsType<InjectChunk>(codeTree.Chunks[1]);
|
||||
injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[1]);
|
||||
Assert.Equal("MyTypeB", injectChunk.TypeName);
|
||||
Assert.Equal("different-property", injectChunk.MemberName);
|
||||
}
|
||||
|
|
@ -110,13 +110,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new InjectChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
|
||||
merger.Merge(chunkTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||
Assert.Equal("MyHelper<dynamic>", injectChunk.TypeName);
|
||||
Assert.Equal("MyProperty", injectChunk.MemberName);
|
||||
|
|
@ -127,13 +127,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new InjectChunkMerger("MyTestModel2");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
|
||||
merger.Merge(chunkTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||
Assert.Equal("MyHelper<MyTestModel2>", injectChunk.TypeName);
|
||||
Assert.Equal("MyProperty", injectChunk.MemberName);
|
||||
|
|
@ -144,14 +144,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new InjectChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new InjectChunk("SomeType", "Property"));
|
||||
merger.Merge(codeTree, new InjectChunk("SomeOtherType", "Property"));
|
||||
merger.Merge(chunkTree, new InjectChunk("SomeType", "Property"));
|
||||
merger.Merge(chunkTree, new InjectChunk("SomeOtherType", "Property"));
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||
Assert.Equal("SomeType", injectChunk.TypeName);
|
||||
Assert.Equal("Property", injectChunk.MemberName);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var expected = "Argument must be an instance of " +
|
||||
"'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'.";
|
||||
"'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'.";
|
||||
var merger = new SetBaseTypeChunkMerger("dynamic");
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -45,43 +45,43 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var expected = "Argument must be an instance of " +
|
||||
"'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'.";
|
||||
"'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'.";
|
||||
var merger = new SetBaseTypeChunkMerger("dynamic");
|
||||
|
||||
// Act and Assert
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected);
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_SetsBaseTypeIfItHasNotBeenSetInCodeTree()
|
||||
public void Merge_SetsBaseTypeIfItHasNotBeenSetInChunkTree()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "MyApp.Razor.MyBaseType";
|
||||
var merger = new SetBaseTypeChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = expected });
|
||||
merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = expected });
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
||||
Assert.Equal(expected, setBaseTypeChunk.TypeName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_IgnoresSetBaseTypeChunksIfCodeTreeContainsOne()
|
||||
public void Merge_IgnoresSetBaseTypeChunksIfChunkTreeContainsOne()
|
||||
{
|
||||
// Arrange
|
||||
var merger = new SetBaseTypeChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" });
|
||||
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" });
|
||||
merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" });
|
||||
|
||||
// Assert
|
||||
Assert.Empty(codeTree.Chunks);
|
||||
Assert.Empty(chunkTree.Chunks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -89,14 +89,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new SetBaseTypeChunkMerger("dynamic");
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase1" });
|
||||
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase2" });
|
||||
merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase1" });
|
||||
merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase2" });
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
||||
Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
public void Visit_ThrowsIfThePassedInChunkIsNotAUsingChunk()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Generator.Compiler.UsingChunk'.";
|
||||
var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'.";
|
||||
var merger = new UsingChunkMerger();
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -24,44 +24,44 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
public void Merge_ThrowsIfThePassedInChunkIsNotAUsingChunk()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Generator.Compiler.UsingChunk'.";
|
||||
var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'.";
|
||||
var merger = new UsingChunkMerger();
|
||||
|
||||
// Act and Assert
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected);
|
||||
ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_AddsNamespacesThatHaveNotBeenVisitedInCodeTree()
|
||||
public void Merge_AddsNamespacesThatHaveNotBeenVisitedInChunkTree()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "MyApp.Models";
|
||||
var merger = new UsingChunkMerger();
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = expected });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = expected });
|
||||
|
||||
// Assert
|
||||
var chunk = Assert.Single(codeTree.Chunks);
|
||||
var chunk = Assert.Single(chunkTree.Chunks);
|
||||
var usingChunk = Assert.IsType<UsingChunk>(chunk);
|
||||
Assert.Equal(expected, usingChunk.Namespace);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_IgnoresNamespacesThatHaveBeenVisitedInCodeTree()
|
||||
public void Merge_IgnoresNamespacesThatHaveBeenVisitedInChunkTree()
|
||||
{
|
||||
// Arrange
|
||||
var merger = new UsingChunkMerger();
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
|
||||
// Assert
|
||||
Assert.Empty(codeTree.Chunks);
|
||||
Assert.Empty(chunkTree.Chunks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -69,18 +69,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new UsingChunkMerger();
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" });
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, codeTree.Chunks.Count);
|
||||
var chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[0]);
|
||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
||||
var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
|
||||
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
||||
chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[1]);
|
||||
chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
|
||||
Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace);
|
||||
}
|
||||
|
||||
|
|
@ -89,17 +89,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
{
|
||||
// Arrange
|
||||
var merger = new UsingChunkMerger();
|
||||
var codeTree = new CodeTree();
|
||||
var chunkTree = new ChunkTree();
|
||||
|
||||
// Act
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.mvc" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
|
||||
merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.mvc" });
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, codeTree.Chunks.Count);
|
||||
var chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[0]);
|
||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
||||
var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
|
||||
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
||||
chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[1]);
|
||||
chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
|
||||
Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -144,15 +144,16 @@ MyType1
|
|||
Assert.Equal(expected, code);
|
||||
}
|
||||
|
||||
private static CodeBuilderContext CreateContext()
|
||||
private static CodeGeneratorContext CreateContext()
|
||||
{
|
||||
var codeTreeCache = new DefaultCodeTreeCache(new TestFileProvider());
|
||||
return new CodeBuilderContext(
|
||||
new CodeGeneratorContext(new MvcRazorHost(codeTreeCache),
|
||||
"MyClass",
|
||||
"MyNamespace",
|
||||
string.Empty,
|
||||
shouldGenerateLinePragmas: true),
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(new TestFileProvider());
|
||||
return new CodeGeneratorContext(
|
||||
new ChunkGeneratorContext(
|
||||
new MvcRazorHost(chunkTreeCache),
|
||||
"MyClass",
|
||||
"MyNamespace",
|
||||
string.Empty,
|
||||
shouldGenerateLinePragmas: true),
|
||||
new ErrorSink());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ Environment.NewLine +
|
|||
var visitor = new ModelChunkVisitor(writer, context);
|
||||
var factory = SpanFactory.CreateCsHtml();
|
||||
var node = (Span)factory.Code("Some code")
|
||||
.As(new ModelCodeGenerator("MyBase", "MyGeneric"));
|
||||
.As(new ModelChunkGenerator("MyBase", "MyGeneric"));
|
||||
|
||||
// Act
|
||||
visitor.Accept(new Chunk[]
|
||||
|
|
@ -86,7 +87,7 @@ Environment.NewLine +
|
|||
var visitor = new ModelChunkVisitor(writer, context);
|
||||
var factory = SpanFactory.CreateCsHtml();
|
||||
var node = (Span)factory.Code("Some code")
|
||||
.As(new ModelCodeGenerator("MyType", "MyPropertyName"));
|
||||
.As(new ModelChunkGenerator("MyType", "MyPropertyName"));
|
||||
|
||||
// Act
|
||||
visitor.Accept(new Chunk[]
|
||||
|
|
@ -100,15 +101,16 @@ Environment.NewLine +
|
|||
Assert.Equal(expected, code);
|
||||
}
|
||||
|
||||
private static CodeBuilderContext CreateContext()
|
||||
private static CodeGeneratorContext CreateContext()
|
||||
{
|
||||
var fileProvider = new TestFileProvider();
|
||||
return new CodeBuilderContext(
|
||||
new CodeGeneratorContext(new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)),
|
||||
"MyClass",
|
||||
"MyNamespace",
|
||||
string.Empty,
|
||||
shouldGenerateLinePragmas: true),
|
||||
return new CodeGeneratorContext(
|
||||
new ChunkGeneratorContext(
|
||||
new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)),
|
||||
"MyClass",
|
||||
"MyNamespace",
|
||||
string.Empty,
|
||||
shouldGenerateLinePragmas: true),
|
||||
new ErrorSink());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
|
|
@ -46,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code(" Foo")
|
||||
.As(new ModelCodeGenerator("RazorView", "Foo"))
|
||||
.As(new ModelChunkGenerator("RazorView", "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -78,10 +79,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code(modelName + "\r\n")
|
||||
.As(new ModelCodeGenerator("RazorView", expectedModel))
|
||||
.As(new ModelChunkGenerator("RazorView", expectedModel))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
|
||||
// Act
|
||||
|
|
@ -110,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code(" ")
|
||||
.As(new ModelCodeGenerator("RazorView", string.Empty))
|
||||
.As(new ModelChunkGenerator("RazorView", string.Empty))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
};
|
||||
|
|
@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo\r\n")
|
||||
.As(new ModelCodeGenerator("RazorView", "Foo"))
|
||||
.As(new ModelChunkGenerator("RazorView", "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -149,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar")
|
||||
.As(new ModelCodeGenerator("RazorView", "Bar"))
|
||||
.As(new ModelChunkGenerator("RazorView", "Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -186,7 +187,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo\r\n")
|
||||
.As(new ModelCodeGenerator("RazorView", "Foo"))
|
||||
.As(new ModelChunkGenerator("RazorView", "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -194,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("inherits ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar")
|
||||
.As(new SetBaseTypeCodeGenerator("Bar"))
|
||||
.As(new SetBaseTypeChunkGenerator("Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -231,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("inherits ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar" + Environment.NewLine)
|
||||
.As(new SetBaseTypeCodeGenerator("Bar"))
|
||||
.As(new SetBaseTypeChunkGenerator("Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -239,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo")
|
||||
.As(new ModelCodeGenerator("RazorView", "Foo"))
|
||||
.As(new ModelChunkGenerator("RazorView", "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -360,7 +361,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
.As(new InjectParameterGenerator(expectedService, expectedPropertyName))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
|
||||
// Act
|
||||
|
|
@ -389,7 +390,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
.As(new InjectParameterGenerator(string.Empty, string.Empty))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
var expectedErrors = new[]
|
||||
{
|
||||
|
|
@ -456,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
.As(new InjectParameterGenerator("IMyService", string.Empty))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
var expectedErrors = new[]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ using System.IO;
|
|||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Xunit;
|
||||
|
|
@ -30,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
|
||||
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
|
||||
var host = new MvcRazorHost(
|
||||
codeTreeCache: null,
|
||||
ChunkTreeCache: null,
|
||||
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
|
||||
var parser = new RazorParser(
|
||||
host.CodeLanguage.CreateCodeParser(),
|
||||
|
|
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
host.DecorateRazorParser(parser, rootedFilePath);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal);
|
||||
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -51,32 +52,32 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
[InlineData("C:/")]
|
||||
[InlineData(@"\\")]
|
||||
[InlineData(@"C:\")]
|
||||
public void DecorateCodeBuilder_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths(
|
||||
public void DecorateCodeGenerator_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths(
|
||||
string rootPrefix)
|
||||
{
|
||||
// Arrange
|
||||
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
|
||||
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
|
||||
var host = new MvcRazorHost(
|
||||
codeTreeCache: null,
|
||||
ChunkTreeCache: null,
|
||||
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
|
||||
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host);
|
||||
var codeBuilderContext = new CodeBuilderContext(
|
||||
new CodeGeneratorContext(
|
||||
var CodeGeneratorContext = new CodeGeneratorContext(
|
||||
new ChunkGeneratorContext(
|
||||
host,
|
||||
host.DefaultClassName,
|
||||
host.DefaultNamespace,
|
||||
rootedFilePath,
|
||||
shouldGenerateLinePragmas: true),
|
||||
new ErrorSink());
|
||||
var codeBuilder = new CSharpCodeBuilder(codeBuilderContext);
|
||||
var codeGenerator = new CSharpCodeGenerator(CodeGeneratorContext);
|
||||
host.ChunkInheritanceUtility = chunkInheritanceUtility;
|
||||
|
||||
// Act
|
||||
host.DecorateCodeBuilder(codeBuilder, codeBuilderContext);
|
||||
host.DecorateCodeGenerator(codeGenerator, CodeGeneratorContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal);
|
||||
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider));
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider));
|
||||
|
||||
// Act
|
||||
var instrumented = host.EnableInstrumentation;
|
||||
|
|
@ -98,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider))
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
|
||||
{
|
||||
DesignTimeMode = true
|
||||
};
|
||||
|
|
@ -152,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new TestMvcRazorHost(new DefaultCodeTreeCache(fileProvider));
|
||||
var host = new TestMvcRazorHost(new DefaultChunkTreeCache(fileProvider));
|
||||
|
||||
// Act and Assert
|
||||
RunRuntimeTest(host, scenarioName);
|
||||
|
|
@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider))
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
|
||||
{
|
||||
DesignTimeMode = true
|
||||
};
|
||||
|
|
@ -183,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider))
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
|
||||
{
|
||||
DesignTimeMode = true
|
||||
};
|
||||
|
|
@ -204,12 +205,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider))
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
|
||||
{
|
||||
DesignTimeMode = true
|
||||
};
|
||||
host.NamespaceImports.Clear();
|
||||
var expectedLineMappings = new []
|
||||
var expectedLineMappings = new[]
|
||||
{
|
||||
BuildLineMapping(7, 0, 7, 222, 6, 7, 7),
|
||||
BuildLineMapping(24, 1, 8, 747, 26, 8, 20),
|
||||
|
|
@ -227,7 +228,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
// Arrange
|
||||
var fileProvider = new TestFileProvider();
|
||||
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider))
|
||||
var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
|
||||
{
|
||||
DesignTimeMode = true
|
||||
};
|
||||
|
|
@ -323,17 +324,17 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private class PathValidatingChunkInheritanceUtility : ChunkInheritanceUtility
|
||||
{
|
||||
public PathValidatingChunkInheritanceUtility(MvcRazorHost razorHost)
|
||||
: base(razorHost, codeTreeCache: null, defaultInheritedChunks: new Chunk[0])
|
||||
: base(razorHost, chunkTreeCache: null, defaultInheritedChunks: new Chunk[0])
|
||||
{
|
||||
}
|
||||
|
||||
public string InheritedCodeTreePagePath { get; private set; }
|
||||
public string InheritedChunkTreePagePath { get; private set; }
|
||||
|
||||
public override IReadOnlyList<CodeTree> GetInheritedCodeTrees([NotNull] string pagePath)
|
||||
public override IReadOnlyList<ChunkTree> GetInheritedChunkTrees([NotNull] string pagePath)
|
||||
{
|
||||
InheritedCodeTreePagePath = pagePath;
|
||||
InheritedChunkTreePagePath = pagePath;
|
||||
|
||||
return new CodeTree[0];
|
||||
return new ChunkTree[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -342,15 +343,15 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
private class TestMvcRazorHost : MvcRazorHost
|
||||
{
|
||||
public TestMvcRazorHost(ICodeTreeCache codeTreeCache)
|
||||
: base(codeTreeCache)
|
||||
public TestMvcRazorHost(IChunkTreeCache ChunkTreeCache)
|
||||
: base(ChunkTreeCache)
|
||||
{ }
|
||||
|
||||
public override CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context)
|
||||
public override CodeGenerator DecorateCodeGenerator(CodeGenerator incomingBuilder, CodeGeneratorContext context)
|
||||
{
|
||||
base.DecorateCodeBuilder(incomingBuilder, context);
|
||||
base.DecorateCodeGenerator(incomingBuilder, context);
|
||||
|
||||
return new TestCSharpCodeBuilder(context,
|
||||
return new TestCSharpCodeGenerator(context,
|
||||
DefaultModel,
|
||||
"Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute",
|
||||
new GeneratedTagHelperAttributeContext
|
||||
|
|
@ -360,11 +361,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
});
|
||||
}
|
||||
|
||||
protected class TestCSharpCodeBuilder : MvcCSharpCodeBuilder
|
||||
protected class TestCSharpCodeGenerator : MvcCSharpCodeGenerator
|
||||
{
|
||||
private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext;
|
||||
|
||||
public TestCSharpCodeBuilder(CodeBuilderContext context,
|
||||
public TestCSharpCodeGenerator(CodeGeneratorContext context,
|
||||
string defaultModel,
|
||||
string activateAttribute,
|
||||
GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
|
|
@ -373,7 +374,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
_tagHelperAttributeContext = tagHelperAttributeContext;
|
||||
}
|
||||
|
||||
protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context)
|
||||
protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
|
||||
{
|
||||
var visitor = base.CreateCSharpCodeVisitor(writer, context);
|
||||
visitor.TagHelperRenderer = new NoUniqueIdsTagHelperCodeRenderer(visitor, writer, context)
|
||||
|
|
@ -388,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
public NoUniqueIdsTagHelperCodeRenderer(IChunkVisitor bodyVisitor,
|
||||
CSharpCodeWriter writer,
|
||||
CodeBuilderContext context)
|
||||
CodeGeneratorContext context)
|
||||
: base(bodyVisitor, writer, context)
|
||||
{ }
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
|
|
@ -21,21 +21,21 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
get
|
||||
{
|
||||
// codeTrees, expectedDirectiveDescriptors
|
||||
return new TheoryData<CodeTree[], TagHelperDirectiveDescriptor[]>
|
||||
// chunkTrees, expectedDirectiveDescriptors
|
||||
return new TheoryData<ChunkTree[], TagHelperDirectiveDescriptor[]>
|
||||
{
|
||||
{
|
||||
new[] { CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) },
|
||||
new[] { CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) },
|
||||
new[] { CreateDirectiveDescriptor("THP", TagHelperDirectiveType.TagHelperPrefix) }
|
||||
},
|
||||
{
|
||||
new[] { CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }) },
|
||||
new[] { CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }) },
|
||||
new[] { CreateDirectiveDescriptor("ATH", TagHelperDirectiveType.AddTagHelper) }
|
||||
},
|
||||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(
|
||||
CreateChunkTree(
|
||||
new AddTagHelperChunk { LookupText = "ATH1" },
|
||||
new AddTagHelperChunk { LookupText = "ATH2" })
|
||||
},
|
||||
|
|
@ -46,13 +46,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
},
|
||||
{
|
||||
new[] { CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) },
|
||||
new[] { CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) },
|
||||
new[] { CreateDirectiveDescriptor("RTH", TagHelperDirectiveType.RemoveTagHelper) }
|
||||
},
|
||||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(
|
||||
CreateChunkTree(
|
||||
new RemoveTagHelperChunk { LookupText = "RTH1" },
|
||||
new RemoveTagHelperChunk { LookupText = "RTH2" })
|
||||
},
|
||||
|
|
@ -65,15 +65,15 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
|
||||
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
|
||||
CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
|
||||
CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
|
||||
},
|
||||
new[] { CreateDirectiveDescriptor("THP1", TagHelperDirectiveType.TagHelperPrefix) }
|
||||
},
|
||||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(
|
||||
CreateChunkTree(
|
||||
new TagHelperPrefixDirectiveChunk { Prefix = "THP" },
|
||||
new RemoveTagHelperChunk { LookupText = "RTH" },
|
||||
new AddTagHelperChunk { LookupText = "ATH" })
|
||||
|
|
@ -88,10 +88,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(
|
||||
CreateChunkTree(
|
||||
new LiteralChunk { Text = "Hello world" },
|
||||
new AddTagHelperChunk { LookupText = "ATH" }),
|
||||
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" })
|
||||
CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" })
|
||||
},
|
||||
new[]
|
||||
{
|
||||
|
|
@ -102,11 +102,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }),
|
||||
CreateCodeTree(
|
||||
CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }),
|
||||
CreateChunkTree(
|
||||
new LiteralChunk { Text = "Hello world" },
|
||||
new AddTagHelperChunk { LookupText = "ATH" }),
|
||||
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" })
|
||||
CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" })
|
||||
},
|
||||
new[]
|
||||
{
|
||||
|
|
@ -118,10 +118,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
new[]
|
||||
{
|
||||
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
|
||||
CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }),
|
||||
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }),
|
||||
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
|
||||
CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
|
||||
CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }),
|
||||
CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }),
|
||||
CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
|
||||
},
|
||||
new[]
|
||||
{
|
||||
|
|
@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
[Theory]
|
||||
[MemberData(nameof(ViewImportsData))]
|
||||
public void GetTagHelperDescriptors_ReturnsExpectedDirectiveDescriptors(
|
||||
CodeTree[] codeTrees,
|
||||
ChunkTree[] chunkTrees,
|
||||
TagHelperDirectiveDescriptor[] expectedDirectiveDescriptors)
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
new CSharpCodeParser(),
|
||||
new HtmlMarkupParser(),
|
||||
tagHelperDescriptorResolver: resolver.Object);
|
||||
var parser = new TestableMvcRazorParser(baseParser, codeTrees, defaultInheritedChunks: new Chunk[0]);
|
||||
var parser = new TestableMvcRazorParser(baseParser, chunkTrees, defaultInheritedChunks: new Chunk[0]);
|
||||
|
||||
// Act
|
||||
parser.GetTagHelperDescriptorsPublic(block, errorSink: new ErrorSink()).ToArray();
|
||||
|
|
@ -211,9 +211,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Assert.Equal(expectedOutput, output, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static CodeTree CreateCodeTree(params Chunk[] chunks)
|
||||
private static ChunkTree CreateChunkTree(params Chunk[] chunks)
|
||||
{
|
||||
return new CodeTree
|
||||
return new ChunkTree
|
||||
{
|
||||
Chunks = chunks
|
||||
};
|
||||
|
|
@ -229,9 +229,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private class TestableMvcRazorParser : MvcRazorParser
|
||||
{
|
||||
public TestableMvcRazorParser(RazorParser parser,
|
||||
IReadOnlyList<CodeTree> codeTrees,
|
||||
IReadOnlyList<ChunkTree> chunkTrees,
|
||||
IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
: base(parser, codeTrees, defaultInheritedChunks, typeof(ModelExpression).FullName)
|
||||
: base(parser, chunkTrees, defaultInheritedChunks, typeof(ModelExpression).FullName)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -31,13 +31,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
typeName: propertyType,
|
||||
isIndexer: false);
|
||||
var writer = new CSharpCodeWriter();
|
||||
var generatorContext = new CodeGeneratorContext(host: null,
|
||||
className: string.Empty,
|
||||
rootNamespace: string.Empty,
|
||||
sourceFile: string.Empty,
|
||||
shouldGenerateLinePragmas: true);
|
||||
var generatorContext = new ChunkGeneratorContext(
|
||||
host: null,
|
||||
className: string.Empty,
|
||||
rootNamespace: string.Empty,
|
||||
sourceFile: string.Empty,
|
||||
shouldGenerateLinePragmas: true);
|
||||
var errorSink = new ErrorSink();
|
||||
var context = new CodeBuilderContext(generatorContext, errorSink);
|
||||
var context = new CodeGeneratorContext(generatorContext, errorSink);
|
||||
|
||||
// Act
|
||||
renderer.RenderAttributeValue(attributeDescriptor, writer, context,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Editor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
||||
|
|
@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
return Builder.Build();
|
||||
}
|
||||
|
||||
public SpanConstructor With(ISpanCodeGenerator generator)
|
||||
public SpanConstructor With(ISpanChunkGenerator generator)
|
||||
{
|
||||
Builder.CodeGenerator = generator;
|
||||
Builder.ChunkGenerator = generator;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -48,9 +48,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
return this;
|
||||
}
|
||||
|
||||
public SpanConstructor With(Action<ISpanCodeGenerator> generatorConfigurer)
|
||||
public SpanConstructor With(Action<ISpanChunkGenerator> generatorConfigurer)
|
||||
{
|
||||
generatorConfigurer(Builder.CodeGenerator);
|
||||
generatorConfigurer(Builder.ChunkGenerator);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
public SpanConstructor Hidden()
|
||||
{
|
||||
Builder.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Builder.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
var symbol = new HtmlSymbol(self.LocationTracker.CurrentLocation, string.Empty, HtmlSymbolType.Unknown);
|
||||
return self.Span(SpanKind.Markup, symbol)
|
||||
.With(new MarkupCodeGenerator());
|
||||
.With(new MarkupChunkGenerator());
|
||||
}
|
||||
|
||||
public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content)
|
||||
|
|
@ -107,12 +107,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
public static SpanConstructor Markup(this SpanFactory self, string content)
|
||||
{
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator());
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator());
|
||||
}
|
||||
|
||||
public static SpanConstructor Markup(this SpanFactory self, params string[] content)
|
||||
{
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator());
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator());
|
||||
}
|
||||
|
||||
public static SourceLocation GetLocationAndAdvance(this SourceLocationTracker self, string content)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
_self = self;
|
||||
}
|
||||
|
||||
public SpanConstructor As(ISpanCodeGenerator codeGenerator)
|
||||
public SpanConstructor As(ISpanChunkGenerator codeGenerator)
|
||||
{
|
||||
return _self.With(codeGenerator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
|
@ -56,8 +57,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
new Block(new BlockBuilder { Type = BlockType.Comment }),
|
||||
Enumerable.Empty<TagHelperDescriptor>(),
|
||||
errorSink,
|
||||
new CodeBuilderResult("", new LineMapping[0]),
|
||||
new CodeTree());
|
||||
new CodeGeneratorResult("", new LineMapping[0]),
|
||||
new ChunkTree());
|
||||
var host = new Mock<IMvcRazorHost>();
|
||||
host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>()))
|
||||
.Returns(generatorResult)
|
||||
|
|
@ -94,8 +95,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
new Block(new BlockBuilder { Type = BlockType.Comment }),
|
||||
Enumerable.Empty<TagHelperDescriptor>(),
|
||||
new ErrorSink(),
|
||||
new CodeBuilderResult(code, new LineMapping[0]),
|
||||
new CodeTree());
|
||||
new CodeGeneratorResult(code, new LineMapping[0]),
|
||||
new ChunkTree());
|
||||
var host = new Mock<IMvcRazorHost>();
|
||||
host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>()))
|
||||
.Returns(generatorResult);
|
||||
|
|
@ -206,8 +207,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
new Block(new BlockBuilder { Type = BlockType.Comment }),
|
||||
Enumerable.Empty<TagHelperDescriptor>(),
|
||||
new ErrorSink(),
|
||||
new CodeBuilderResult("", new LineMapping[0]),
|
||||
new CodeTree());
|
||||
new CodeGeneratorResult("", new LineMapping[0]),
|
||||
new ChunkTree());
|
||||
}
|
||||
|
||||
private static IOptions<RazorViewEngineOptions> GetOptions(IFileProvider fileProvider = null)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
|
@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code(" Foo")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -66,10 +67,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo?\r\n")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo?"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo?"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
Assert.Equal(expectedSpans, spans.ToArray());
|
||||
}
|
||||
|
|
@ -91,10 +92,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo[[]][]\r\n")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo[[]][]"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo[[]][]"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.Markup("Bar")
|
||||
.With(new MarkupCodeGenerator())
|
||||
.With(new MarkupChunkGenerator())
|
||||
};
|
||||
Assert.Equal(expectedSpans, spans.ToArray());
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("$rootnamespace$.MyModel")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "$rootnamespace$.MyModel"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "$rootnamespace$.MyModel"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code(" ")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, string.Empty))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, string.Empty))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -173,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo\r\n")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -181,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Bar"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -215,7 +216,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo\r\n")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -223,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("inherits ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar")
|
||||
.As(new SetBaseTypeCodeGenerator("Bar"))
|
||||
.As(new SetBaseTypeChunkGenerator("Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
@ -257,7 +258,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("inherits ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Bar" + Environment.NewLine)
|
||||
.As(new SetBaseTypeCodeGenerator("Bar"))
|
||||
.As(new SetBaseTypeChunkGenerator("Bar"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml(),
|
||||
factory.CodeTransition(SyntaxConstants.TransitionString)
|
||||
|
|
@ -265,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
factory.MetaCode("model ")
|
||||
.Accepts(AcceptedCharacters.None),
|
||||
factory.Code("Foo")
|
||||
.As(new ModelCodeGenerator(DefaultBaseType, "Foo"))
|
||||
.As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
|
||||
.Accepts(AcceptedCharacters.AnyExceptNewline),
|
||||
factory.EmptyHtml()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Editor;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
public static SpanConstructor EmptyHtml(this SpanFactory self)
|
||||
{
|
||||
return self.Span(SpanKind.Markup, new HtmlSymbol(self.LocationTracker.CurrentLocation, String.Empty, HtmlSymbolType.Unknown))
|
||||
.With(new MarkupCodeGenerator());
|
||||
.With(new MarkupChunkGenerator());
|
||||
}
|
||||
|
||||
public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content)
|
||||
|
|
@ -40,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
}
|
||||
public static SpanConstructor Markup(this SpanFactory self, string content)
|
||||
{
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator());
|
||||
return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
_self = self;
|
||||
}
|
||||
|
||||
public SpanConstructor As(ISpanCodeGenerator codeGenerator)
|
||||
public SpanConstructor As(ISpanChunkGenerator codeGenerator)
|
||||
{
|
||||
return _self.With(codeGenerator);
|
||||
}
|
||||
|
|
@ -160,9 +161,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
|
|||
return Builder.Build();
|
||||
}
|
||||
|
||||
public SpanConstructor With(ISpanCodeGenerator generator)
|
||||
public SpanConstructor With(ISpanChunkGenerator generator)
|
||||
{
|
||||
Builder.CodeGenerator = generator;
|
||||
Builder.ChunkGenerator = generator;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue