Adding a ShapePlacementParsingStrategy

Built-in shape table provider to provide alterations based on placement files in modules and themes

--HG--
branch : composition
This commit is contained in:
Louis DeJardin
2010-10-12 11:18:00 -07:00
parent 0ce0dcb69b
commit fd6f482295
3 changed files with 58 additions and 1 deletions

View File

@@ -392,7 +392,7 @@
<Content Include="Shapes\Views\MenuItem.cshtml" />
<Content Include="Shapes\Views\Web.config" />
<Content Include="Dashboard\Views\Helper\Index.cshtml" />
<Content Include="Routable\Views\Parts\Routable.RoutePart.cshtml" />
<None Include="Routable\Views\Parts\RoutableTitle.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
namespace Orchard.DisplayManagement.Descriptors.ShapePlacements {
public class ShapePlacementParsingStrategy : IShapeTableProvider {
private readonly IExtensionManager _extensionManager;
private readonly ShellDescriptor _shellDescriptor;
public ShapePlacementParsingStrategy(
IExtensionManager extensionManager,
ShellDescriptor shellDescriptor) {
_extensionManager = extensionManager;
_shellDescriptor = shellDescriptor;
}
public void Discover(ShapeTableBuilder builder) {
var availableFeatures = _extensionManager.AvailableFeatures();
var activeFeatures = availableFeatures.Where(fd => FeatureIsTheme(fd) || FeatureIsEnabled(fd));
var activeExtensions = Once(activeFeatures);
foreach (var extensionDescriptor in activeExtensions) {
foreach (var featureDescriptor in extensionDescriptor.Features.Where(fd=>fd.Name == fd.Extension.Name)) {
builder.Describe("Parts_RoutableTitle")
.From(new Feature{Descriptor = featureDescriptor})
.Placement(ctx => ctx.ContentType == "WidgetPage", "Content:after");
}
//var featureDescriptors = extensionDescriptor.Where(fd => fd.Name == hit.extensionDescriptor.Name);
//foreach (var featureDescriptor in featureDescriptors) {
}
//builder.Describe("Parts_RoutableTitle")
//.Placement(ctx => ctx.ContentType == "Page", "Content:after");
}
private bool FeatureIsTheme(FeatureDescriptor fd) {
return fd.Extension.ExtensionType == "Theme";
}
private bool FeatureIsEnabled(FeatureDescriptor fd) {
return _shellDescriptor.Features.Any(sf => sf.Name == fd.Name);
}
private static IEnumerable<ExtensionDescriptor> Once(IEnumerable<FeatureDescriptor> featureDescriptors) {
var once = new ConcurrentDictionary<string, object>();
return featureDescriptors.Select(fd => fd.Extension).Where(ed => once.TryAdd(ed.Name, null)).ToList();
}
}
}

View File

@@ -165,6 +165,7 @@
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptor.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeAlteration.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeAlterationBuilder.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapePlacements\ShapePlacementParsingStrategy.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeTable.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeTableBuilder.cs" />
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />