--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-25 13:36:25 -08:00
7 changed files with 90 additions and 34 deletions

View File

@@ -162,7 +162,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
var hello = manager.GetShapeTable(null).Descriptors["Hello"];
hello.DefaultPlacement = "Header:5";
var result = hello.Placement(null);
Assert.That(result, Is.EqualTo("Header:5"));
Assert.That(result.Location, Is.EqualTo("Header:5"));
}
[Test]
@@ -170,8 +170,8 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
_container.Resolve<TestShapeProvider>().Discover =
builder => builder.Describe("Hello").From(TestFeature())
.Placement(ctx => ctx.DisplayType == "Detail" ? "Main" : null)
.Placement(ctx => ctx.DisplayType == "Summary" ? "" : null);
.Placement(ctx => ctx.DisplayType == "Detail" ? new PlacementInfo { Location = "Main" } : null)
.Placement(ctx => ctx.DisplayType == "Summary" ? new PlacementInfo { Location = "" } : null);
var manager = _container.Resolve<IShapeTableManager>();
var hello = manager.GetShapeTable(null).Descriptors["Hello"];
@@ -183,12 +183,12 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
var result5 = hello.Placement(new ShapePlacementContext { DisplayType = "Summary" });
var result6 = hello.Placement(new ShapePlacementContext { DisplayType = "Tile" });
Assert.That(result1, Is.EqualTo("Main"));
Assert.That(result2, Is.EqualTo(""));
Assert.That(result3, Is.Null);
Assert.That(result4, Is.EqualTo("Main"));
Assert.That(result5, Is.EqualTo(""));
Assert.That(result6, Is.EqualTo("Header:5"));
Assert.That(result1.Location, Is.EqualTo("Main"));
Assert.That(result2.Location, Is.EqualTo(""));
Assert.That(result3.Location, Is.Null);
Assert.That(result4.Location, Is.EqualTo("Main"));
Assert.That(result5.Location, Is.EqualTo(""));
Assert.That(result6.Location, Is.EqualTo("Header:5"));
}
[Test]
@@ -196,8 +196,8 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
_container.Resolve<TestShapeProvider>().Discover =
builder => builder.Describe("Hello").From(TestFeature())
.Placement(ctx => ctx.DisplayType == "Detail", "Main")
.Placement(ctx => ctx.DisplayType == "Summary", "");
.Placement(ctx => ctx.DisplayType == "Detail", new PlacementInfo { Location = "Main" })
.Placement(ctx => ctx.DisplayType == "Summary", new PlacementInfo { Location = "" });
var manager = _container.Resolve<IShapeTableManager>();
var hello = manager.GetShapeTable(null).Descriptors["Hello"];
@@ -208,13 +208,13 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
var result4 = hello.Placement(new ShapePlacementContext { DisplayType = "Detail" });
var result5 = hello.Placement(new ShapePlacementContext { DisplayType = "Summary" });
var result6 = hello.Placement(new ShapePlacementContext { DisplayType = "Tile" });
Assert.That(result1, Is.EqualTo("Main"));
Assert.That(result2, Is.EqualTo(""));
Assert.That(result3, Is.Null);
Assert.That(result4, Is.EqualTo("Main"));
Assert.That(result5, Is.EqualTo(""));
Assert.That(result6, Is.EqualTo("Header:5"));
Assert.That(result1.Location, Is.EqualTo("Main"));
Assert.That(result2.Location, Is.EqualTo(""));
Assert.That(result3.Location, Is.Null);
Assert.That(result4.Location, Is.EqualTo("Main"));
Assert.That(result5.Location, Is.EqualTo(""));
Assert.That(result6.Location, Is.EqualTo("Header:5"));
}
[Test]
@@ -242,17 +242,17 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
_container.Resolve<TestShapeProvider>().Discover =
builder => builder.Describe("Hello").From(TestFeature())
.Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair<string, string>("Path", path)), "Match");
.Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair<string, string>("Path", path)), new PlacementInfo { Location = "Match" });
var manager = _container.Resolve<IShapeTableManager>();
var hello = manager.GetShapeTable(null).Descriptors["Hello"];
var result = hello.Placement(new ShapePlacementContext {Path = context});
if (match) {
Assert.That(result, Is.EqualTo("Match"), String.Format("{0}|{1}", path, context));
Assert.That(result.Location, Is.EqualTo("Match"), String.Format("{0}|{1}", path, context));
}
else {
Assert.That(result, Is.Null, String.Format("{0}|{1}", path, context));
Assert.That(result.Location, Is.Null, String.Format("{0}|{1}", path, context));
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using ClaySharp.Implementation;
@@ -113,14 +114,13 @@ namespace Orchard.ContentManagement {
Path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo
};
var location = descriptor.Placement(placementContext);
if (location != null) {
return new PlacementInfo {
Location = location,
Source = placementContext.Source
};
var placement = descriptor.Placement(placementContext);
if(placement != null) {
placement.Source = placementContext.Source;
return placement;
}
}
return new PlacementInfo {
Location = defaultLocation,
Source = String.Empty

View File

@@ -35,6 +35,21 @@ namespace Orchard.ContentManagement.Drivers {
newShapeMetadata.Prefix = _prefix;
newShapeMetadata.DisplayType = displayType;
newShapeMetadata.PlacementSource = placement.Source;
// if a specific shape is provided, remove all previous alternates and wrappers
if (!String.IsNullOrEmpty(placement.ShapeType)) {
newShapeMetadata.Type = placement.ShapeType;
newShapeMetadata.Alternates.Clear();
newShapeMetadata.Wrappers.Clear();
}
foreach (var alternate in placement.Alternates) {
newShapeMetadata.Alternates.Add(alternate);
}
foreach (var wrapper in placement.Wrappers) {
newShapeMetadata.Wrappers.Add(wrapper);
}
var delimiterIndex = placement.Location.IndexOf(':');
if (delimiterIndex < 0) {

View File

@@ -1,6 +1,18 @@
namespace Orchard.DisplayManagement.Descriptors {
using System.Collections.Generic;
using System.Linq;
namespace Orchard.DisplayManagement.Descriptors {
public class PlacementInfo {
public PlacementInfo() {
Alternates = Enumerable.Empty<string>();
Wrappers = Enumerable.Empty<string>();
}
public string Location { get; set; }
public string Source { get; set; }
public string ShapeType { get; set; }
public IEnumerable<string> Alternates { get; set; }
public IEnumerable<string> Wrappers { get; set; }
}
}

View File

@@ -88,14 +88,14 @@ namespace Orchard.DisplayManagement.Descriptors {
});
}
public ShapeAlterationBuilder Placement(Func<ShapePlacementContext, string> action) {
public ShapeAlterationBuilder Placement(Func<ShapePlacementContext, PlacementInfo> action) {
return Configure(descriptor => {
var next = descriptor.Placement;
descriptor.Placement = ctx => action(ctx) ?? next(ctx);
});
}
public ShapeAlterationBuilder Placement(Func<ShapePlacementContext, bool> predicate, string location) {
public ShapeAlterationBuilder Placement(Func<ShapePlacementContext, bool> predicate, PlacementInfo location) {
return Configure(descriptor => {
var next = descriptor.Placement;
descriptor.Placement = ctx => predicate(ctx) ? location : next(ctx);

View File

@@ -13,7 +13,7 @@ namespace Orchard.DisplayManagement.Descriptors {
Displayed = Enumerable.Empty<Action<ShapeDisplayedContext>>();
Wrappers = new List<string>();
Bindings = new Dictionary<string, ShapeBinding>();
Placement = ctx => DefaultPlacement;
Placement = ctx => new PlacementInfo {Location = DefaultPlacement};
}
public string ShapeType { get; set; }
@@ -43,7 +43,7 @@ namespace Orchard.DisplayManagement.Descriptors {
public IEnumerable<Action<ShapeDisplayingContext>> Displaying { get; set; }
public IEnumerable<Action<ShapeDisplayedContext>> Displayed { get; set; }
public Func<ShapePlacementContext, string> Placement { get; set; }
public Func<ShapePlacementContext, PlacementInfo> Placement { get; set; }
public string DefaultPlacement { get; set; }
public IList<string> Wrappers { get; set; }

View File

@@ -68,6 +68,35 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate);
}
var placement = new PlacementInfo();
var segments = shapeLocation.Location.Split(';').Select(s => s.Trim());
foreach (var segment in segments) {
if (!segment.Contains('=')) {
placement.Location = segment;
}
else {
var index = segment.IndexOf('=');
var property = segment.Substring(0, index).ToLower();
var value = segment.Substring(index + 1);
switch (property) {
case "shape":
placement.ShapeType = value;
break;
case "alternate":
placement.Alternates = new[] {value};
break;
case "wrapper":
placement.Wrappers = new[] {value};
break;
default:
// ignore unknown properties
// Logger.Warning("Unknown property name [{0}] in {1}", property, placement.Source);
break;
}
}
}
builder.Describe(shapeType)
.From(feature)
.Placement(ctx => {
@@ -78,7 +107,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
ctx.Source = virtualPath;
}
return hit;
}, shapeLocation.Location);
}, placement);
}
}