Add support for _Imports.razor (dotnet/aspnetcore-tooling#354)
* Added support _Imports.razor
* Feedback
\n\nCommit migrated from 14704054f2
This commit is contained in:
parent
62199e2195
commit
91a383ad3b
|
|
@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
{
|
{
|
||||||
internal class ComponentImportProjectFeature : IImportProjectFeature
|
internal class ComponentImportProjectFeature : IImportProjectFeature
|
||||||
{
|
{
|
||||||
private const string ImportsFileName = "_ViewImports.cshtml";
|
|
||||||
|
|
||||||
private static readonly char[] PathSeparators = new char[]{ '/', '\\' };
|
private static readonly char[] PathSeparators = new char[]{ '/', '\\' };
|
||||||
|
|
||||||
// Using explicit newlines here to avoid fooling our baseline tests
|
// Using explicit newlines here to avoid fooling our baseline tests
|
||||||
|
|
@ -74,7 +72,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
public IEnumerable<RazorProjectItem> GetHierarchicalImports(RazorProject project, RazorProjectItem projectItem)
|
public IEnumerable<RazorProjectItem> GetHierarchicalImports(RazorProject project, RazorProjectItem projectItem)
|
||||||
{
|
{
|
||||||
// We want items in descending order. FindHierarchicalItems returns items in ascending order.
|
// We want items in descending order. FindHierarchicalItems returns items in ascending order.
|
||||||
return project.FindHierarchicalItems(projectItem.FilePath, ImportsFileName).Reverse();
|
return project.FindHierarchicalItems(projectItem.FilePath, ComponentMetadata.ImportsFileName).Reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class VirtualProjectItem : RazorProjectItem
|
private class VirtualProjectItem : RazorProjectItem
|
||||||
|
|
@ -99,6 +97,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
|
|
||||||
public override bool Exists => true;
|
public override bool Exists => true;
|
||||||
|
|
||||||
|
public override string FileKind => FileKinds.ComponentImport;
|
||||||
|
|
||||||
public override Stream Read() => new MemoryStream(_bytes);
|
public override Stream Read() => new MemoryStream(_bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
// use our own metadata entry to denote non-Component tag helpers.
|
// use our own metadata entry to denote non-Component tag helpers.
|
||||||
public static readonly string SpecialKindKey = "Components.IsSpecialKind";
|
public static readonly string SpecialKindKey = "Components.IsSpecialKind";
|
||||||
|
|
||||||
|
public static readonly string ImportsFileName = "_Imports.razor";
|
||||||
|
|
||||||
public static class Bind
|
public static class Bind
|
||||||
{
|
{
|
||||||
public static readonly string RuntimeName = "Components.None";
|
public static readonly string RuntimeName = "Components.None";
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.AspNetCore.Razor.Language.Components;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Language
|
namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
|
|
@ -10,12 +11,20 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
public static readonly string Component = "component";
|
public static readonly string Component = "component";
|
||||||
|
|
||||||
|
public static readonly string ComponentImport = "componentImport";
|
||||||
|
|
||||||
public static readonly string Legacy = "mvc";
|
public static readonly string Legacy = "mvc";
|
||||||
|
|
||||||
public static bool IsComponent(string fileKind)
|
public static bool IsComponent(string fileKind)
|
||||||
{
|
{
|
||||||
// fileKind might be null.
|
// fileKind might be null.
|
||||||
return string.Equals(fileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase);
|
return string.Equals(fileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase) || IsComponentImport(fileKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsComponentImport(string fileKind)
|
||||||
|
{
|
||||||
|
// fileKind might be null.
|
||||||
|
return string.Equals(fileKind, FileKinds.ComponentImport, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFileKindFromFilePath(string filePath)
|
public static string GetFileKindFromFilePath(string filePath)
|
||||||
|
|
@ -25,7 +34,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
throw new ArgumentNullException(nameof(filePath));
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.Equals(".razor", Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(ComponentMetadata.ImportsFileName, Path.GetFileName(filePath), StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
return FileKinds.ComponentImport;
|
||||||
|
}
|
||||||
|
else if (string.Equals(".razor", Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return FileKinds.Component;
|
return FileKinds.Component;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue