mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : mvc3p1
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
using Orchard.DisplayManagement.Implementation;
|
using Orchard.DisplayManagement.Implementation;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
@@ -24,10 +25,9 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
|
|
||||||
public class ShapeDescriptor {
|
public class ShapeDescriptor {
|
||||||
public string ShapeType { get; set; }
|
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 {
|
public class ShapeTableBuilder {
|
||||||
readonly IList<ShapeDescriptorAlterationBuilderImpl> _descriptorBuilders = new List<ShapeDescriptorAlterationBuilderImpl>();
|
readonly IList<ShapeDescriptorAlterationBuilderImpl> _descriptorBuilders = new List<ShapeDescriptorAlterationBuilderImpl>();
|
||||||
@@ -89,11 +89,11 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, ShapeBinding> binder) {
|
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
|
||||||
// schedule the configuration
|
// schedule the configuration
|
||||||
return Configure(descriptor => {
|
return Configure(descriptor => {
|
||||||
|
|
||||||
ShapeBinding target = null;
|
Func<DisplayContext, IHtmlString> target = null;
|
||||||
|
|
||||||
// announce the binding, which may be reconfigured before it's used
|
// announce the binding, which may be reconfigured before it's used
|
||||||
descriptor.Binding = displayContext => {
|
descriptor.Binding = displayContext => {
|
||||||
|
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Web;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Core;
|
using Autofac.Core;
|
||||||
using Microsoft.CSharp.RuntimeBinder;
|
using Microsoft.CSharp.RuntimeBinder;
|
||||||
@@ -34,7 +35,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShapeBinding CreateDelegate(
|
private Func<DisplayContext, IHtmlString> CreateDelegate(
|
||||||
ShapeAttributeOccurrence attributeOccurrence,
|
ShapeAttributeOccurrence attributeOccurrence,
|
||||||
ShapeDescriptor descriptor) {
|
ShapeDescriptor descriptor) {
|
||||||
return context => {
|
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()
|
var arguments = methodInfo.GetParameters()
|
||||||
.Select(parameter => BindParameter(displayContext, parameter));
|
.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) {
|
private object BindParameter(DisplayContext displayContext, ParameterInfo parameter) {
|
||||||
|
@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Mvc.Html;
|
using System.Web.Mvc.Html;
|
||||||
using Orchard.DisplayManagement.Implementation;
|
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);
|
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
|
||||||
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
||||||
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);
|
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);
|
||||||
|
Reference in New Issue
Block a user