From 123e4681f3e856151877f291b7d2fc8937718896 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 10 May 2011 20:49:17 -0700 Subject: [PATCH] Fixing Json formatting in Shape Tracing --HG-- branch : 1.x --- .../Orchard.DesignerTools/Services/ShapeTracingFactory.cs | 2 +- .../Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs index 2f3b05b0f..6b93ab57a 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs @@ -190,7 +190,7 @@ namespace Orchard.DesignerTools.Services { } } - private static string FormatJsonValue(string value) { + public static string FormatJsonValue(string value) { // replace " by \" in json strings return value.Replace(@"\", @"\\").Replace("\"", @"\""").Replace("\r\n", @"\n").Replace("\r", @"\n").Replace("\n", @"\n"); } diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml index 4616422b1..87bcf05d5 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml @@ -1,4 +1,5 @@ @using Orchard.Utility.Extensions; +@using Orchard.DesignerTools.Services; @functions { string FormatShapeName(string shape) { @@ -59,14 +60,14 @@ shapeTracingMetadataHost[@Model.ShapeId].shape = { } ], - html: '@RemoveEmptyLines(RemoveBeacons(Display(Model.ChildContent).ToString())).Replace(Environment.NewLine, "\\n")', - templateContent: '@(String.IsNullOrWhiteSpace((string)Model.TemplateContent) ? @T("Content not available as coming from source code.") : @Model.TemplateContent.Replace(Environment.NewLine, "\\n"))', + html: '@ShapeTracingFactory.FormatJsonValue(RemoveEmptyLines(RemoveBeacons(Display(Model.ChildContent).ToString())))', + templateContent: '@(ShapeTracingFactory.FormatJsonValue(String.IsNullOrWhiteSpace((string)Model.TemplateContent) ? @T("Content not available as coming from source code.").ToString() : (string)Model.TemplateContent))', model: { @(new MvcHtmlString((string)@Model.Dump)) } }; @if (!String.IsNullOrEmpty((string)Model.PlacementSource) && (WorkContext.HttpContext.Items[(string)Model.PlacementSource] == null)) { WorkContext.HttpContext.Items[(string)Model.PlacementSource] = new object(); -shapeTracingMetadataHost.placement['@Model.PlacementSource.ToString()'] = '@Model.PlacementContent.Replace(Environment.NewLine, "\\n")'; +shapeTracingMetadataHost.placement['@Model.PlacementSource.ToString()'] = '@ShapeTracingFactory.FormatJsonValue((string)Model.PlacementContent)'; }