--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-22 21:39:13 -08:00
9 changed files with 42 additions and 12 deletions

View File

@@ -37,6 +37,7 @@
Definition: @descriptor.BindingSource <br />
Display Type: @(Model.Metadata.DisplayType ?? "n/a")<br />
Position: @(Model.Metadata.Position ?? "n/a") <br />
Placement Source: @(Model.Metadata.PlacementSource ?? "n/a") <br />
</div>
<div class="alternates">

View File

@@ -112,10 +112,19 @@ namespace Orchard.ContentManagement {
Differentiator = differentiator,
Path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo
};
var location = descriptor.Placement(placementContext);
return location ?? defaultLocation;
if (location != null) {
return new PlacementInfo {
Location = location,
Source = placementContext.Source
};
}
}
return defaultLocation;
return new PlacementInfo {
Location = defaultLocation,
Source = String.Empty
};
};
}
}

View File

@@ -25,8 +25,8 @@ namespace Orchard.ContentManagement.Drivers {
}
private void ApplyImplementation(BuildShapeContext context, string displayType) {
var location = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);
if (string.IsNullOrEmpty(location) || location == "-")
var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);
if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
return;
dynamic parentShape = context.Shape;
@@ -34,14 +34,15 @@ namespace Orchard.ContentManagement.Drivers {
ShapeMetadata newShapeMetadata = newShape.Metadata;
newShapeMetadata.Prefix = _prefix;
newShapeMetadata.DisplayType = displayType;
newShapeMetadata.PlacementSource = placement.Source;
var delimiterIndex = location.IndexOf(':');
var delimiterIndex = placement.Location.IndexOf(':');
if (delimiterIndex < 0) {
parentShape.Zones[location].Add(newShape);
parentShape.Zones[placement.Location].Add(newShape);
}
else {
var zoneName = location.Substring(0, delimiterIndex);
var position = location.Substring(delimiterIndex + 1);
var zoneName = placement.Location.Substring(0, delimiterIndex);
var position = placement.Location.Substring(delimiterIndex + 1);
parentShape.Zones[zoneName].Add(newShape, position);
}
}

View File

@@ -1,5 +1,7 @@
using System;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy;
namespace Orchard.ContentManagement.Handlers {
public class BuildShapeContext {
@@ -7,13 +9,13 @@ namespace Orchard.ContentManagement.Handlers {
Shape = shape;
ContentItem = content.ContentItem;
New = shapeFactory;
FindPlacement = (partType, differentiator, defaultLocation) => defaultLocation;
FindPlacement = (partType, differentiator, defaultLocation) => new PlacementInfo {Location = defaultLocation, Source = String.Empty};
}
public dynamic Shape { get; private set; }
public ContentItem ContentItem { get; private set; }
public dynamic New { get; private set; }
public Func<string, string, string, string> FindPlacement { get; set; }
public Func<string, string, string, PlacementInfo> FindPlacement { get; set; }
}
}

View File

@@ -0,0 +1,6 @@
namespace Orchard.DisplayManagement.Descriptors {
public class PlacementInfo {
public string Location { get; set; }
public string Source { get; set; }
}
}

View File

@@ -112,5 +112,6 @@ namespace Orchard.DisplayManagement.Descriptors {
public string DisplayType { get; set; }
public string Differentiator { get; set; }
public string Path { get; set; }
public string Source { get; set; }
}
}

View File

@@ -65,12 +65,20 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
}
if (matches.Any()) {
predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate);
predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate);
}
builder.Describe(shapeType)
.From(feature)
.Placement(predicate, shapeLocation.Location);
.Placement(ctx => {
var hit = predicate(ctx);
// generate 'debugging' information to trace which file originated the actual location
if (hit) {
var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info";
ctx.Source = virtualPath;
}
return hit;
}, shapeLocation.Location);
}
}

View File

@@ -16,6 +16,7 @@ namespace Orchard.DisplayManagement.Shapes {
public string Type { get; set; }
public string DisplayType { get; set; }
public string Position { get; set; }
public string PlacementSource { get; set; }
public string Prefix { get; set; }
public IList<string> Wrappers { get; set; }
public IList<string> Alternates { get; set; }

View File

@@ -158,6 +158,7 @@
<Compile Include="ContentManagement\Handlers\BuildShapeContext.cs" />
<Compile Include="ContentManagement\IContentBehavior.cs" />
<Compile Include="ContentManagement\Utilities\ComputedField.cs" />
<Compile Include="DisplayManagement\Descriptors\PlacementInfo.cs" />
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StylesheetBindingStrategy.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptor.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeAlteration.cs" />