parent
68554f8106
commit
c7e2e1880e
|
|
@ -8,15 +8,8 @@ using System.Linq;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="RazorProject"/> implementation over the physical file system.
|
||||
/// </summary>
|
||||
public class FileSystemRazorProject : RazorProject
|
||||
internal 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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(root))
|
||||
|
|
@ -27,12 +20,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
Root = root.Replace('\\', '/').TrimEnd('/');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The root of the file system.
|
||||
/// </summary>
|
||||
public string Root { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
|
||||
{
|
||||
var absoluteBasePath = NormalizeAndEnsureValidPath(basePath);
|
||||
|
|
@ -52,7 +41,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override RazorProjectItem GetItem(string path)
|
||||
{
|
||||
var absolutePath = NormalizeAndEnsureValidPath(path);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ using System.IO;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||
{
|
||||
/// <summary>
|
||||
/// An implementation of <see cref="RazorProjectItem"/> using <see cref="FileInfo"/>.
|
||||
/// </summary>
|
||||
public class FileSystemRazorProjectItem : RazorProjectItem
|
||||
internal class FileSystemRazorProjectItem : RazorProjectItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="FileSystemRazorProjectItem"/>.
|
||||
|
|
@ -23,27 +20,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
File = file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="FileInfo"/>.
|
||||
/// </summary>
|
||||
public FileInfo File { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BasePath { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Path { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Exists => File.Exists;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileName => File.Name;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string PhysicalPath => File.FullName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Stream Read() => File.OpenRead();
|
||||
}
|
||||
}
|
||||
|
|
@ -123,5 +123,15 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
RazorExtensions.Register(b);
|
||||
});
|
||||
|
||||
var templateEngine = new MvcRazorTemplateEngine(engine, new FileSystemRazorProject(projectPath));
|
||||
var templateEngine = new MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath));
|
||||
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
return templateEngine;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace RazorPageGenerator
|
|||
});
|
||||
|
||||
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 fileCount = 0;
|
||||
|
|
@ -66,7 +66,7 @@ namespace RazorPageGenerator
|
|||
Console.WriteLine();
|
||||
Console.WriteLine(" Generating code files for views in {0}", viewDir);
|
||||
var viewDirPath = viewDir.Substring(targetProjectDirectory.Length).Replace('\\', '/');
|
||||
var cshtmlFiles = razorProject.EnumerateItems(viewDirPath).Cast<FileSystemRazorProjectItem>();
|
||||
var cshtmlFiles = razorProject.EnumerateItems(viewDirPath);
|
||||
|
||||
if (!cshtmlFiles.Any())
|
||||
{
|
||||
|
|
@ -86,7 +86,7 @@ namespace RazorPageGenerator
|
|||
return results;
|
||||
}
|
||||
|
||||
private static RazorPageGeneratorResult GenerateCodeFile(RazorTemplateEngine templateEngine, FileSystemRazorProjectItem projectItem)
|
||||
private static RazorPageGeneratorResult GenerateCodeFile(RazorTemplateEngine templateEngine, RazorProjectItem projectItem)
|
||||
{
|
||||
var projectItemWrapper = new FileSystemRazorProjectItemWrapper(projectItem);
|
||||
var cSharpDocument = templateEngine.GenerateCode(projectItemWrapper);
|
||||
|
|
@ -106,9 +106,9 @@ namespace RazorPageGenerator
|
|||
|
||||
private class FileSystemRazorProjectItemWrapper : RazorProjectItem
|
||||
{
|
||||
private readonly FileSystemRazorProjectItem _source;
|
||||
private readonly RazorProjectItem _source;
|
||||
|
||||
public FileSystemRazorProjectItemWrapper(FileSystemRazorProjectItem item)
|
||||
public FileSystemRazorProjectItemWrapper(RazorProjectItem item)
|
||||
{
|
||||
_source = item;
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ namespace RazorPageGenerator
|
|||
|
||||
private string ProcessFileIncludes()
|
||||
{
|
||||
var basePath = _source.File.DirectoryName;
|
||||
var basePath = System.IO.Path.GetDirectoryName(_source.PhysicalPath);
|
||||
var cshtmlContent = File.ReadAllText(_source.PhysicalPath);
|
||||
|
||||
var startMatch = "<%$ include: ";
|
||||
|
|
|
|||
Loading…
Reference in New Issue