mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Renaming and relocating things in the DisplayManagement namespace
--HG-- branch : mvc3p1
This commit is contained in:
@@ -19,14 +19,14 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
|
||||
[Test]
|
||||
public void ShapeTableRecognizesMethodNames() {
|
||||
var stf = CreateShapeTableFactory(cfg => cfg.RegisterType<Test>().As<IShapeProvider>());
|
||||
var stf = CreateShapeTableFactory(cfg => cfg.RegisterType<Test>().As<IShapeDriver>());
|
||||
var shapeTable = stf.CreateShapeTable();
|
||||
Assert.That(shapeTable.Entries.Count(), Is.EqualTo(2));
|
||||
Assert.That(shapeTable.Entries.ContainsKey("Pager"));
|
||||
Assert.That(shapeTable.Entries.ContainsKey("Email"));
|
||||
}
|
||||
|
||||
public class Test : IShapeProvider {
|
||||
public class Test : IShapeDriver {
|
||||
public void Pager() {
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ using ClaySharp.Implementation;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
@@ -18,14 +19,14 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
var shapeFactory = new Mock<IShapeFactory>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var displayHelper = displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
var displayHelper = displayHelperFactory.CreateHelper(viewContext, null);
|
||||
|
||||
displayHelper.Invoke("Pager", ArgsUtility.Positional(1, 2, 3, 4));
|
||||
|
||||
shapeFactory.Verify(sf=>sf.Build("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
shapeFactory.Verify(sf => sf.Create("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
//displayManager.Verify(dm => dm.Execute(It.IsAny<Shape>(), viewContext, null));
|
||||
}
|
||||
[Test]
|
||||
@@ -33,14 +34,14 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
var shapeFactory = new Mock<IShapeFactory>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var display = (dynamic)displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
var display = (dynamic)displayHelperFactory.CreateHelper(viewContext, null);
|
||||
|
||||
display.Pager(1, 2, 3, 4);
|
||||
|
||||
shapeFactory.Verify(sf => sf.Build("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
shapeFactory.Verify(sf => sf.Create("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
//displayManager.Verify(dm => dm.Execute(It.IsAny<Shape>(), viewContext, null));
|
||||
}
|
||||
|
||||
@@ -51,10 +52,10 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
var shapeFactory = new Mock<IShapeFactory>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var display = (dynamic)displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
var display = (dynamic)displayHelperFactory.CreateHelper(viewContext, null);
|
||||
var outline = new Shape { Attributes = new ShapeAttributes { Type = "Outline" } };
|
||||
display(outline);
|
||||
|
||||
|
@@ -15,23 +15,23 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShapeHasAttributesType() {
|
||||
var factory = _container.Resolve<IShapeBuilder>();
|
||||
dynamic foo = factory.Build("Foo", ArgsUtility.Empty());
|
||||
var factory = _container.Resolve<IShapeFactory>();
|
||||
dynamic foo = factory.Create("Foo", ArgsUtility.Empty());
|
||||
ShapeAttributes attributes = foo.Attributes;
|
||||
Assert.That(attributes.Type, Is.EqualTo("Foo"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateShapeWithNamedArguments() {
|
||||
var factory = _container.Resolve<IShapeBuilder>();
|
||||
var foo = factory.Build("Foo", ArgsUtility.Named(new { one = 1, two = "dos" }));
|
||||
var factory = _container.Resolve<IShapeFactory>();
|
||||
var foo = factory.Create("Foo", ArgsUtility.Named(new { one = 1, two = "dos" }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
@@ -16,14 +17,14 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
_container = builder.Build();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatingNewShapeTypeByName() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateHelper();
|
||||
|
||||
var alpha = shape.Alpha();
|
||||
|
||||
@@ -32,7 +33,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
|
||||
[Test]
|
||||
public void CreatingShapeWithAdditionalNamedParameters() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateHelper();
|
||||
|
||||
var alpha = shape.Alpha(one: 1, two: "dos");
|
||||
|
||||
@@ -43,7 +44,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
|
||||
[Test]
|
||||
public void WithPropertyBearingObjectInsteadOfNamedParameters() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateHelper();
|
||||
|
||||
var alpha = shape.Alpha(new { one = 1, two = "dos" });
|
||||
|
||||
|
@@ -7,6 +7,7 @@ using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Secondary;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
@@ -19,15 +20,15 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
builder.RegisterType<DefaultShapeTableFactory>().As<IShapeTableFactory>();
|
||||
builder.RegisterType<SimpleShapes>().As<IShapeProvider>();
|
||||
builder.RegisterType<SimpleShapes>().As<IShapeDriver>();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
public class SimpleShapes : IShapeProvider {
|
||||
public class SimpleShapes : IShapeDriver {
|
||||
public IHtmlString Something() {
|
||||
return new HtmlString("<br/>");
|
||||
}
|
||||
@@ -41,9 +42,9 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
public void RenderingSomething() {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
dynamic Display = _container.Resolve<IDisplayHelperFactory>().CreateDisplayHelper(viewContext, null);
|
||||
dynamic Display = _container.Resolve<IDisplayHelperFactory>().CreateHelper(viewContext, null);
|
||||
|
||||
dynamic New = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
dynamic New = _container.Resolve<IShapeHelperFactory>().CreateHelper();
|
||||
|
||||
var result1 = Display.Something();
|
||||
var result2 = ((DisplayHelper)Display).ShapeExecute((Shape)New.Pager());
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DevTools.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
@@ -8,6 +9,7 @@ using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.DevTools.Controllers {
|
||||
[Themed]
|
||||
@@ -18,7 +20,7 @@ namespace Orchard.DevTools.Controllers {
|
||||
public HomeController(INotifier notifier, IShapeHelperFactory shapeHelperFactory) {
|
||||
_notifier = notifier;
|
||||
T = NullLocalizer.Instance;
|
||||
New = shapeHelperFactory.CreateShapeHelper();
|
||||
New = shapeHelperFactory.CreateHelper();
|
||||
}
|
||||
|
||||
dynamic New { get; set; }
|
||||
@@ -52,16 +54,26 @@ namespace Orchard.DevTools.Controllers {
|
||||
return View("Simple", new Simple { Title = "This is not themed", Quantity = 5 });
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ActionResult UsingShapes() {
|
||||
|
||||
ViewModel.Page = New.Page()
|
||||
.Main(New.Zone(typeof(Array), Name: "Main"))
|
||||
.Messages(New.Zone(typeof(Array), Name: "Main"))
|
||||
.Sidebar(New.Zone(typeof(Array), Name: "Main"));
|
||||
.Main(New.Zone(typeof (Array), Name: "Main"))
|
||||
.Messages(New.Zone(typeof (Array), Name: "Messages"))
|
||||
.Sidebar(New.Zone(typeof (Array), Name: "Sidebar"));
|
||||
|
||||
ViewModel.Page.Add("Messages:5", New.Message(Content: T("This is a test"), Severity: "Really bad!!!"));
|
||||
|
||||
ViewModel.Page.Messages.Add(
|
||||
New.Message(Content: T("This is a test"), Severity: "Really bad!!!"));
|
||||
|
||||
var model = New.Explosion(Height: 100, Width: 200);
|
||||
var model = New.Message(
|
||||
Content: New.Explosion(Height: 100, Width: 200),
|
||||
Severity: "Meh");
|
||||
|
||||
ViewModel.Page.Messages.Add(new HtmlString("<hr/>abuse<hr/>"));
|
||||
ViewModel.Page.Messages.Add("<hr/>encoded<hr/>");
|
||||
|
||||
return View("UsingShapes", model);
|
||||
}
|
||||
@@ -70,7 +82,5 @@ namespace Orchard.DevTools.Controllers {
|
||||
return view.Model.Box.Title;
|
||||
}
|
||||
}
|
||||
public class MyViewModel {
|
||||
public dynamic Box { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,13 +6,13 @@ using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.DevTools {
|
||||
public class Shapes : IShapeProvider {
|
||||
public class Shapes : IShapeDriver {
|
||||
public IHtmlString Title(dynamic text) {
|
||||
return new HtmlString("<h2>" + text + "</h2>");
|
||||
}
|
||||
|
||||
public IHtmlString Explosion(int Height, int Width) {
|
||||
return new HtmlString(string.Format("<div>Boom {0}x{1}</div>", Height, Width));
|
||||
public IHtmlString Explosion(int? Height, int? Width) {
|
||||
return new HtmlString(string.Format("<span>Boom {0}x{1}</span>", Height, Width));
|
||||
}
|
||||
|
||||
public IHtmlString Page(dynamic Display, dynamic Shape) {
|
||||
@@ -29,7 +29,7 @@ namespace Orchard.DevTools {
|
||||
}
|
||||
|
||||
public IHtmlString Message(dynamic Display, object Content, string Severity) {
|
||||
return Display(Severity, ": ", Content);
|
||||
return Display(new HtmlString("<p class=\"message\">"), Severity ?? "Neutral", ": ", Content, new HtmlString("</p>"));
|
||||
}
|
||||
|
||||
private static IHtmlString Smash(IEnumerable<IHtmlString> contents) {
|
||||
|
@@ -1,8 +1,14 @@
|
||||
<div>
|
||||
|
||||
@Display.Title(text:"This is everything")
|
||||
@Display(Model)
|
||||
a @Display.Title(text:"This is everything")
|
||||
b @Display(Model)
|
||||
|
||||
@Display(View.Page)
|
||||
c @Display(View.Page)
|
||||
|
||||
d @Display.Message(Content:"Madness!!!")
|
||||
|
||||
e @Display.Explosion(Width:40)
|
||||
|
||||
f @Display.Message(Content: @Display.Explosion(Height:10,Width:15))
|
||||
|
||||
</div>
|
||||
|
@@ -12,6 +12,7 @@ using Orchard.Data.Migration.Interpreters;
|
||||
using Orchard.Data.Providers;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Secondary;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Environment.Extensions;
|
||||
@@ -64,7 +65,7 @@ namespace Orchard.Setup {
|
||||
// in progress - adding services for display/shape support in setup
|
||||
builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
|
||||
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DefaultShapeTableFactory>().As<IShapeTableFactory>();
|
||||
}
|
||||
|
||||
|
@@ -1,7 +0,0 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IDisplayHelperFactory : IDependency {
|
||||
DisplayHelper CreateDisplayHelper(ViewContext viewContext, IViewDataContainer viewDataContainer);
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class ShapeHelperFactory : IShapeHelperFactory {
|
||||
static private readonly ShapeHelperBehavior[] _behaviors = new[] { new ShapeHelperBehavior() };
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public ShapeHelperFactory(IShapeBuilder shapeBuilder) {
|
||||
_shapeBuilder = shapeBuilder;
|
||||
}
|
||||
|
||||
public ShapeHelper CreateShapeHelper() {
|
||||
return (ShapeHelper)ClayActivator.CreateInstance<ShapeHelper>(
|
||||
_behaviors,
|
||||
_shapeBuilder);
|
||||
}
|
||||
|
||||
class ShapeHelperBehavior : ClayBehavior {
|
||||
public override object InvokeMember(Func<object> proceed, object target, string name, INamedEnumerable<object> args) {
|
||||
return ((ShapeHelper)target).CreateShapeType(name, args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
src/Orchard/DisplayManagement/IDisplayHelperFactory.cs
Normal file
11
src/Orchard/DisplayManagement/IDisplayHelperFactory.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
/// Used to create a dynamic, contextualized Display object to dispatch shape rendering
|
||||
/// </summary>
|
||||
public interface IDisplayHelperFactory : IDependency {
|
||||
dynamic CreateHelper(ViewContext viewContext, IViewDataContainer viewDataContainer);
|
||||
}
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IDisplayManager : IDependency {
|
||||
IHtmlString Execute(DisplayContext context);
|
||||
}
|
||||
}
|
13
src/Orchard/DisplayManagement/IShape.cs
Normal file
13
src/Orchard/DisplayManagement/IShape.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
/// Interface present on dynamic shapes.
|
||||
/// May be used to access attributes in a strongly typed fashion.
|
||||
/// Note: Anything on this interface is a reserved word for the purpose of shape properties
|
||||
/// </summary>
|
||||
public interface IShape {
|
||||
IShapeAttributes Attributes { get; set; }
|
||||
}
|
||||
}
|
6
src/Orchard/DisplayManagement/IShapeAttributes.cs
Normal file
6
src/Orchard/DisplayManagement/IShapeAttributes.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeAttributes {
|
||||
string Type { get; set; }
|
||||
string Position { get; set; }
|
||||
}
|
||||
}
|
7
src/Orchard/DisplayManagement/IShapeDriver.cs
Normal file
7
src/Orchard/DisplayManagement/IShapeDriver.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
/// Base interface for module components which define new shape types and
|
||||
/// optionally provide default implementation method
|
||||
/// </summary>
|
||||
public interface IShapeDriver : IDependency{}
|
||||
}
|
12
src/Orchard/DisplayManagement/IShapeFactory.cs
Normal file
12
src/Orchard/DisplayManagement/IShapeFactory.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
/// Service that creates new instances of dynamic shape objects
|
||||
/// This may be used directly, or through the IShapeHelperFactory.
|
||||
/// </summary>
|
||||
public interface IShapeFactory : IDependency {
|
||||
IShape Create(string shapeType, INamedEnumerable<object> parameters);
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeHelperFactory : IDependency {
|
||||
ShapeHelper CreateShapeHelper();
|
||||
dynamic CreateHelper();
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Localization;
|
||||
|
||||
@@ -12,7 +13,12 @@ namespace Orchard.DisplayManagement.Secondary {
|
||||
public class DefaultDisplayManager : IDisplayManager {
|
||||
private readonly IShapeTableFactory _shapeTableFactory;
|
||||
|
||||
private static CallSite<Func<CallSite, object, Shape>> _convertAsShapeCallsite;
|
||||
private static CallSite<Func<CallSite, object, IShape>> _convertAsShapeCallsite = CallSite<Func<CallSite, object, IShape>>.Create(
|
||||
new ForgivingConvertBinder(
|
||||
(ConvertBinder)Binder.Convert(
|
||||
CSharpBinderFlags.ConvertExplicit | CSharpBinderFlags.CheckedContext,
|
||||
typeof(IShape),
|
||||
null/*typeof(DefaultDisplayManager)*/)));
|
||||
|
||||
public DefaultDisplayManager(IShapeTableFactory shapeTableFactory) {
|
||||
_shapeTableFactory = shapeTableFactory;
|
||||
@@ -23,14 +29,6 @@ namespace Orchard.DisplayManagement.Secondary {
|
||||
|
||||
|
||||
public IHtmlString Execute(DisplayContext context) {
|
||||
if (_convertAsShapeCallsite == null) {
|
||||
_convertAsShapeCallsite = CallSite<Func<CallSite, object, Shape>>.Create(
|
||||
new ForgivingConvertBinder(
|
||||
(ConvertBinder)Binder.Convert(
|
||||
CSharpBinderFlags.ConvertExplicit | CSharpBinderFlags.CheckedContext,
|
||||
typeof(Shape),
|
||||
null/*typeof(DefaultDisplayManager)*/)));
|
||||
}
|
||||
var shape = _convertAsShapeCallsite.Target(_convertAsShapeCallsite, context.Value);
|
||||
|
||||
// non-shape arguements are returned as a no-op
|
||||
@@ -61,7 +59,7 @@ namespace Orchard.DisplayManagement.Secondary {
|
||||
return new HtmlString(HttpUtility.HtmlEncode(value));
|
||||
}
|
||||
|
||||
private IHtmlString Process(ShapeTable.Entry entry, Shape shape, DisplayContext context) {
|
||||
private IHtmlString Process(ShapeTable.Entry entry, IShape shape, DisplayContext context) {
|
||||
return CoerceHtmlString(entry.Target(context));
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@ using System.Linq;
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class DefaultShapeBuilder : IShapeBuilder {
|
||||
public Shape Build(string shapeType, INamedEnumerable<object> parameters) {
|
||||
public class DefaultShapeFactory : IShapeFactory {
|
||||
public IShape Create(string shapeType, INamedEnumerable<object> parameters) {
|
||||
|
||||
var positional = parameters.Positional;
|
||||
|
@@ -4,22 +4,27 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Refactor: I this doesn't really need to exist, does it?
|
||||
/// It can all be an aspect of a display helper behavior implementation...
|
||||
/// Or should this remain a CLR type for clarity?
|
||||
/// </summary>
|
||||
public class DisplayHelper {
|
||||
private readonly IDisplayManager _displayManager;
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
|
||||
public DisplayHelper(
|
||||
IDisplayManager displayManager,
|
||||
IShapeBuilder shapeBuilder,
|
||||
IShapeFactory shapeFactory,
|
||||
ViewContext viewContext,
|
||||
IViewDataContainer viewDataContainer) {
|
||||
_displayManager = displayManager;
|
||||
_shapeBuilder = shapeBuilder;
|
||||
_shapeFactory = shapeFactory;
|
||||
ViewContext = viewContext;
|
||||
ViewDataContainer = viewDataContainer;
|
||||
}
|
||||
@@ -60,7 +65,7 @@ namespace Orchard.DisplayManagement {
|
||||
}
|
||||
|
||||
private object ShapeTypeExecute(string name, INamedEnumerable<object> parameters) {
|
||||
var shape = _shapeBuilder.Build(name, parameters);
|
||||
var shape = _shapeFactory.Create(name, parameters);
|
||||
return ShapeExecute(shape);
|
||||
}
|
||||
|
@@ -1,24 +1,25 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class DisplayHelperFactory : IDisplayHelperFactory {
|
||||
static private readonly DisplayHelperBehavior[] _behaviors = new[] { new DisplayHelperBehavior() };
|
||||
private readonly IDisplayManager _displayManager;
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
|
||||
public DisplayHelperFactory(IDisplayManager displayManager, IShapeBuilder shapeBuilder) {
|
||||
public DisplayHelperFactory(IDisplayManager displayManager, IShapeFactory shapeFactory) {
|
||||
_displayManager = displayManager;
|
||||
_shapeBuilder = shapeBuilder;
|
||||
_shapeFactory = shapeFactory;
|
||||
}
|
||||
|
||||
public DisplayHelper CreateDisplayHelper(ViewContext viewContext, IViewDataContainer viewDataContainer) {
|
||||
return (DisplayHelper)ClayActivator.CreateInstance<DisplayHelper>(
|
||||
public dynamic CreateHelper(ViewContext viewContext, IViewDataContainer viewDataContainer) {
|
||||
return ClayActivator.CreateInstance<DisplayHelper>(
|
||||
_behaviors,
|
||||
_displayManager,
|
||||
_shapeBuilder,
|
||||
_shapeFactory,
|
||||
viewContext,
|
||||
viewDataContainer);
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.DisplayManagement.Implementation {
|
||||
/// <summary>
|
||||
/// Coordinates the rendering of shapes.
|
||||
/// This interface isn't used directly - instead you would call through a
|
||||
/// DisplayHelper created by the IDisplayHelperFactory interface
|
||||
/// </summary>
|
||||
public interface IDisplayManager : IDependency {
|
||||
IHtmlString Execute(DisplayContext context);
|
||||
}
|
||||
}
|
15
src/Orchard/DisplayManagement/Implementation/ShapeHelper.cs
Normal file
15
src/Orchard/DisplayManagement/Implementation/ShapeHelper.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Implementation {
|
||||
public class ShapeHelper {
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
|
||||
public ShapeHelper(IShapeFactory shapeFactory) {
|
||||
_shapeFactory = shapeFactory;
|
||||
}
|
||||
|
||||
public IShape CreateShapeType(string shapeType, INamedEnumerable<object> parameters) {
|
||||
return _shapeFactory.Create(shapeType, parameters);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Implementation {
|
||||
public class ShapeHelperFactory : IShapeHelperFactory {
|
||||
static private readonly ShapeHelperBehavior[] _behaviors = new[] { new ShapeHelperBehavior() };
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
|
||||
public ShapeHelperFactory(IShapeFactory shapeFactory) {
|
||||
_shapeFactory = shapeFactory;
|
||||
}
|
||||
|
||||
public dynamic CreateHelper() {
|
||||
return ClayActivator.CreateInstance<ShapeHelper>(
|
||||
_behaviors,
|
||||
_shapeFactory);
|
||||
}
|
||||
|
||||
class ShapeHelperBehavior : ClayBehavior {
|
||||
public override object InvokeMember(Func<object> proceed, object target, string name, INamedEnumerable<object> args) {
|
||||
return ((ShapeHelper)target).CreateShapeType(name, args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class ShapeHelper {
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public ShapeHelper(IShapeBuilder shapeBuilder) {
|
||||
_shapeBuilder = shapeBuilder;
|
||||
}
|
||||
|
||||
public Shape CreateShapeType(string shapeType, INamedEnumerable<object> parameters) {
|
||||
return _shapeBuilder.Build(shapeType, parameters);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public interface IShapeBuilder : IDependency {
|
||||
Shape Build(string shapeType, INamedEnumerable<object> parameters);
|
||||
}
|
||||
}
|
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class Shape {
|
||||
public virtual ShapeAttributes Attributes { get; set; }
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class Shape : IShape {
|
||||
public virtual IShapeAttributes Attributes { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class ShapeAttributes {
|
||||
public class ShapeAttributes : IShapeAttributes {
|
||||
public string Type { get; set; }
|
||||
public string Position { get; set; }
|
||||
}
|
||||
|
@@ -1,13 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Web;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Binder = Microsoft.CSharp.RuntimeBinder.Binder;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class DefaultShapeTableFactory : IShapeTableFactory {
|
||||
private readonly IEnumerable<IShapeProvider> _shapeProviders;
|
||||
private readonly IEnumerable<IShapeDriver> _shapeProviders;
|
||||
|
||||
public DefaultShapeTableFactory(IEnumerable<IShapeProvider> shapeProviders) {
|
||||
public DefaultShapeTableFactory(IEnumerable<IShapeDriver> shapeProviders) {
|
||||
_shapeProviders = shapeProviders;
|
||||
}
|
||||
|
||||
@@ -29,13 +35,13 @@ namespace Orchard.DisplayManagement {
|
||||
}
|
||||
}
|
||||
|
||||
private object PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, IShapeProvider shapeProvider) {
|
||||
private object PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, IShapeDriver shapeDriver) {
|
||||
// oversimplification for the sake of evolving
|
||||
dynamic shape = displayContext.Value;
|
||||
var arguments = methodInfo.GetParameters()
|
||||
.Select(parameter => BindParameter(displayContext, parameter));
|
||||
|
||||
return methodInfo.Invoke(shapeProvider, arguments.ToArray());
|
||||
return methodInfo.Invoke(shapeDriver, arguments.ToArray());
|
||||
}
|
||||
|
||||
private object BindParameter(DisplayContext displayContext, ParameterInfo parameter) {
|
||||
@@ -45,9 +51,29 @@ namespace Orchard.DisplayManagement {
|
||||
if (parameter.Name == "Display")
|
||||
return displayContext.Display;
|
||||
|
||||
return ((dynamic)(displayContext.Value))[parameter.Name];
|
||||
var result = ((dynamic)(displayContext.Value))[parameter.Name];
|
||||
var converter = _converters.GetOrAdd(
|
||||
parameter.ParameterType,
|
||||
CompileConverter);
|
||||
return converter(result);
|
||||
}
|
||||
|
||||
static Func<object, object> CompileConverter(Type targetType) {
|
||||
var valueParameter = Expression.Parameter(typeof (object), "value");
|
||||
|
||||
return Expression.Lambda<Func<object, object>>(
|
||||
Expression.Convert(
|
||||
Expression.Dynamic(
|
||||
Binder.Convert(CSharpBinderFlags.ConvertExplicit, targetType, null),
|
||||
targetType,
|
||||
valueParameter),
|
||||
typeof (object)),
|
||||
valueParameter).Compile();
|
||||
}
|
||||
|
||||
static readonly ConcurrentDictionary<Type, Func<object, object>> _converters =
|
||||
new ConcurrentDictionary<Type, Func<object, object>>();
|
||||
|
||||
static bool IsAcceptableMethod(MethodInfo methodInfo) {
|
||||
if (methodInfo.IsSpecialName)
|
||||
return false;
|
||||
|
@@ -1,3 +0,0 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeProvider : IDependency{}
|
||||
}
|
@@ -35,7 +35,7 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
contextualize();
|
||||
|
||||
_localizer = LocalizationUtilities.Resolve(ViewContext, VirtualPath);
|
||||
_display = DisplayHelperFactory.CreateDisplayHelper(ViewContext, this);
|
||||
_display = DisplayHelperFactory.CreateHelper(ViewContext, this);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -377,22 +377,24 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DataMigrations\FrameworkDataMigration.cs" />
|
||||
<Compile Include="DisplayManagement\Secondary\DefaultDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\DefaultShapeBuilder.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\IShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\IDisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\DefaultDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\DefaultShapeFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IDisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IShape.cs" />
|
||||
<Compile Include="DisplayManagement\IShapeAttributes.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\Shape.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\ShapeAttributes.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\DefaultShapeTableFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\DisplayContext.cs" />
|
||||
<Compile Include="DisplayManagement\DisplayHelper.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\DisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\IShapeBuilder.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\IShapeProvider.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\DisplayContext.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\DisplayHelper.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\DisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\IDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\IShapeFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IShapeDriver.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\IShapeTableFactory.cs" />
|
||||
<Compile Include="DisplayManagement\ShapeHelper.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\ShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\ShapeHelper.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\ShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\ShapeTable.cs" />
|
||||
<Compile Include="Environment\IContextualizable.cs" />
|
||||
<Compile Include="Environment\IHostLocalRestart.cs" />
|
||||
|
Reference in New Issue
Block a user