Modify MvcRazorHost to use a fixed namespace for generated views.
Fixes #554
This commit is contained in:
parent
a53e378cf4
commit
0c66074033
|
|
@ -8,6 +8,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
public interface IMvcRazorHost
|
public interface IMvcRazorHost
|
||||||
{
|
{
|
||||||
GeneratorResults GenerateCode(string rootNamespace, string rootRelativePath, Stream inputStream);
|
GeneratorResults GenerateCode(string rootRelativePath, Stream inputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
public class MvcRazorHost : RazorEngineHost, IMvcRazorHost
|
public class MvcRazorHost : RazorEngineHost, IMvcRazorHost
|
||||||
{
|
{
|
||||||
|
private const string ViewNamespace = "ASP";
|
||||||
|
|
||||||
private static readonly string[] _defaultNamespaces = new[]
|
private static readonly string[] _defaultNamespaces = new[]
|
||||||
{
|
{
|
||||||
"System",
|
"System",
|
||||||
|
|
@ -53,13 +55,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeneratorResults GenerateCode(string rootNamespace, string rootRelativePath, Stream inputStream)
|
public GeneratorResults GenerateCode(string rootRelativePath, Stream inputStream)
|
||||||
{
|
{
|
||||||
string className = ParserHelpers.SanitizeClassName(rootRelativePath);
|
string className = ParserHelpers.SanitizeClassName(rootRelativePath);
|
||||||
using (var reader = new StreamReader(inputStream))
|
using (var reader = new StreamReader(inputStream))
|
||||||
{
|
{
|
||||||
var engine = new RazorTemplateEngine(this);
|
var engine = new RazorTemplateEngine(this);
|
||||||
return engine.GenerateCode(reader, className, rootNamespace, rootRelativePath);
|
return engine.GenerateCode(reader, className, ViewNamespace, rootRelativePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase));
|
Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase));
|
||||||
var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length);
|
var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length);
|
||||||
results = _razorHost.GenerateCode(_environment.ApplicationName, rootRelativePath, inputStream);
|
results = _razorHost.GenerateCode(rootRelativePath, inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.Success)
|
if (!results.Success)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
||||||
env.SetupGet(e => e.ApplicationName).Returns("MyTestApplication");
|
env.SetupGet(e => e.ApplicationName).Returns("MyTestApplication");
|
||||||
env.SetupGet(e => e.ApplicationBasePath).Returns(appPath);
|
env.SetupGet(e => e.ApplicationBasePath).Returns(appPath);
|
||||||
var host = new Mock<IMvcRazorHost>();
|
var host = new Mock<IMvcRazorHost>();
|
||||||
host.Setup(h => h.GenerateCode("MyTestApplication", @"views\index\home.cshtml", It.IsAny<Stream>()))
|
host.Setup(h => h.GenerateCode(@"views\index\home.cshtml", It.IsAny<Stream>()))
|
||||||
.Returns(new GeneratorResults(new Block(new BlockBuilder { Type = BlockType.Comment }), new RazorError[0], new CodeBuilderResult("", new LineMapping[0])))
|
.Returns(new GeneratorResults(new Block(new BlockBuilder { Type = BlockType.Comment }), new RazorError[0], new CodeBuilderResult("", new LineMapping[0])))
|
||||||
.Verifiable();
|
.Verifiable();
|
||||||
var compiler = new Mock<ICompilationService>();
|
var compiler = new Mock<ICompilationService>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue