Make FileSystemRazorProject internal (#1152)

Fixes #1117
This commit is contained in:
Yves57 2017-04-04 23:09:53 +02:00 committed by Pranav K
parent 68554f8106
commit c7e2e1880e
5 changed files with 19 additions and 33 deletions

View File

@ -8,15 +8,8 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Evolution namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> internal class FileSystemRazorProject : RazorProject
/// A <see cref="RazorProject"/> implementation over the physical file system.
/// </summary>
public class FileSystemRazorProject : RazorProject
{ {
/// <summary>
/// Initializes a new instance of <see cref="FileSystemRazorProject"/>.
/// </summary>
/// <param name="root">The directory to root the file system at.</param>
public FileSystemRazorProject(string root) public FileSystemRazorProject(string root)
{ {
if (string.IsNullOrEmpty(root)) if (string.IsNullOrEmpty(root))
@ -27,12 +20,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Root = root.Replace('\\', '/').TrimEnd('/'); Root = root.Replace('\\', '/').TrimEnd('/');
} }
/// <summary>
/// The root of the file system.
/// </summary>
public string Root { get; } public string Root { get; }
/// <inheritdoc />
public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath) public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
{ {
var absoluteBasePath = NormalizeAndEnsureValidPath(basePath); var absoluteBasePath = NormalizeAndEnsureValidPath(basePath);
@ -52,7 +41,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
}); });
} }
/// <inheritdoc />
public override RazorProjectItem GetItem(string path) public override RazorProjectItem GetItem(string path)
{ {
var absolutePath = NormalizeAndEnsureValidPath(path); var absolutePath = NormalizeAndEnsureValidPath(path);

View File

@ -5,10 +5,7 @@ using System.IO;
namespace Microsoft.AspNetCore.Razor.Evolution namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> internal class FileSystemRazorProjectItem : RazorProjectItem
/// An implementation of <see cref="RazorProjectItem"/> using <see cref="FileInfo"/>.
/// </summary>
public class FileSystemRazorProjectItem : RazorProjectItem
{ {
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="FileSystemRazorProjectItem"/>. /// Initializes a new instance of <see cref="FileSystemRazorProjectItem"/>.
@ -23,27 +20,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution
File = file; File = file;
} }
/// <summary>
/// Gets the <see cref="FileInfo"/>.
/// </summary>
public FileInfo File { get; } public FileInfo File { get; }
/// <inheritdoc />
public override string BasePath { get; } public override string BasePath { get; }
/// <inheritdoc />
public override string Path { get; } public override string Path { get; }
/// <inheritdoc />
public override bool Exists => File.Exists; public override bool Exists => File.Exists;
/// <inheritdoc />
public override string FileName => File.Name; public override string FileName => File.Name;
/// <inheritdoc />
public override string PhysicalPath => File.FullName; public override string PhysicalPath => File.FullName;
/// <inheritdoc />
public override Stream Read() => File.OpenRead(); public override Stream Read() => File.OpenRead();
} }
} }

View File

@ -123,5 +123,15 @@ namespace Microsoft.AspNetCore.Razor.Evolution
return path; return path;
} }
/// <summary>
/// Create a Razor project based on a physical file system.
/// </summary>
/// <param name="rootDirectoryPath">The directory to root the file system at.</param>
/// <returns>A <see cref="RazorProject"/></returns>
public static RazorProject Create(string rootDirectoryPath)
{
return new FileSystemRazorProject(rootDirectoryPath);
}
} }
} }

View File

@ -26,7 +26,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
RazorExtensions.Register(b); RazorExtensions.Register(b);
}); });
var templateEngine = new MvcRazorTemplateEngine(engine, new FileSystemRazorProject(projectPath)); var templateEngine = new MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath));
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
return templateEngine; return templateEngine;
} }

View File

@ -55,7 +55,7 @@ namespace RazorPageGenerator
}); });
var viewDirectories = Directory.EnumerateDirectories(targetProjectDirectory, "Views", SearchOption.AllDirectories); var viewDirectories = Directory.EnumerateDirectories(targetProjectDirectory, "Views", SearchOption.AllDirectories);
var razorProject = new FileSystemRazorProject(targetProjectDirectory); var razorProject = RazorProject.Create(targetProjectDirectory);
var templateEngine = new RazorTemplateEngine(razorEngine, razorProject); var templateEngine = new RazorTemplateEngine(razorEngine, razorProject);
var fileCount = 0; var fileCount = 0;
@ -66,7 +66,7 @@ namespace RazorPageGenerator
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(" Generating code files for views in {0}", viewDir); Console.WriteLine(" Generating code files for views in {0}", viewDir);
var viewDirPath = viewDir.Substring(targetProjectDirectory.Length).Replace('\\', '/'); var viewDirPath = viewDir.Substring(targetProjectDirectory.Length).Replace('\\', '/');
var cshtmlFiles = razorProject.EnumerateItems(viewDirPath).Cast<FileSystemRazorProjectItem>(); var cshtmlFiles = razorProject.EnumerateItems(viewDirPath);
if (!cshtmlFiles.Any()) if (!cshtmlFiles.Any())
{ {
@ -86,7 +86,7 @@ namespace RazorPageGenerator
return results; return results;
} }
private static RazorPageGeneratorResult GenerateCodeFile(RazorTemplateEngine templateEngine, FileSystemRazorProjectItem projectItem) private static RazorPageGeneratorResult GenerateCodeFile(RazorTemplateEngine templateEngine, RazorProjectItem projectItem)
{ {
var projectItemWrapper = new FileSystemRazorProjectItemWrapper(projectItem); var projectItemWrapper = new FileSystemRazorProjectItemWrapper(projectItem);
var cSharpDocument = templateEngine.GenerateCode(projectItemWrapper); var cSharpDocument = templateEngine.GenerateCode(projectItemWrapper);
@ -106,9 +106,9 @@ namespace RazorPageGenerator
private class FileSystemRazorProjectItemWrapper : RazorProjectItem private class FileSystemRazorProjectItemWrapper : RazorProjectItem
{ {
private readonly FileSystemRazorProjectItem _source; private readonly RazorProjectItem _source;
public FileSystemRazorProjectItemWrapper(FileSystemRazorProjectItem item) public FileSystemRazorProjectItemWrapper(RazorProjectItem item)
{ {
_source = item; _source = item;
} }
@ -130,7 +130,7 @@ namespace RazorPageGenerator
private string ProcessFileIncludes() private string ProcessFileIncludes()
{ {
var basePath = _source.File.DirectoryName; var basePath = System.IO.Path.GetDirectoryName(_source.PhysicalPath);
var cshtmlContent = File.ReadAllText(_source.PhysicalPath); var cshtmlContent = File.ReadAllText(_source.PhysicalPath);
var startMatch = "<%$ include: "; var startMatch = "<%$ include: ";