mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding different type of zone shapes for different purposes
--HG-- branch : theming
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Orchard.Core.Contents {
|
||||
|
||||
public void Creating(ShapeCreatingContext creating) {
|
||||
if (creating.ShapeType.StartsWith("Items_Content"))
|
||||
creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory));
|
||||
creating.Behaviors.Add(new ZoneHoldingBehavior(name => creating.New.ContentZone()));
|
||||
}
|
||||
|
||||
public void Created(ShapeCreatedContext created) {
|
||||
|
||||
@@ -406,6 +406,8 @@
|
||||
<None Include="Contents\Views\Items\Content.SummaryAdmin.cshtml" />
|
||||
<None Include="Contents\Views\Item\Display.cshtml" />
|
||||
<None Include="HomePage\Views\HomePage.cshtml" />
|
||||
<None Include="Shapes\Views\ContentZone.cshtml" />
|
||||
<None Include="Shapes\Views\DocumentZone.cshtml" />
|
||||
<None Include="Shapes\Views\Document.cshtml" />
|
||||
<None Include="Shapes\Views\User.cshtml" />
|
||||
<None Include="Shapes\Views\Header.cshtml" />
|
||||
|
||||
@@ -21,10 +21,15 @@ namespace Orchard.Core.Shapes {
|
||||
// and has an automatic zone creating behavior
|
||||
builder.Describe.Named("Layout").From(Feature.Descriptor)
|
||||
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory)))
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(name => creating.New.Zone())))
|
||||
.OnCreated(created => {
|
||||
created.Shape.Zones.Content.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
created.Shape.Zones.Body.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
created.Shape.Head = created.New.DocumentZone();
|
||||
created.Shape.Body = created.New.DocumentZone();
|
||||
created.Shape.Tail = created.New.DocumentZone();
|
||||
created.Shape.Body.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
|
||||
created.Shape.Content = created.New.Zone();
|
||||
created.Shape.Content.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
});
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
|
||||
1
src/Orchard.Web/Core/Shapes/Views/ContentZone.cshtml
Normal file
1
src/Orchard.Web/Core/Shapes/Views/ContentZone.cshtml
Normal file
@@ -0,0 +1 @@
|
||||
@foreach (var item in Model) {@Display(item)}
|
||||
@@ -17,5 +17,6 @@
|
||||
</head>
|
||||
<body>
|
||||
@Display(Model.Body)
|
||||
@Display(Model.Tail)
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
1
src/Orchard.Web/Core/Shapes/Views/DocumentZone.cshtml
Normal file
1
src/Orchard.Web/Core/Shapes/Views/DocumentZone.cshtml
Normal file
@@ -0,0 +1 @@
|
||||
@foreach (var item in Model) {@Display(item)}
|
||||
@@ -3,10 +3,17 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class Shape : IShape, IEnumerable {
|
||||
public virtual ShapeMetadata Metadata { get; set; }
|
||||
|
||||
private readonly IList<object> _items = new List<object>();
|
||||
private readonly IList<string> _classes = new List<string>();
|
||||
private readonly IDictionary<string, string> _attributes = new Dictionary<string, string>();
|
||||
|
||||
public virtual ShapeMetadata Metadata { get; set; }
|
||||
|
||||
public virtual string Id { get; set; }
|
||||
public virtual IList<string> Classes { get { return _classes; } }
|
||||
public virtual IDictionary<string, string> Attributes { get { return _attributes; } }
|
||||
public virtual IEnumerable<dynamic> Items { get { return _items; } }
|
||||
|
||||
public virtual Shape Add(object item) {
|
||||
_items.Add(item);
|
||||
@@ -32,9 +39,7 @@ namespace Orchard.DisplayManagement.Shapes {
|
||||
public virtual IEnumerator GetEnumerator() {
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<dynamic> Items {
|
||||
get { return _items; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace Orchard.UI.Zones {
|
||||
///
|
||||
/// </summary>
|
||||
public class ZoneHoldingBehavior : ClayBehavior {
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly Func<string, dynamic> _zoneFactory;
|
||||
|
||||
public ZoneHoldingBehavior(IShapeFactory shapeFactory) {
|
||||
_shapeFactory = shapeFactory;
|
||||
public ZoneHoldingBehavior(Func<string, dynamic> zoneFactory) {
|
||||
_zoneFactory = zoneFactory;
|
||||
}
|
||||
|
||||
public override object GetMember(Func<object> proceed, object self, string name) {
|
||||
@@ -31,30 +31,30 @@ namespace Orchard.UI.Zones {
|
||||
// provide a robot for zone manipulation on parent object
|
||||
return ClayActivator.CreateInstance(new IClayBehavior[] {
|
||||
new InterfaceProxyBehavior(),
|
||||
new ZonesBehavior(_shapeFactory, self)
|
||||
new ZonesBehavior(_zoneFactory, self)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var result = proceed();
|
||||
if (((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(_shapeFactory, self, name)
|
||||
new ZoneOnDemandBehavior(_zoneFactory, self, name)
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public class ZonesBehavior : ClayBehavior {
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly Func<string, dynamic> _zoneFactory;
|
||||
private readonly object _parent;
|
||||
|
||||
public ZonesBehavior(IShapeFactory shapeFactory, object parent) {
|
||||
_shapeFactory = shapeFactory;
|
||||
public ZonesBehavior(Func<string, dynamic> zoneFactory, object parent) {
|
||||
_zoneFactory = zoneFactory;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Orchard.UI.Zones {
|
||||
return ClayActivator.CreateInstance(new IClayBehavior[] {
|
||||
new InterfaceProxyBehavior(),
|
||||
new NilBehavior(),
|
||||
new ZoneOnDemandBehavior(_shapeFactory, _parent, name)
|
||||
new ZoneOnDemandBehavior(_zoneFactory, _parent, name)
|
||||
});
|
||||
}
|
||||
return parentMember;
|
||||
@@ -78,12 +78,12 @@ namespace Orchard.UI.Zones {
|
||||
}
|
||||
|
||||
public class ZoneOnDemandBehavior : ClayBehavior {
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly Func<string, dynamic> _zoneFactory;
|
||||
private readonly object _parent;
|
||||
private readonly string _potentialZoneName;
|
||||
|
||||
public ZoneOnDemandBehavior(IShapeFactory shapeFactory, object parent, string potentialZoneName) {
|
||||
_shapeFactory = shapeFactory;
|
||||
public ZoneOnDemandBehavior(Func<string, dynamic> zoneFactory, object parent, string potentialZoneName) {
|
||||
_zoneFactory = zoneFactory;
|
||||
_parent = parent;
|
||||
_potentialZoneName = potentialZoneName;
|
||||
}
|
||||
@@ -93,14 +93,14 @@ namespace Orchard.UI.Zones {
|
||||
if (name == "Add" && (argsCount == 1 || argsCount == 2)) {
|
||||
dynamic parent = _parent;
|
||||
|
||||
dynamic zone = _shapeFactory.Create("Zone", Arguments.Empty());
|
||||
dynamic zone = _zoneFactory(_potentialZoneName);
|
||||
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());
|
||||
}
|
||||
return proceed();
|
||||
|
||||
Reference in New Issue
Block a user