Adding ability to override the content of a shape

- Using ShapeDispayingContext.ChildContent to force the HmlString to render

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-21 17:49:34 -08:00
parent c26cc0973e
commit f99e8ab793
3 changed files with 31 additions and 1 deletions

View File

@@ -145,6 +145,35 @@ namespace Orchard.Tests.DisplayManagement {
Assert.That(result.ToString(), Is.EqualTo("Hi there!"));
}
[Test]
public void RenderPreCalculatedShape() {
var displayManager = _container.Resolve<IDisplayManager>();
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<IDisplayManager>();

View File

@@ -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)
}

View File

@@ -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 {