From a8ebbd7af9f6d1f460b7c21e088f636f611dcf13 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 9 Feb 2011 15:01:03 -0800 Subject: [PATCH] Adding predicate in placement files Can use * at the end of the string Path="/" matches the homepage --HG-- branch : dev extra : transplant_source : %FA%B8%DB%0D%DDI%9DbP%BC%D8%F6%B31j%24%BB%E6%AD%FE --- src/Orchard/ContentManagement/DefaultContentDisplay.cs | 3 +++ .../DisplayManagement/Descriptors/ShapeAlterationBuilder.cs | 1 + .../ShapePlacementStrategy/ShapePlacementParsingStrategy.cs | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/Orchard/ContentManagement/DefaultContentDisplay.cs b/src/Orchard/ContentManagement/DefaultContentDisplay.cs index cb03ce034..2f59d16c5 100644 --- a/src/Orchard/ContentManagement/DefaultContentDisplay.cs +++ b/src/Orchard/ContentManagement/DefaultContentDisplay.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Web; using System.Web.Routing; using ClaySharp.Implementation; using Orchard.ContentManagement.Handlers; @@ -100,6 +101,7 @@ namespace Orchard.ContentManagement { //var theme = workContext.CurrentTheme; var theme = _themeService.Value.GetRequestTheme(_requestContext); var shapeTable = _shapeTableManager.GetShapeTable(theme.Id); + var request = _requestContext.HttpContext.Request; ShapeDescriptor descriptor; if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) { @@ -107,6 +109,7 @@ namespace Orchard.ContentManagement { ContentType = context.ContentItem.ContentType, DisplayType = displayType, Differentiator = differentiator, + Path = request.Path.Substring((request.ApplicationPath ?? "").Length) }; var location = descriptor.Placement(placementContext); return location ?? defaultLocation; diff --git a/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs b/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs index 5bb361e0f..f5799ac8d 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs @@ -111,5 +111,6 @@ namespace Orchard.DisplayManagement.Descriptors { public string ContentType { get; set; } public string DisplayType { get; set; } public string Differentiator { get; set; } + public string Path { get; set; } } } diff --git a/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs b/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs index b7761a785..3275b32ae 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs @@ -98,6 +98,12 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy { return ctx => (ctx.DisplayType ?? "").StartsWith(prefix) && predicate(ctx); } return ctx => (ctx.DisplayType == expression) && predicate(ctx); + case "Path": + if (expression.EndsWith("*")) { + var prefix = expression.Substring(0, expression.Length - 1); + return ctx => (ctx.Path ?? "").StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && predicate(ctx); + } + return ctx => (ctx.Path.Equals(expression, StringComparison.OrdinalIgnoreCase)) && predicate(ctx); } return predicate; }