From d821401ea2dae1d3db8105cf0f114ea4b9243450 Mon Sep 17 00:00:00 2001 From: neehouse Date: Fri, 6 Sep 2013 15:34:19 -0400 Subject: [PATCH 1/4] Removing file location restriction from PartialViewMacro to allow custom paths. --- src/Umbraco.Web/Macros/PartialViewMacroEngine.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs index e454a99f17..3e819a737d 100644 --- a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs @@ -104,11 +104,11 @@ namespace Umbraco.Web.Macros if (currentPage == null) throw new ArgumentNullException("currentPage"); if (macro.ScriptName.IsNullOrWhiteSpace()) throw new ArgumentException("The ScriptName property of the macro object cannot be null or empty"); - if (!macro.ScriptName.StartsWith(SystemDirectories.MvcViews + "/MacroPartials/") - && (!Regex.IsMatch(macro.ScriptName, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled))) - { - throw new InvalidOperationException("Cannot render the Partial View Macro with file: " + macro.ScriptName + ". All Partial View Macros must exist in the " + SystemDirectories.MvcViews + "/MacroPartials/ folder"); - } + //if (!macro.ScriptName.StartsWith(SystemDirectories.MvcViews + "/MacroPartials/") + // && (!Regex.IsMatch(macro.ScriptName, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled))) + //{ + // throw new InvalidOperationException("Cannot render the Partial View Macro with file: " + macro.ScriptName + ". All Partial View Macros must exist in the " + SystemDirectories.MvcViews + "/MacroPartials/ folder"); + //} var http = _getHttpContext(); var umbCtx = _getUmbracoContext(); From 998e2228815667c04436aa544ed784bdfa93f21f Mon Sep 17 00:00:00 2001 From: neehouse Date: Mon, 9 Sep 2013 14:00:08 -0400 Subject: [PATCH 2/4] Adding event to RenderMacro methods to allow for manipulation of the MacroModel. --- src/Umbraco.Web/umbraco.presentation/macro.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index d8914040ac..180d69a015 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -231,8 +231,22 @@ namespace umbraco return renderMacro(pageElements, pageId); } + public delegate void RenderEventHandler(MacroModel sender, RenderEventArgs e); + public new static event RenderEventHandler BeforeRender; + protected virtual void FireBeforeRender(RenderEventArgs e) + { + if (BeforeRender != null) + BeforeRender(Model, e); + } + + public Control renderMacro(Hashtable pageElements, int pageId) { + // Event to allow manipulation of Macro Model + var rea = new RenderEventArgs(); + FireBeforeRender(rea); + + var macroInfo = (Model.MacroType == MacroTypes.Script && Model.Name.IsNullOrWhiteSpace()) ? string.Format("Render Inline Macro, Cache: {0})", Model.CacheDuration) : string.Format("Render Macro: {0}, type: {1}, cache: {2})", Name, Model.MacroType, Model.CacheDuration); @@ -1952,4 +1966,6 @@ namespace umbraco #endregion } + public class RenderEventArgs : System.ComponentModel.CancelEventArgs { } + } \ No newline at end of file From c0214ac4ec75d1c8d6d0d8ce53a5523298ddfd87 Mon Sep 17 00:00:00 2001 From: neehouse Date: Tue, 10 Sep 2013 09:34:19 -0400 Subject: [PATCH 3/4] Modified the MacroRendering event as requested. Removed the unnecessary check for the file path from the Partial View Macro as it would not be hit anyhow since the macro engine is determined using the same rule. U4-2644 & U4-2643 --- src/Umbraco.Web/Macros/PartialViewMacroEngine.cs | 6 ------ src/Umbraco.Web/umbraco.presentation/macro.cs | 16 ++++++++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs index 3e819a737d..507b9fbb6e 100644 --- a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs @@ -104,12 +104,6 @@ namespace Umbraco.Web.Macros if (currentPage == null) throw new ArgumentNullException("currentPage"); if (macro.ScriptName.IsNullOrWhiteSpace()) throw new ArgumentException("The ScriptName property of the macro object cannot be null or empty"); - //if (!macro.ScriptName.StartsWith(SystemDirectories.MvcViews + "/MacroPartials/") - // && (!Regex.IsMatch(macro.ScriptName, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled))) - //{ - // throw new InvalidOperationException("Cannot render the Partial View Macro with file: " + macro.ScriptName + ". All Partial View Macros must exist in the " + SystemDirectories.MvcViews + "/MacroPartials/ folder"); - //} - var http = _getHttpContext(); var umbCtx = _getUmbracoContext(); var routeVals = new RouteData(); diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index 180d69a015..d2ad5fe292 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -231,20 +231,20 @@ namespace umbraco return renderMacro(pageElements, pageId); } - public delegate void RenderEventHandler(MacroModel sender, RenderEventArgs e); - public new static event RenderEventHandler BeforeRender; - protected virtual void FireBeforeRender(RenderEventArgs e) + public delegate void OnMacroRenderingEventHandler(macro sender, EventArgs e); + public static event OnMacroRenderingEventHandler OnMacroRendering; + protected void FireOnMacroRendering(EventArgs e) { - if (BeforeRender != null) - BeforeRender(Model, e); + if (OnMacroRendering != null) + OnMacroRendering(this, e); } public Control renderMacro(Hashtable pageElements, int pageId) { // Event to allow manipulation of Macro Model - var rea = new RenderEventArgs(); - FireBeforeRender(rea); + var rea = new EventArgs(); + FireOnMacroRendering(rea); var macroInfo = (Model.MacroType == MacroTypes.Script && Model.Name.IsNullOrWhiteSpace()) @@ -1966,6 +1966,6 @@ namespace umbraco #endregion } - public class RenderEventArgs : System.ComponentModel.CancelEventArgs { } + public class MacroRenderingEventArgs : System.EventArgs { } } \ No newline at end of file From 1781528390546652f36eac6a56213586c306ae69 Mon Sep 17 00:00:00 2001 From: neehouse Date: Tue, 10 Sep 2013 09:36:09 -0400 Subject: [PATCH 4/4] Removing Whitespace --- src/Umbraco.Web/umbraco.presentation/macro.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index d2ad5fe292..a3348e76a2 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -239,14 +239,12 @@ namespace umbraco OnMacroRendering(this, e); } - public Control renderMacro(Hashtable pageElements, int pageId) { // Event to allow manipulation of Macro Model var rea = new EventArgs(); FireOnMacroRendering(rea); - var macroInfo = (Model.MacroType == MacroTypes.Script && Model.Name.IsNullOrWhiteSpace()) ? string.Format("Render Inline Macro, Cache: {0})", Model.CacheDuration) : string.Format("Render Macro: {0}, type: {1}, cache: {2})", Name, Model.MacroType, Model.CacheDuration);