Added PluginViewEngine for App_Plugins

This commit is contained in:
Shannon Deminick
2012-10-01 23:22:23 +05:00
parent be5076783f
commit bc04d4f8da
6 changed files with 75 additions and 4 deletions

View File

@@ -261,8 +261,8 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="umbraco\settings\views\EditView.aspx.cs">
<DependentUpon>EditView.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
<DependentUpon>EditView.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="umbraco\settings\views\EditView.aspx.designer.cs">
<DependentUpon>EditView.aspx</DependentUpon>
@@ -2221,6 +2221,7 @@
<ItemGroup>
<Folder Include="App_Code\" />
<Folder Include="App_Data\" />
<Folder Include="App_Plugins\Packages\" />
<Folder Include="css\" />
<Folder Include="macroScripts\" />
<Folder Include="masterpages\" />

View File

@@ -3,5 +3,6 @@ namespace Umbraco.Web.Mvc
internal static class Constants
{
public const string ViewLocation = "~/Views";
public const string PluginsLocation = "~/App_Plugins";
}
}

View File

@@ -0,0 +1,65 @@
using System.Linq;
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// A view engine to look into the App_Plugins/Packages folder for views for packaged controllers
/// </summary>
public class PluginViewEngine : RazorViewEngine
{
/// <summary>
/// Constructor
/// </summary>
public PluginViewEngine()
{
SetViewLocations();
}
private void SetViewLocations()
{
//these are the originals:
//base.AreaViewLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
//base.AreaMasterLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
//base.AreaPartialViewLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
//base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/Views/{1}/{0}.vbhtml", "~/Views/Shared/{0}.cshtml", "~/Views/Shared/{0}.vbhtml" };
//base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/Views/{1}/{0}.vbhtml", "~/Views/Shared/{0}.cshtml", "~/Views/Shared/{0}.vbhtml" };
//base.PartialViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/Views/{1}/{0}.vbhtml", "~/Views/Shared/{0}.cshtml", "~/Views/Shared/{0}.vbhtml" };
//base.FileExtensions = new string[] { "cshtml", "vbhtml" };
var viewLocationsArray = new[]
{
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/{1}/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/{1}/{0}.vbhtml")
};
//set all of the area view locations to the plugin folder
AreaViewLocationFormats = viewLocationsArray
.Concat(new[]
{
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Shared/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Shared/{0}.vbhtml")
})
.ToArray();
AreaMasterLocationFormats = viewLocationsArray;
AreaPartialViewLocationFormats = new[]
{
//will be used when we have partial view and child action macros
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Partials/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Partials/{0}.vbhtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/MacroPartials/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/MacroPartials/{0}.vbhtml"),
//for partials
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/{1}/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/{1}/{0}.vbhtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Shared/{0}.cshtml"),
string.Concat(Constants.PluginsLocation, "/Packages/{2}/Views/Shared/{0}.vbhtml")
};
}
}
}

View File

@@ -279,6 +279,7 @@
<Compile Include="Mvc\IHtmlTagWrapper.cs" />
<Compile Include="Mvc\MergeModelStateToChildActionAttribute.cs" />
<Compile Include="Mvc\PluginController.cs" />
<Compile Include="Mvc\PluginViewEngine.cs" />
<Compile Include="Mvc\PostedDataProxyInfo.cs" />
<Compile Include="Mvc\RedirectToUmbracoPageResult.cs" />
<Compile Include="Mvc\Strings.Designer.cs">

View File

@@ -54,6 +54,8 @@ namespace Umbraco.Web
//set the render view engine
ViewEngines.Engines.Add(new RenderViewEngine());
//set the plugin view engine
ViewEngines.Engines.Add(new PluginViewEngine());
//set model binder
ModelBinders.Binders.Add(new KeyValuePair<Type, IModelBinder>(typeof(RenderModel), new RenderModelBinder()));

View File

@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F0242771-6DE6-4E03-BD3A-7B79BA79105B}"
ProjectSection(SolutionItems) = preProject
INDIGO64.testrunconfig = INDIGO64.testrunconfig
@@ -12,6 +12,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{2849E9D4-3B4E-40A3-A309-F3CB4F0E125F}"
ProjectSection(SolutionItems) = preProject
..\build\Build.bat = ..\build\Build.bat
..\build\Build.proj = ..\build\Build.proj
umbraco.presentation.targets = umbraco.presentation.targets
EndProjectSection
EndProject