From bc04d4f8dad4c151ae48c6d382bfec332d8f9cd8 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Mon, 1 Oct 2012 23:22:23 +0500 Subject: [PATCH] Added PluginViewEngine for App_Plugins --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 5 +- src/Umbraco.Web/Mvc/Constants.cs | 1 + src/Umbraco.Web/Mvc/PluginViewEngine.cs | 65 ++++++++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + src/Umbraco.Web/WebBootManager.cs | 2 + src/umbraco.sln | 5 +- 6 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 src/Umbraco.Web/Mvc/PluginViewEngine.cs diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 68ca6b5054..ca8ec15c50 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -261,8 +261,8 @@ - EditView.aspx - ASPXCodeBehind + EditView.aspx + ASPXCodeBehind EditView.aspx @@ -2221,6 +2221,7 @@ + diff --git a/src/Umbraco.Web/Mvc/Constants.cs b/src/Umbraco.Web/Mvc/Constants.cs index 1ec35e4928..63ddf5fa05 100644 --- a/src/Umbraco.Web/Mvc/Constants.cs +++ b/src/Umbraco.Web/Mvc/Constants.cs @@ -3,5 +3,6 @@ namespace Umbraco.Web.Mvc internal static class Constants { public const string ViewLocation = "~/Views"; + public const string PluginsLocation = "~/App_Plugins"; } } \ No newline at end of file diff --git a/src/Umbraco.Web/Mvc/PluginViewEngine.cs b/src/Umbraco.Web/Mvc/PluginViewEngine.cs new file mode 100644 index 0000000000..2abc352ef0 --- /dev/null +++ b/src/Umbraco.Web/Mvc/PluginViewEngine.cs @@ -0,0 +1,65 @@ +using System.Linq; +using System.Web.Mvc; + +namespace Umbraco.Web.Mvc +{ + /// + /// A view engine to look into the App_Plugins/Packages folder for views for packaged controllers + /// + public class PluginViewEngine : RazorViewEngine + { + + /// + /// Constructor + /// + 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") + }; + + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 1ade3a03fa..c720b831c8 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -279,6 +279,7 @@ + diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index f77963af99..0085653d5b 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -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(typeof(RenderModel), new RenderModelBinder())); diff --git a/src/umbraco.sln b/src/umbraco.sln index 661245f906..b10a9c82db 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -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