Small update to shape descriptor

Adding a BindingSource description text
Adding a devtools/inventory/shapetable action to list shapes in the system and where their display is implemented

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-08-31 18:30:12 -07:00
parent e8e03cc98e
commit 59d1100f95
11 changed files with 86 additions and 14 deletions

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Themes;
using Orchard.UI.Admin;
namespace Orchard.DevTools.Controllers {
[Themed, Admin]
public class InventoryController : Controller {
private readonly IShapeTableManager _shapeTableManager;
public InventoryController(IShapeTableManager shapeTableManager) {
_shapeTableManager = shapeTableManager;
}
public ActionResult ShapeTable(string themeName) {
return View("ShapeTable", _shapeTableManager.GetShapeTable(themeName));
}
}
}

View File

@@ -77,6 +77,7 @@
<Compile Include="Controllers\ContentController.cs" />
<Compile Include="Controllers\DatabaseUpdateController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\InventoryController.cs" />
<Compile Include="Controllers\MetadataController.cs" />
<Compile Include="Handlers\DebugLinkHandler.cs" />
<Compile Include="Models\ShowDebugLink.cs" />
@@ -127,6 +128,7 @@
<ItemGroup>
<None Include="Views\Home\FormShapes.cshtml" />
<None Include="Views\Home\UsingShapes.cshtml" />
<None Include="Views\Inventory\ShapeTable.cshtml" />
<None Include="Views\Rounded.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -0,0 +1,12 @@

<div>
@model Orchard.DisplayManagement.Descriptors.ShapeTable;
<ul>
@foreach(var descriptor in Model.Descriptors) {
<li>
@descriptor.Key
<p>@descriptor.Value.BindingSource</p>
</li>
}
</ul>
</div>

View File

@@ -310,6 +310,7 @@
<Content Include="Themes\TheAdmin\Views\User.ascx" />
<Content Include="Themes\TheAdmin\Views\Header.ascx" />
<Content Include="Themes\Web.config" />
<None Include="Themes\TheAdmin\Views\Message.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />

View File

@@ -18,7 +18,8 @@ namespace Orchard.DisplayManagement.Descriptors {
bindingStrategy.Discover(builder);
}
// placeholder - alterations will need to be selective and in a particular order
// GroupBy has been determined to preserve the order of items in original series
_shapeTable = new ShapeTable {
Descriptors = builder.Build()
.GroupBy(alteration => alteration.ShapeType)

View File

@@ -25,6 +25,13 @@ namespace Orchard.DisplayManagement.Descriptors {
public class ShapeDescriptor {
public string ShapeType { get; set; }
/// <summary>
/// The BindingSource is informational text about the source of the Binding delegate. Not used except for
/// troubleshooting.
/// </summary>
public string BindingSource { get; set; }
public Func<DisplayContext, IHtmlString> Binding { get; set; }
}
@@ -89,12 +96,14 @@ namespace Orchard.DisplayManagement.Descriptors {
return this;
}
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
public ShapeDescriptorAlterationBuilder BoundAs(string bindingSource, Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
// schedule the configuration
return Configure(descriptor => {
Func<DisplayContext, IHtmlString> target = null;
descriptor.BindingSource = bindingSource;
// announce the binding, which may be reconfigured before it's used
descriptor.Binding = displayContext => {

View File

@@ -36,7 +36,9 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
builder.Describe
.Named(shapeType)
.From(occurrence.Feature)
.BoundAs(descriptor => CreateDelegate(occurrence, descriptor));
.BoundAs(
occurrence.MethodInfo.DeclaringType.FullName + "::" + occurrence.MethodInfo.Name,
descriptor => CreateDelegate(occurrence, descriptor));
}
}
@@ -45,7 +47,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
ShapeDescriptor descriptor) {
return context => {
var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
// oversimplification for the sake of evolving
return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);
};

View File

@@ -38,7 +38,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });
var availableFeatures = _extensionManager.AvailableFeatures();
var activeFeatures = availableFeatures.Where(fd => _shellDescriptor.Features.Any(sf => sf.Name == fd.Name));
var activeFeatures = availableFeatures.Where(fd => FeatureIsTheme(fd) || FeatureIsEnabled(fd));
var activeExtensions = Once(activeFeatures);
var hits = activeExtensions.SelectMany(extensionDescriptor => {
@@ -50,7 +50,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
var fileNames = ve.DetectTemplateFileNames(pathContext.virtualPath);
return fileNames.Select(fileName => new { fileName, fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName), pathContext });
return fileNames.Select(fileName => new { fileName = Path.GetFileNameWithoutExtension(fileName), fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace('\\','/'), pathContext });
}));
var shapeContexts = fileContexts.SelectMany(fileContext => {
@@ -75,15 +75,24 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
builder.Describe
.From(featureDescriptor)
.Named(iter.shapeContext.harvestShapeHit.ShapeType)
.BoundAs(shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
.BoundAs(
hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
}
}
}
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 IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
}
}

View File

@@ -11,7 +11,6 @@ using Orchard.Localization;
namespace Orchard.DisplayManagement.Implementation {
public class DefaultDisplayManager : IDisplayManager {
private readonly IShapeTableManager _shapeTableManager;
private readonly IShapeTableFactory _shapeTableFactory;
// this need to be Shape instead of IShape - cast to interface throws error on clr types like HtmlString
private static readonly CallSite<Func<CallSite, object, Shape>> _convertAsShapeCallsite = CallSite<Func<CallSite, object, Shape>>.Create(

View File

@@ -36,12 +36,26 @@ namespace Orchard.Environment.Extensions {
public IEnumerable<FeatureDescriptor> AvailableFeatures() {
var featureDescriptors = AvailableExtensions().SelectMany(ext => ext.Features);
var featureDescriptorsOrdered = featureDescriptors.OrderByDependencies((item, dep) =>
item.Dependencies != null &&
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, dep.Name)));
var featureDescriptorsOrdered = featureDescriptors.OrderByDependencies(HasDependency);
return featureDescriptorsOrdered.ToReadOnlyCollection();
}
/// <summary>
/// Returns true if the item has an explicit or implicit dependency on the subject
/// </summary>
/// <param name="item"></param>
/// <param name="subject"></param>
/// <returns></returns>
static bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject) {
// Themes implicitly depend on modules to ensure build and override ordering
if (item.Extension.ExtensionType == "Theme" && subject.Extension.ExtensionType == "Module")
return true;
// Return based on explicit dependencies
return item.Dependencies != null &&
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, subject.Name));
}
private IEnumerable<ExtensionEntry> LoadedModules() {
foreach (var descriptor in AvailableExtensions()) {

View File

@@ -95,7 +95,7 @@ namespace Orchard.Mvc.ViewEngines.Razor {
var fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
foreach (var fileName in fileNames) {
if (fileName.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) {
yield return fileName.Substring(0, fileName.Length - ".cshtml".Length);
yield return fileName;
}
}
}