From f99e8ab793cb1934ba6d0b6978180970c0ea65bd Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 21 Feb 2011 17:49:34 -0800 Subject: [PATCH] Adding ability to override the content of a shape - Using ShapeDispayingContext.ChildContent to force the HmlString to render --HG-- branch : dev --- .../DefaultDisplayManagerTests.cs | 29 +++++++++++++++++++ .../Core/Contents/Views/Admin/Create.cshtml | 2 +- .../Implementation/IShapeDisplayEvents.cs | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Tests/DisplayManagement/DefaultDisplayManagerTests.cs b/src/Orchard.Tests/DisplayManagement/DefaultDisplayManagerTests.cs index e05bec7c3..c3d2099ba 100644 --- a/src/Orchard.Tests/DisplayManagement/DefaultDisplayManagerTests.cs +++ b/src/Orchard.Tests/DisplayManagement/DefaultDisplayManagerTests.cs @@ -145,6 +145,35 @@ namespace Orchard.Tests.DisplayManagement { Assert.That(result.ToString(), Is.EqualTo("Hi there!")); } + [Test] + public void RenderPreCalculatedShape() { + var displayManager = _container.Resolve(); + + var shape = new Shape { + Metadata = new ShapeMetadata { + Type = "Foo" + } + }; + + shape.Metadata.OnDisplaying( + context => { + context.ChildContent = new HtmlString("Bar"); + }); + + var descriptor = new ShapeDescriptor { + ShapeType = "Foo", + }; + descriptor.Bindings["Foo"] = new ShapeBinding { + BindingName = "Foo", + Binding = ctx => new HtmlString("Hi there!"), + }; + + AddShapeDescriptor(descriptor); + + var result = displayManager.Execute(CreateDisplayContext(shape)); + Assert.That(result.ToString(), Is.EqualTo("Bar")); + } + [Test] public void RenderFallbackShape() { var displayManager = _container.Resolve(); diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/Create.cshtml b/src/Orchard.Web/Core/Contents/Views/Admin/Create.cshtml index 086ac38b1..471b54362 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/Create.cshtml +++ b/src/Orchard.Web/Core/Contents/Views/Admin/Create.cshtml @@ -7,6 +7,6 @@ @using (Html.BeginFormAntiForgeryPost()) { @Html.ValidationSummary() -// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type + // Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type @Display(Model) } \ No newline at end of file diff --git a/src/Orchard/DisplayManagement/Implementation/IShapeDisplayEvents.cs b/src/Orchard/DisplayManagement/Implementation/IShapeDisplayEvents.cs index 063a3f99a..6f1c678fb 100644 --- a/src/Orchard/DisplayManagement/Implementation/IShapeDisplayEvents.cs +++ b/src/Orchard/DisplayManagement/Implementation/IShapeDisplayEvents.cs @@ -10,6 +10,7 @@ namespace Orchard.DisplayManagement.Implementation { public class ShapeDisplayingContext { public dynamic Shape { get; set; } public ShapeMetadata ShapeMetadata { get; set; } + public IHtmlString ChildContent { get; set; } } public class ShapeDisplayedContext {