From d83887e314338628ed266bce7b3854bb0e36f027 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sat, 8 Sep 2012 11:30:19 +0700 Subject: [PATCH] Ported updates to DynamicDocument to allow dynamic access to RTE content and still have it render all embedded macro content without resorting to use some other mechanism. Fixes the .Field method of the UmbracoHelper. --- .../config/umbracoSettings.Release.config | 4 ++++ .../config/umbracoSettings.config | 4 ++++ src/Umbraco.Web/Properties/AssemblyInfo.cs | 3 ++- ...roRenderingPropertyEditorValueConverter.cs | 6 +---- src/Umbraco.Web/UmbracoHelper.cs | 1 - .../HtmlStringDataTypeModel.cs | 23 ++++++++++++++++++- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config index fd7917ef47..2e6277929d 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config @@ -168,6 +168,10 @@ + true true diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index 283c04f5b8..c28455a162 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -130,6 +130,10 @@ + true true diff --git a/src/Umbraco.Web/Properties/AssemblyInfo.cs b/src/Umbraco.Web/Properties/AssemblyInfo.cs index 619c605a57..88d65e23cc 100644 --- a/src/Umbraco.Web/Properties/AssemblyInfo.cs +++ b/src/Umbraco.Web/Properties/AssemblyInfo.cs @@ -27,4 +27,5 @@ using System.Security; // if we remove this class then we won't need to do this. [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)] -[assembly: InternalsVisibleTo("Umbraco.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("umbraco.MacroEngines")] \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs b/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs index 42a8b11bb6..6f435c3d19 100644 --- a/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs @@ -22,11 +22,7 @@ namespace Umbraco.Web.PropertyEditors /// public override Attempt ConvertPropertyValue(object value) { - //TODO: we need to make a few new classes, like a new MacroParser, etc... and move a bunch of the logic - // out of 'Item' that does all of this but it will be tricky because of the way that it creates a 'Macro' class - // we may have to do some server Execute trickyness. - // Then, we need to add this to the resolver and remove the base class and make it abstract. - + //we're going to send the string through the macro parser and create the output string. var sb = new StringBuilder(); var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); MacroTagParser.ParseMacros( diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index ec632f1d45..abbdd0324a 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -202,7 +202,6 @@ namespace Umbraco.Web ItemRenderer.Instance.Init(item); ItemRenderer.Instance.Load(item); ItemRenderer.Instance.Render(item, htmlWriter); - _umbracoContext.HttpContext.Server.Execute(containerPage, output, false); return new HtmlString(output.ToString()); } } diff --git a/src/umbraco.MacroEngines/RazorDataTypeModels/HtmlStringDataTypeModel.cs b/src/umbraco.MacroEngines/RazorDataTypeModels/HtmlStringDataTypeModel.cs index 400ca879f5..bb96bbbc6d 100644 --- a/src/umbraco.MacroEngines/RazorDataTypeModels/HtmlStringDataTypeModel.cs +++ b/src/umbraco.MacroEngines/RazorDataTypeModels/HtmlStringDataTypeModel.cs @@ -3,14 +3,35 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; +using Umbraco.Core; +using Umbraco.Core.Macros; +using Umbraco.Web; namespace umbraco.MacroEngines.RazorDataTypeModels { + /// + /// This ensures that the RTE renders with HtmlString encoding and also ensures that the macro contents in it + /// render properly too. + /// + [RazorDataTypeModel("5e9b75ae-face-41c8-b47e-5f4b0fd82f83", 90)] public class HtmlStringDataTypeModel : IRazorDataTypeModel { public bool Init(int CurrentNodeId, string PropertyData, out object instance) { - instance = new HtmlString(PropertyData); + //we're going to send the string through the macro parser and create the output string. + var sb = new StringBuilder(); + var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); + MacroTagParser.ParseMacros( + PropertyData, + //callback for when text block is found + textBlock => sb.Append(textBlock), + //callback for when macro syntax is found + (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro( + macroAlias, + //needs to be explicitly casted to Dictionary + macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString())); + + instance = new HtmlString(sb.ToString()); return true; } }