--HG--
branch : mvc3p1
This commit is contained in:
Nathan Heskew
2010-08-30 21:51:27 -07:00
3 changed files with 15 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions.Models;
@@ -24,10 +25,9 @@ namespace Orchard.DisplayManagement.Descriptors {
public class ShapeDescriptor {
public string ShapeType { get; set; }
public ShapeBinding Binding { get; set; }
public Func<DisplayContext, IHtmlString> Binding { get; set; }
}
public delegate object ShapeBinding(DisplayContext displayContext);
public class ShapeTableBuilder {
readonly IList<ShapeDescriptorAlterationBuilderImpl> _descriptorBuilders = new List<ShapeDescriptorAlterationBuilderImpl>();
@@ -89,11 +89,11 @@ namespace Orchard.DisplayManagement.Descriptors {
return this;
}
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, ShapeBinding> binder) {
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
// schedule the configuration
return Configure(descriptor => {
ShapeBinding target = null;
Func<DisplayContext, IHtmlString> target = null;
// announce the binding, which may be reconfigured before it's used
descriptor.Binding = displayContext => {

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;
using Autofac;
using Autofac.Core;
using Microsoft.CSharp.RuntimeBinder;
@@ -34,7 +35,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
}
}
private ShapeBinding CreateDelegate(
private Func<DisplayContext, IHtmlString> CreateDelegate(
ShapeAttributeOccurrence attributeOccurrence,
ShapeDescriptor descriptor) {
return context => {
@@ -46,11 +47,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
}
private object PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance) {
private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance) {
var arguments = methodInfo.GetParameters()
.Select(parameter => BindParameter(displayContext, parameter));
return methodInfo.Invoke(serviceInstance, arguments.ToArray());
return CoerceHtmlString(methodInfo.Invoke(serviceInstance, arguments.ToArray()));
}
private static IHtmlString CoerceHtmlString(object invoke) {
return invoke as IHtmlString ?? (invoke != null ? new HtmlString(invoke.ToString()) : null);
}
private object BindParameter(DisplayContext displayContext, ParameterInfo parameter) {

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Orchard.DisplayManagement.Implementation;
@@ -79,7 +80,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
}
}
private object Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);