Permalink
Browse files

Replaced options class with simple properties.

  • Loading branch information...
jdiamond committed Mar 6, 2012
1 parent d0d466e commit f9c6aa25cfb83e58dacba35c2faee607b6b4b4d2
@@ -38,14 +38,13 @@ public static void RegisterRoutes(RouteCollection routes)
public static void RegisterViewEngines(ViewEngineCollection engines)
{
engines.RemoveAt(0);
- engines.Add(new NustacheViewEngine(
- new NustachViewEngineOptions
- {
- // Uncomment out this line to not need Model in front of all your expressions.
- // This makes it easier to share templates between the client and server.
- // But it also means that ViewData/ViewBag will be inaccessible.
- //RootContext = NustacheViewEngineRootContext.Model
- }));
+ engines.Add(new NustacheViewEngine
+ {
+ // Uncomment out this line to not need Model in front of all your expressions.
+ // This makes it easier to share templates between the client and server.
+ // But it also means that ViewData/ViewBag will be inaccessible.
+ //RootContext = NustacheViewEngineRootContext.Model
+ });
}
}
}
@@ -1,14 +0,0 @@
-namespace Nustache.Mvc
-{
- public class NustachViewEngineOptions
- {
- public string Extension { get; set; }
- public NustacheViewEngineRootContext RootContext { get; set; }
- }
-
- public enum NustacheViewEngineRootContext
- {
- ViewData,
- Model
- }
-}
@@ -40,7 +40,6 @@
<ItemGroup>
<Compile Include="NustacheView.cs" />
<Compile Include="NustacheViewEngine.cs" />
- <Compile Include="NustachViewEngineOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -9,18 +9,18 @@ public class NustacheView : IView
private readonly ControllerContext _controllerContext;
private readonly string _viewPath;
private readonly string _masterPath;
- private readonly NustachViewEngineOptions _options;
+ private readonly NustacheViewEngineRootContext _rootContext;
public NustacheView(
ControllerContext controllerContext,
string viewPath,
string masterPath,
- NustachViewEngineOptions options)
+ NustacheViewEngineRootContext rootContext)
{
_controllerContext = controllerContext;
_viewPath = viewPath;
_masterPath = masterPath;
- _options = options;
+ _rootContext = rootContext;
}
public void Render(ViewContext viewContext, TextWriter writer)
@@ -31,7 +31,7 @@ public void Render(ViewContext viewContext, TextWriter writer)
{
var masterTemplate = GetTemplate(_masterPath);
- var data = _options.RootContext == NustacheViewEngineRootContext.ViewData
+ var data = _rootContext == NustacheViewEngineRootContext.ViewData
? viewContext.ViewData
: viewContext.ViewData.Model;
@@ -4,18 +4,23 @@ namespace Nustache.Mvc
{
public class NustacheViewEngine : VirtualPathProviderViewEngine
{
- private readonly NustachViewEngineOptions _options;
+ private string _fileExtension;
public NustacheViewEngine()
- : this(new NustachViewEngineOptions())
{
+ FileExtension = ".mustache";
+ RootContext = NustacheViewEngineRootContext.ViewData;
}
- public NustacheViewEngine(NustachViewEngineOptions options)
+ public string FileExtension
{
- _options = options;
+ get { return _fileExtension; }
+ set { _fileExtension = value; UpdatePaths(); }
+ }
- var fileExtension = options.Extension ?? ".mustache";
+ private void UpdatePaths()
+ {
+ var fileExtension = FileExtension;
MasterLocationFormats = new[]
{
@@ -43,14 +48,22 @@ public NustacheViewEngine(NustachViewEngineOptions options)
};
}
+ public NustacheViewEngineRootContext RootContext { get; set; }
+
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
{
- return new NustacheView(controllerContext, viewPath, masterPath, _options);
+ return new NustacheView(controllerContext, viewPath, masterPath, RootContext);
}
protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
{
- return new NustacheView(controllerContext, partialPath, null, _options);
+ return new NustacheView(controllerContext, partialPath, null, RootContext);
}
}
+
+ public enum NustacheViewEngineRootContext
+ {
+ ViewData,
+ Model
+ }
}

0 comments on commit f9c6aa2

Please sign in to comment.