mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
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:
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -77,6 +77,7 @@
|
|||||||
<Compile Include="Controllers\ContentController.cs" />
|
<Compile Include="Controllers\ContentController.cs" />
|
||||||
<Compile Include="Controllers\DatabaseUpdateController.cs" />
|
<Compile Include="Controllers\DatabaseUpdateController.cs" />
|
||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
|
<Compile Include="Controllers\InventoryController.cs" />
|
||||||
<Compile Include="Controllers\MetadataController.cs" />
|
<Compile Include="Controllers\MetadataController.cs" />
|
||||||
<Compile Include="Handlers\DebugLinkHandler.cs" />
|
<Compile Include="Handlers\DebugLinkHandler.cs" />
|
||||||
<Compile Include="Models\ShowDebugLink.cs" />
|
<Compile Include="Models\ShowDebugLink.cs" />
|
||||||
@@ -127,6 +128,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Views\Home\FormShapes.cshtml" />
|
<None Include="Views\Home\FormShapes.cshtml" />
|
||||||
<None Include="Views\Home\UsingShapes.cshtml" />
|
<None Include="Views\Home\UsingShapes.cshtml" />
|
||||||
|
<None Include="Views\Inventory\ShapeTable.cshtml" />
|
||||||
<None Include="Views\Rounded.cshtml" />
|
<None Include="Views\Rounded.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
@@ -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>
|
@@ -310,6 +310,7 @@
|
|||||||
<Content Include="Themes\TheAdmin\Views\User.ascx" />
|
<Content Include="Themes\TheAdmin\Views\User.ascx" />
|
||||||
<Content Include="Themes\TheAdmin\Views\Header.ascx" />
|
<Content Include="Themes\TheAdmin\Views\Header.ascx" />
|
||||||
<Content Include="Themes\Web.config" />
|
<Content Include="Themes\Web.config" />
|
||||||
|
<None Include="Themes\TheAdmin\Views\Message.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
@@ -18,7 +18,8 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
bindingStrategy.Discover(builder);
|
bindingStrategy.Discover(builder);
|
||||||
}
|
}
|
||||||
// placeholder - alterations will need to be selective and in a particular order
|
// 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 {
|
_shapeTable = new ShapeTable {
|
||||||
Descriptors = builder.Build()
|
Descriptors = builder.Build()
|
||||||
.GroupBy(alteration => alteration.ShapeType)
|
.GroupBy(alteration => alteration.ShapeType)
|
||||||
|
@@ -25,6 +25,13 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
|
|
||||||
public class ShapeDescriptor {
|
public class ShapeDescriptor {
|
||||||
public string ShapeType { get; set; }
|
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; }
|
public Func<DisplayContext, IHtmlString> Binding { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,12 +96,14 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
return this;
|
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
|
// schedule the configuration
|
||||||
return Configure(descriptor => {
|
return Configure(descriptor => {
|
||||||
|
|
||||||
Func<DisplayContext, IHtmlString> target = null;
|
Func<DisplayContext, IHtmlString> target = null;
|
||||||
|
|
||||||
|
descriptor.BindingSource = bindingSource;
|
||||||
|
|
||||||
// announce the binding, which may be reconfigured before it's used
|
// announce the binding, which may be reconfigured before it's used
|
||||||
descriptor.Binding = displayContext => {
|
descriptor.Binding = displayContext => {
|
||||||
|
|
||||||
|
@@ -36,7 +36,9 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
|||||||
builder.Describe
|
builder.Describe
|
||||||
.Named(shapeType)
|
.Named(shapeType)
|
||||||
.From(occurrence.Feature)
|
.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) {
|
ShapeDescriptor descriptor) {
|
||||||
return context => {
|
return context => {
|
||||||
var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
|
var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
|
||||||
|
|
||||||
// oversimplification for the sake of evolving
|
// oversimplification for the sake of evolving
|
||||||
return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);
|
return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);
|
||||||
};
|
};
|
||||||
|
@@ -38,7 +38,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
|||||||
var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });
|
var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });
|
||||||
|
|
||||||
var availableFeatures = _extensionManager.AvailableFeatures();
|
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 activeExtensions = Once(activeFeatures);
|
||||||
|
|
||||||
var hits = activeExtensions.SelectMany(extensionDescriptor => {
|
var hits = activeExtensions.SelectMany(extensionDescriptor => {
|
||||||
@@ -50,7 +50,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
|||||||
|
|
||||||
var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
|
var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
|
||||||
var fileNames = ve.DetectTemplateFileNames(pathContext.virtualPath);
|
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 => {
|
var shapeContexts = fileContexts.SelectMany(fileContext => {
|
||||||
@@ -75,15 +75,24 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
|||||||
builder.Describe
|
builder.Describe
|
||||||
.From(featureDescriptor)
|
.From(featureDescriptor)
|
||||||
.Named(iter.shapeContext.harvestShapeHit.ShapeType)
|
.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) {
|
private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
|
||||||
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
|
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
|
||||||
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
||||||
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,6 @@ using Orchard.Localization;
|
|||||||
namespace Orchard.DisplayManagement.Implementation {
|
namespace Orchard.DisplayManagement.Implementation {
|
||||||
public class DefaultDisplayManager : IDisplayManager {
|
public class DefaultDisplayManager : IDisplayManager {
|
||||||
private readonly IShapeTableManager _shapeTableManager;
|
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
|
// 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(
|
private static readonly CallSite<Func<CallSite, object, Shape>> _convertAsShapeCallsite = CallSite<Func<CallSite, object, Shape>>.Create(
|
||||||
|
@@ -36,12 +36,26 @@ namespace Orchard.Environment.Extensions {
|
|||||||
|
|
||||||
public IEnumerable<FeatureDescriptor> AvailableFeatures() {
|
public IEnumerable<FeatureDescriptor> AvailableFeatures() {
|
||||||
var featureDescriptors = AvailableExtensions().SelectMany(ext => ext.Features);
|
var featureDescriptors = AvailableExtensions().SelectMany(ext => ext.Features);
|
||||||
var featureDescriptorsOrdered = featureDescriptors.OrderByDependencies((item, dep) =>
|
var featureDescriptorsOrdered = featureDescriptors.OrderByDependencies(HasDependency);
|
||||||
item.Dependencies != null &&
|
|
||||||
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, dep.Name)));
|
|
||||||
return featureDescriptorsOrdered.ToReadOnlyCollection();
|
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() {
|
private IEnumerable<ExtensionEntry> LoadedModules() {
|
||||||
foreach (var descriptor in AvailableExtensions()) {
|
foreach (var descriptor in AvailableExtensions()) {
|
||||||
|
@@ -95,7 +95,7 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
|||||||
var fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
|
var fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName);
|
||||||
foreach (var fileName in fileNames) {
|
foreach (var fileName in fileNames) {
|
||||||
if (fileName.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) {
|
if (fileName.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) {
|
||||||
yield return fileName.Substring(0, fileName.Length - ".cshtml".Length);
|
yield return fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user