diff --git a/lib/claysharp/ClaySharp.dll b/lib/claysharp/ClaySharp.dll
deleted file mode 100644
index 51179ddad..000000000
Binary files a/lib/claysharp/ClaySharp.dll and /dev/null differ
diff --git a/lib/claysharp/ClaySharp.pdb b/lib/claysharp/ClaySharp.pdb
deleted file mode 100644
index 991b7fc80..000000000
Binary files a/lib/claysharp/ClaySharp.pdb and /dev/null differ
diff --git a/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj b/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj
index 3e0a67193..1abcf3f7e 100644
--- a/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj
+++ b/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj
@@ -59,9 +59,6 @@
False
..\..\lib\autofac\Autofac.dll
-
- ..\..\lib\claysharp\ClaySharp.dll
-
False
..\..\lib\nhibernate\FluentNHibernate.dll
diff --git a/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj b/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj
index 7048e937b..eb1f4fa23 100644
--- a/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj
+++ b/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj
@@ -62,9 +62,6 @@
..\..\lib\Castle Windsor 2.0\bin\Castle.Core.dll
-
- ..\..\lib\claysharp\ClaySharp.dll
-
False
..\..\lib\nhibernate\FluentNHibernate.dll
diff --git a/src/Orchard.Tests.Modules/Scripting.Dlr/ScriptingTests.cs b/src/Orchard.Tests.Modules/Scripting.Dlr/ScriptingTests.cs
index 7f926a971..dbf09e961 100644
--- a/src/Orchard.Tests.Modules/Scripting.Dlr/ScriptingTests.cs
+++ b/src/Orchard.Tests.Modules/Scripting.Dlr/ScriptingTests.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Autofac;
-using ClaySharp;
using NUnit.Framework;
using Orchard.Scripting.Dlr.Services;
using Path = Bleroy.FluentPath.Path;
@@ -83,22 +82,6 @@ namespace Orchard.Tests.Modules.Scripting.Dlr {
Assert.That(_scriptingManager.ExecuteExpression("f / 4"), Is.EqualTo(8));
}
-
- [Test]
- public void CanDeclareCallbackOnGlobalMethod() {
- _scriptingManager.SetVariable("x", new Clay(new ReturnMethodNameLengthBehavior()));
-
- Assert.That(_scriptingManager.ExecuteExpression("3 + x.foo()"), Is.EqualTo(6));
- }
-
-
- public class ReturnMethodNameLengthBehavior : ClayBehavior {
- public override object InvokeMemberMissing(Func
-
- False
- ..\..\lib\claysharp\ClaySharp.dll
-
False
..\..\lib\nhibernate\FluentNHibernate.dll
@@ -220,6 +216,8 @@
+
+
diff --git a/src/Orchard.Tests/UI/ShapeTests.cs b/src/Orchard.Tests/UI/ShapeTests.cs
index 202f2b59d..3e5ef2e7d 100644
--- a/src/Orchard.Tests/UI/ShapeTests.cs
+++ b/src/Orchard.Tests/UI/ShapeTests.cs
@@ -2,107 +2,98 @@
using System.Collections.Generic;
using System.Linq;
using Autofac;
-using ClaySharp;
using NUnit.Framework;
+using Orchard.Core.Shapes;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
-using Orchard.DisplayManagement.Shapes;
-using Orchard.Environment;
-using Orchard.Mvc;
+using Orchard.Tests.DisplayManagement;
using Orchard.UI.Zones;
namespace Orchard.Tests.UI {
[TestFixture]
public class ShapeTests : ContainerTestBase {
- private WorkContext _workContext;
+ dynamic _layout;
protected override void Register(ContainerBuilder builder) {
- builder.RegisterType().As();
- builder.RegisterType().As();
+ var defaultShapeTable = new ShapeTable {
+ Descriptors = new Dictionary(StringComparer.OrdinalIgnoreCase),
+ Bindings = new Dictionary(StringComparer.OrdinalIgnoreCase)
+ };
+ builder.Register(ctx => defaultShapeTable);
+
+ builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
- //builder.RegisterType().As();
- builder.RegisterType().As();
-
- throw new NotImplementedException("this test fixture needs to move to modules tests now");
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
}
protected override void Resolve(ILifetimeScope container) {
- _workContext = container.Resolve().CreateWorkContextScope().WorkContext;
+ var shapeFactory = _container.Resolve();
+ _layout = new ZoneHolding(() => shapeFactory.Create("Zone"));
}
- [Test, Ignore("implementation pending")]
- public void WorkContextPageIsLayoutShape() {
- var layout = _workContext.Layout;
- ShapeMetadata pageMetadata = layout.Metadata;
- Assert.That(pageMetadata.Type, Is.EqualTo("Layout"));
- Assert.That(layout.Metadata.Type, Is.EqualTo("Layout"));
- }
-
- [Test, Ignore("implementation pending")]
+ [Test]
public void PagePropertiesAreNil() {
- var layout = _workContext.Layout;
- var pageFoo = layout.Foo;
+
+ var pageFoo = _layout.Foo;
Assert.That(pageFoo == null);
}
- [Test, Ignore("implementation pending")]
+ [Test]
public void PageZonesPropertyIsNotNil() {
- var layout = _workContext.Layout;
- var pageZones = layout.Zones;
+ var pageZones = _layout.Zones;
Assert.That(pageZones != null);
Assert.That(pageZones.Foo == null);
}
- [Test, Ignore("implementation pending")]
+ [Test]
public void AddingToZonePropertyMakesItExist() {
- var layout = _workContext.Layout;
- Assert.That(layout.Zones.Foo == null);
+ Assert.That(_layout.Zones.Foo == null);
- var pageZonesFoo = layout.Zones.Foo;
+ var pageZonesFoo = _layout.Zones.Foo;
pageZonesFoo.Add("hello");
- Assert.That(layout.Zones.Foo != null);
- Assert.That(layout.Foo != null);
- Assert.That(layout.Foo.Metadata.Type, Is.EqualTo("Zone"));
+ Assert.That(_layout.Zones.Foo != null);
+ Assert.That(_layout.Foo != null);
+ Assert.That(_layout.Foo.Metadata.Type, Is.EqualTo("Zone"));
}
- [Test, Ignore("implementation pending")]
+ [Test]
public void AddingToZoneIndexedMakesItExist() {
- var layout = _workContext.Layout;
- Assert.That(layout.Zones["Foo"] == null);
+ Assert.That(_layout.Zones["Foo"] == null);
- var pageZonesFoo = layout.Zones["Foo"];
+ var pageZonesFoo = _layout.Zones["Foo"];
pageZonesFoo.Add("hello");
- Assert.That(layout.Zones["Foo"] != null);
- Assert.That(layout["Foo"] != null);
- Assert.That(layout["Foo"].Metadata.Type, Is.EqualTo("Zone"));
+ Assert.That(_layout.Zones["Foo"] != null);
+ Assert.That(_layout["Foo"] != null);
+ Assert.That(_layout["Foo"].Metadata.Type, Is.EqualTo("Zone"));
}
- [Test, Ignore("implementation pending")]
+ [Test]
public void CallingAddOnNilPropertyMakesItBecomeZone() {
- var layout = _workContext.Layout;
- Assert.That(layout.Foo == null);
+ Assert.That(_layout.Foo == null);
- layout.Foo.Add("hello");
+ _layout.Foo.Add("hello");
- Assert.That(layout.Foo != null);
- Assert.That(layout.Foo.Metadata.Type, Is.EqualTo("Zone"));
+ Assert.That(_layout.Foo != null);
+ Assert.That(_layout.Foo.Metadata.Type, Is.EqualTo("Zone"));
}
- [Test, Ignore("implementation pending")]
+ [Test]
public void ZoneContentsAreEnumerable() {
- var layout = _workContext.Layout;
- Assert.That(layout.Foo == null);
+ Assert.That(_layout.Foo == null);
- layout.Foo.Add("hello");
- layout.Foo.Add("world");
+ _layout.Foo.Add("hello");
+ _layout.Foo.Add("world");
var list = new List();
- foreach (var item in layout.Foo) {
+ foreach (var item in _layout.Foo) {
list.Add(item);
}
@@ -111,27 +102,38 @@ namespace Orchard.Tests.UI {
Assert.That(list.Last(), Is.EqualTo("world"));
}
+ [Test]
+ public void ZoneContentsCastBeConvertedToEnunerableOfObject() {
+ Assert.That(_layout.Foo == null);
- class NumberIsAlwaysFortyTwo : ShapeFactoryEvents {
- public override void Creating(ShapeCreatingContext context) {
- context.Behaviors.Add(new Behavior());
- }
+ _layout.Foo.Add("hello");
+ _layout.Foo.Add("world");
- class Behavior : ClayBehavior {
- public override object GetMember(Func proceed, object self, string name) {
- return name == "Number" ? 42 : proceed();
- }
- }
+ IEnumerable list = _layout.Foo;
+
+ Assert.That(list.Count(), Is.EqualTo(2));
+ Assert.That(list.First(), Is.EqualTo("hello"));
+ Assert.That(list.Last(), Is.EqualTo("world"));
+
+ var first = ((IEnumerable)_layout.Foo).FirstOrDefault();
+ Assert.That(first, Is.EqualTo("hello"));
}
- [Test, Ignore("implementation pending")]
- public void NumberIsFortyTwo() {
- var layout = _workContext.Layout;
- Assert.That(layout.Number, Is.EqualTo(42));
- Assert.That(layout.Foo.Number == null);
- layout.Foo.Add("yarg");
- Assert.That(layout.Foo.Number, Is.EqualTo(42));
+ [Test]
+ public void ZoneContentsCastBeConvertedToEnunerableOfDynamics() {
+ Assert.That(_layout.Foo == null);
+
+ _layout.Foo.Add("hello");
+ _layout.Foo.Add("world");
+
+ IEnumerable list = _layout.Foo;
+
+ Assert.That(list.Count(), Is.EqualTo(2));
+ Assert.That(list.First(), Is.EqualTo("hello"));
+ Assert.That(list.Last(), Is.EqualTo("world"));
+
+ var first = ((IEnumerable) _layout.Foo).FirstOrDefault();
+ Assert.That(first, Is.EqualTo("hello"));
}
}
-
}
diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj
index a3579ca58..a4b76040a 100644
--- a/src/Orchard.Web/Core/Orchard.Core.csproj
+++ b/src/Orchard.Web/Core/Orchard.Core.csproj
@@ -46,11 +46,6 @@
AllRules.ruleset
-
- False
- ..\..\..\lib\claysharp\ClaySharp.dll
- True
-
diff --git a/src/Orchard.Web/Core/Shapes/CoreShapes.cs b/src/Orchard.Web/Core/Shapes/CoreShapes.cs
index 6c810015a..20627dc96 100644
--- a/src/Orchard.Web/Core/Shapes/CoreShapes.cs
+++ b/src/Orchard.Web/Core/Shapes/CoreShapes.cs
@@ -48,7 +48,7 @@ namespace Orchard.Core.Shapes {
// and has an automatic zone creating behavior
builder.Describe("Layout")
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
- .OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(() => creating.New.Zone(), null)))
+ .OnCreating(creating => creating.Create = () => new ZoneHolding(() => creating.New.Zone()))
.OnCreated(created => {
var layout = created.Shape;
@@ -68,7 +68,7 @@ namespace Orchard.Core.Shapes {
// They have class="zone zone-{name}"
// and the template can be specialized with "Zone-{Name}" base file name
builder.Describe("Zone")
- .OnCreating(creating => creating.BaseType = typeof(Zone))
+ .OnCreating(creating => creating.Create = () => new Zone())
.OnDisplaying(displaying => {
var zone = displaying.Shape;
string zoneName = zone.ZoneName;
diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj
index 997162bb1..aa7266286 100644
--- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj
+++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj
@@ -21,6 +21,10 @@
4.0
+
+
+
+
true
@@ -41,7 +45,6 @@
4
-
diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/PlacementService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/PlacementService.cs
index e0af18790..ddfaa1c31 100644
--- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/PlacementService.cs
+++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/PlacementService.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
-using ClaySharp.Implementation;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
@@ -215,8 +214,9 @@ namespace Orchard.ContentTypes.Services {
}
private dynamic CreateItemShape(string actualShapeType) {
- var zoneHoldingBehavior = new ZoneHoldingBehavior((Func)(() => _shapeFactory.Create("ContentZone", Arguments.Empty())), _workContextAccessor.GetContext().Layout);
- return _shapeFactory.Create(actualShapeType, Arguments.Empty(), new[] { zoneHoldingBehavior });
+ var zoneHolding = new ZoneHolding(() => _shapeFactory.Create("ContentZone", Arguments.Empty()));
+ zoneHolding.Metadata.Type = actualShapeType;
+ return zoneHolding;
}
private void BindPlacement(BuildShapeContext context, string displayType, string stereotype) {
diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Orchard.DesignerTools.csproj b/src/Orchard.Web/Modules/Orchard.DesignerTools/Orchard.DesignerTools.csproj
index 513a9a638..e48d7db9e 100644
--- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Orchard.DesignerTools.csproj
+++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Orchard.DesignerTools.csproj
@@ -21,6 +21,10 @@
false
+
+
+
+
true
@@ -42,10 +46,6 @@
AllRules.ruleset
-
- ..\..\..\..\lib\claysharp\ClaySharp.dll
- True
-
diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js
index a6431a172..a90572c3e 100644
--- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js
+++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js
@@ -550,7 +550,7 @@ jQuery(function ($) {
var text = shapeNode.type;
// add the hint to the tree node if available
- if (shapeNode.hint != '') {
+ if (shapeNode.hint && shapeNode.hint != '') {
text += ' [' + shapeNode.hint + ']';
}
diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs
index 063294a35..7392d3b82 100644
--- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs
+++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs
@@ -4,7 +4,6 @@ using System.Collections;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
-using ClaySharp;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Shapes;
@@ -195,12 +194,19 @@ namespace Orchard.DesignerTools.Services {
}
private void DumpShape(IShape shape) {
- var members = new Dictionary();
- ((IClayBehaviorProvider) (dynamic) shape).Behavior.GetMembers(() => null, shape, members);
+ var value = shape as Shape;
- foreach (var key in members.Keys.Where(key => !key.StartsWith("_"))) {
+ if (value == null) {
+ return;
+ }
+
+ foreach (DictionaryEntry entry in value.Properties) {
// ignore private members (added dynamically by the shape wrapper)
- Dump(members[key], key);
+ if (entry.Key.ToString().StartsWith("_")) {
+ continue;
+ }
+
+ Dump(entry.Value, entry.Key.ToString());
}
}
diff --git a/src/Orchard.Web/Modules/Orchard.Forms/Orchard.Forms.csproj b/src/Orchard.Web/Modules/Orchard.Forms/Orchard.Forms.csproj
index 9e3c10258..2e96b387d 100644
--- a/src/Orchard.Web/Modules/Orchard.Forms/Orchard.Forms.csproj
+++ b/src/Orchard.Web/Modules/Orchard.Forms/Orchard.Forms.csproj
@@ -46,9 +46,6 @@
AllRules.ruleset
-
- ..\..\..\..\lib\claysharp\ClaySharp.dll
-
..\..\..\..\lib\newtonsoft.json\Newtonsoft.Json.dll
diff --git a/src/Orchard.Web/Modules/Orchard.Forms/Shapes/EditorShapes.cs b/src/Orchard.Web/Modules/Orchard.Forms/Shapes/EditorShapes.cs
index fc9a9c92f..42eebdfd1 100644
--- a/src/Orchard.Web/Modules/Orchard.Forms/Shapes/EditorShapes.cs
+++ b/src/Orchard.Web/Modules/Orchard.Forms/Shapes/EditorShapes.cs
@@ -26,8 +26,8 @@ namespace Orchard.Forms.Shapes {
builder.Describe("Input").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper"));
builder.Describe("SelectList").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper"));
builder.Describe("Textarea").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper"));
- builder.Describe("Form").OnCreating(ctx => ctx.Behaviors.Add(new PropertiesAreItems()));
- builder.Describe("Fieldset").OnCreating(ctx => ctx.Behaviors.Add(new PropertiesAreItems()));
+ builder.Describe("Form").OnCreating(ctx => ctx.Create = () => new PropertiesAreItems());
+ builder.Describe("Fieldset").OnCreating(ctx => ctx.Create = () => new PropertiesAreItems());
}
[Shape]
diff --git a/src/Orchard.Web/Modules/Orchard.Forms/Shapes/PropertyItemsBehavior.cs b/src/Orchard.Web/Modules/Orchard.Forms/Shapes/PropertyItemsBehavior.cs
index 1fa9691c6..4bc96cb48 100644
--- a/src/Orchard.Web/Modules/Orchard.Forms/Shapes/PropertyItemsBehavior.cs
+++ b/src/Orchard.Web/Modules/Orchard.Forms/Shapes/PropertyItemsBehavior.cs
@@ -1,26 +1,26 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using Orchard.DisplayManagement;
-using ClaySharp;
+using Orchard.DisplayManagement.Shapes;
namespace Orchard.Forms.Shapes {
- public class PropertiesAreItems : ClayBehavior {
- public override object SetMember(Func proceed, dynamic self, string name, object value) {
- Patch(self, name, value);
- return proceed();
+ public class PropertiesAreItems : Composite {
+ public override bool TrySetMember(System.Dynamic.SetMemberBinder binder, object value) {
+ Patch(this, binder.Name, value);
+ return base.TrySetMember(binder, value);
}
- public override object SetIndex(Func proceed, dynamic self, IEnumerable keys, object value) {
- if (keys.Count() == 1 && keys.All(k => k is string))
- Patch(self, System.Convert.ToString(keys.Single()), value);
- return proceed();
+ public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value) {
+ if (indexes.Count() == 1 && indexes.All(k => k is string))
+ Patch(this, System.Convert.ToString(indexes.Single()), value);
+ return base.TrySetIndex(binder, indexes, value);
}
- public override object InvokeMember(Func proceed, dynamic self, string name, INamedEnumerable args) {
- if (args.Count() == 1 && args.Named.Count() == 0)
- Patch(self, name, args.Single());
- return proceed();
+ public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result) {
+ var arguments = Arguments.From(args, binder.CallInfo.ArgumentNames);
+ if (args.Count() == 1 && !arguments.Named.Any())
+ Patch(this, binder.Name, args.Single());
+ return base.TryInvokeMember(binder, args, out result);
}
readonly IDictionary _assigned = new Dictionary();
diff --git a/src/Orchard.Web/Modules/Orchard.Rules/Orchard.Rules.csproj b/src/Orchard.Web/Modules/Orchard.Rules/Orchard.Rules.csproj
index 578960cf7..dabcc5317 100644
--- a/src/Orchard.Web/Modules/Orchard.Rules/Orchard.Rules.csproj
+++ b/src/Orchard.Web/Modules/Orchard.Rules/Orchard.Rules.csproj
@@ -21,6 +21,10 @@
false
+
+
+
+
true
@@ -42,7 +46,6 @@
AllRules.ruleset
-
diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj
index 3ca370a28..f0ba33f90 100644
--- a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj
+++ b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj
@@ -50,9 +50,6 @@
False
..\..\..\..\lib\autofac\Autofac.dll
-
- ..\..\..\..\lib\claysharp\ClaySharp.dll
-
diff --git a/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml b/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml
index bcf5586d4..3ef9783e7 100644
--- a/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml
+++ b/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml
@@ -30,7 +30,11 @@
: null;
IHtmlString sectionHeaderMarkup;
- if (firstOfTheSecond != null && firstLevelMenuItem.LinkToFirstChild && (firstOfTheSecond.RouteValues != null || HasText(firstOfTheSecond.Url))) {
+ if (firstOfTheSecond != null
+ && firstLevelMenuItem.LinkToFirstChild
+ && (
+ firstOfTheSecond.RouteValues != null
+ || HasText(firstOfTheSecond.Url))) {
sectionHeaderMarkup = HasText(itemId)
? Html.Link(sectionHeaderText, (string)firstOfTheSecond.Href, new { @class = itemClassName, id = itemId })
: Html.Link(sectionHeaderText, (string)firstOfTheSecond.Href, new { @class = itemClassName });
@@ -72,7 +76,7 @@
-
- False
- ..\..\lib\claysharp\ClaySharp.dll
- True
-
False
..\..\lib\nhibernate\FluentNHibernate.dll
@@ -157,8 +152,6 @@
-
-
@@ -172,12 +165,11 @@
-
-
+
@@ -204,6 +196,8 @@
+
+
diff --git a/src/Orchard/UI/Zones/LayoutWorkContext.cs b/src/Orchard/UI/Zones/LayoutWorkContext.cs
index 82b83530b..c5fb4a644 100644
--- a/src/Orchard/UI/Zones/LayoutWorkContext.cs
+++ b/src/Orchard/UI/Zones/LayoutWorkContext.cs
@@ -1,5 +1,4 @@
using System;
-using ClaySharp.Implementation;
using Orchard.DisplayManagement;
namespace Orchard.UI.Zones {
diff --git a/src/Orchard/UI/Zones/ZoneHoldingBehavior.cs b/src/Orchard/UI/Zones/ZoneHoldingBehavior.cs
index 90ad13eef..0da38e11f 100644
--- a/src/Orchard/UI/Zones/ZoneHoldingBehavior.cs
+++ b/src/Orchard/UI/Zones/ZoneHoldingBehavior.cs
@@ -1,7 +1,7 @@
using System;
using System.Linq;
-using ClaySharp;
-using ClaySharp.Behaviors;
+using System.Linq.Expressions;
+using Orchard.DisplayManagement.Shapes;
namespace Orchard.UI.Zones {
///
@@ -17,102 +17,179 @@ namespace Orchard.UI.Zones {
/// Foo.Alpha :same
///
///
- public class ZoneHoldingBehavior : ClayBehavior {
+ public class ZoneHolding : Shape {
private readonly Func _zoneFactory;
- private readonly dynamic _layoutShape;
- public ZoneHoldingBehavior(Func zoneFactory, dynamic layoutShape) {
+ public ZoneHolding(Func zoneFactory) {
_zoneFactory = zoneFactory;
- _layoutShape = layoutShape;
}
- public override object GetMember(Func proceed, object self, string name) {
- if (name == "Zones") {
- // provide a robot for zone manipulation on parent object
- return ClayActivator.CreateInstance(new IClayBehavior[] {
- new InterfaceProxyBehavior(),
- new ZonesBehavior(_zoneFactory, self, _layoutShape)
- });
+ private Zones _zones;
+ public Zones Zones {
+ get {
+ if (_zones == null) {
+ return _zones = new Zones(_zoneFactory, this);
+ }
+
+ return _zones;
}
+ }
- var result = proceed();
- if (((dynamic)result) == null) {
+ public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result) {
+ var name = binder.Name;
+ if (!base.TryGetMember(binder, out result) || ((dynamic)result) == null) {
// substitute nil results with a robot that turns adds a zone on
// the parent when .Add is invoked
- return ClayActivator.CreateInstance(new IClayBehavior[] {
- new InterfaceProxyBehavior(),
- new NilBehavior(),
- new ZoneOnDemandBehavior(_zoneFactory, self, name)
- });
+ result = new ZoneOnDemand(_zoneFactory, this, name);
+ TrySetMemberImpl(name, result);
}
- return result;
+
+ return true;
}
- public class ZonesBehavior : ClayBehavior {
- private readonly Func _zoneFactory;
- private object _parent;
- private readonly dynamic _layoutShape;
+ }
- public ZonesBehavior(Func zoneFactory, object parent, dynamic layoutShape) {
- _zoneFactory = zoneFactory;
- _parent = parent;
- _layoutShape = layoutShape;
+ ///
+ /// InterfaceProxyBehavior()
+ /// ZonesBehavior(_zoneFactory, self, _layoutShape) => Create ZoneOnDemand if member access
+ ///
+ public class Zones : Composite {
+ private readonly Func _zoneFactory;
+ private readonly object _parent;
+
+ public Zones(Func zoneFactory, object parent) {
+ _zoneFactory = zoneFactory;
+ _parent = parent;
+ }
+
+ public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result) {
+ return TryGetMemberImpl(binder.Name, out result);
+ }
+
+ private bool TryGetMemberImpl(string name, out object result) {
+
+ var parentMember = ((dynamic)_parent)[name];
+ if (parentMember == null) {
+ result = new ZoneOnDemand(_zoneFactory, _parent, name);
+ return true;
}
- public override object GetMember(Func proceed, object self, string name) {
- var parentMember = ((dynamic)_parent)[name];
- if (parentMember == null) {
- return ClayActivator.CreateInstance(new IClayBehavior[] {
- new InterfaceProxyBehavior(),
- new NilBehavior(),
- new ZoneOnDemandBehavior(_zoneFactory, _parent, name)
- });
- }
- return parentMember;
- }
- public override object GetIndex(Func proceed, object self, System.Collections.Generic.IEnumerable keys) {
- if (keys.Count() == 1) {
- var key = System.Convert.ToString(keys.Single());
+ result = parentMember;
+ return true;
+ }
- return GetMember(proceed, null, key);
- }
- return proceed();
+
+ public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result) {
+
+ if (indexes.Count() == 1) {
+ var key = Convert.ToString(indexes.Single());
+
+ return TryGetMemberImpl(key, out result);
+ }
+
+ return base.TryGetIndex(binder, indexes, out result);
+ }
+ }
+
+ ///
+ /// InterfaceProxyBehavior()
+ /// NilBehavior() => return Nil on GetMember and GetIndex in all cases
+ /// ZoneOnDemandBehavior(_zoneFactory, _parent, name) => when a zone (Shape) is
+ /// created, replace itself with the zone so that Layout.ZoneName is no more equal to Nil
+ ///
+ public class ZoneOnDemand : Shape {
+
+ private readonly Func _zoneFactory;
+ private readonly object _parent;
+ private readonly string _potentialZoneName;
+
+ public ZoneOnDemand(Func zoneFactory, object parent, string potentialZoneName) {
+ _zoneFactory = zoneFactory;
+ _parent = parent;
+ _potentialZoneName = potentialZoneName;
+ }
+
+ public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result) {
+ // NilBehavior
+ result = Nil.Instance;
+ return true;
+ }
+
+ public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result) {
+ // NilBehavior
+ result = Nil.Instance;
+ return true;
+ }
+
+ public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result) {
+ var name = binder.Name;
+
+ // NilBehavior
+ if (!args.Any() && name != "ToString") {
+ result = Nil.Instance;
+ return true;
+ }
+
+ return base.TryInvokeMember(binder, args, out result);
+ }
+
+ public override string ToString() {
+ return String.Empty;
+ }
+
+ public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) {
+ result = null;
+ return true;
+ }
+
+ public static bool operator ==(ZoneOnDemand expr, object arg) {
+ // if ZoneOnDemand is compared to null it must return true
+ return arg == null || ReferenceEquals(arg, Nil.Instance);
+ }
+
+ public static bool operator !=(ZoneOnDemand expr, object arg) {
+ // if ZoneOnDemand is compared to null it must return true
+ return arg != null && !ReferenceEquals(arg, Nil.Instance);
+ }
+
+ public override bool Equals(object obj) {
+ if (ReferenceEquals(null, obj)) {
+ return true;
+ }
+
+ if (ReferenceEquals(this, obj)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public override int GetHashCode() {
+ unchecked {
+ int hashCode = (_parent != null ? _parent.GetHashCode() : 0);
+ hashCode = (hashCode * 397) ^ (_potentialZoneName != null ? _potentialZoneName.GetHashCode() : 0);
+ return hashCode;
}
}
- public class ZoneOnDemandBehavior : ClayBehavior {
- private readonly Func _zoneFactory;
- private readonly object _parent;
- private readonly string _potentialZoneName;
-
- public ZoneOnDemandBehavior(Func zoneFactory, object parent, string potentialZoneName) {
- _zoneFactory = zoneFactory;
- _parent = parent;
- _potentialZoneName = potentialZoneName;
- }
-
- public override object InvokeMember(Func proceed, object self, string name, INamedEnumerable args) {
- var argsCount = args.Count();
- if (name == "Add" && (argsCount == 1 || argsCount == 2)) {
- // pszmyd: Ignore null shapes
- if (args.First() == null)
- return _parent;
-
- dynamic parent = _parent;
-
- dynamic zone = _zoneFactory();
- zone.Parent = _parent;
- zone.ZoneName = _potentialZoneName;
- parent[_potentialZoneName] = zone;
-
- if (argsCount == 1)
- return zone.Add(args.Single());
-
- return zone.Add(args.First(), (string)args.Last());
+ public override Shape Add(object item, string position = null) {
+ if (item == null) {
+ return (Shape)_parent;
}
- return proceed();
- }
+
+ dynamic parent = _parent;
+
+ dynamic zone = _zoneFactory();
+ zone.Parent = _parent;
+ zone.ZoneName = _potentialZoneName;
+ parent[_potentialZoneName] = zone;
+
+ if (position == null) {
+ return zone.Add(item);
+ }
+
+ return zone.Add(item, position);
}
}
}
\ No newline at end of file
diff --git a/src/Orchard/WorkContext.cs b/src/Orchard/WorkContext.cs
index 28910debe..3af200397 100644
--- a/src/Orchard/WorkContext.cs
+++ b/src/Orchard/WorkContext.cs
@@ -41,7 +41,7 @@ namespace Orchard {
/// The Layout shape corresponding to the work context
///
public dynamic Layout {
- get { return GetState("Layout"); }
+ get { return GetState("Layout"); }
set { SetState("Layout", value); }
}