mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 20:13:52 +08:00
Some refactoring in DisplayManagement namespace
Removing unused IShapeTableFactory ShapeTableBuilder has default Feature - components describing shapes from their own module do not need to pass feature in Fixing some tests IShapeDescriptorBindingStrategy becomes IShapeTableProvider --HG-- branch : theming
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
[TestFixture]
|
||||
public class DefaultShapeTableFactoryTests : ContainerTestBase {
|
||||
private IShapeTableFactory _factory;
|
||||
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterType<DefaultShapeTableFactory>().As<IShapeTableFactory>();
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
_factory = container.Resolve<IShapeTableFactory>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FactoryIsResolved() {
|
||||
Assert.That(_factory, Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,52 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
[TestFixture]
|
||||
public class DefaultShapeTableManagerTests {
|
||||
public class DefaultShapeTableManagerTests : ContainerTestBase {
|
||||
protected override void Register(Autofac.ContainerBuilder builder) {
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
|
||||
builder.RegisterType<TestShapeProvider>().As<IShapeTableProvider>()
|
||||
.WithMetadata("Feature", TestFeature());
|
||||
}
|
||||
|
||||
static Feature TestFeature() {
|
||||
return new Feature {
|
||||
Descriptor = new FeatureDescriptor {
|
||||
Name = "Testing",
|
||||
Dependencies = Enumerable.Empty<string>(),
|
||||
Extension = new ExtensionDescriptor {
|
||||
Name = "Testing",
|
||||
ExtensionType = "Module",
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class TestShapeProvider : IShapeTableProvider {
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
builder.Describe("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManagerCanBeResolved() {
|
||||
var manager = _container.Resolve<IShapeTableManager>();
|
||||
Assert.That(manager, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultShapeTableIsReturnedForNullOrEmpty() {
|
||||
var manager = _container.Resolve<IShapeTableManager>();
|
||||
var shapeTable1 = manager.GetShapeTable(null);
|
||||
var shapeTable2 = manager.GetShapeTable(string.Empty);
|
||||
Assert.That(shapeTable1.Descriptors["Hello"], Is.Not.Null);
|
||||
Assert.That(shapeTable2.Descriptors["Hello"], Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using JetBrains.Annotations;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
@@ -15,12 +17,23 @@ using Orchard.Tests.Utility;
|
||||
namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
[TestFixture]
|
||||
public class ShapeAttributeBindingStrategyTests : ContainerTestBase {
|
||||
private FeatureDescriptor _testFeature;
|
||||
private Feature _testFeature;
|
||||
|
||||
protected override void Register(Autofac.ContainerBuilder builder) {
|
||||
protected override void Register([NotNull] Autofac.ContainerBuilder builder) {
|
||||
if (builder == null) {
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
builder.RegisterAutoMocking();
|
||||
_testFeature = new FeatureDescriptor { Name = "Testing", Extension = new ExtensionDescriptor { Name = "Testing" } };
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeDescriptorBindingStrategy>();
|
||||
_testFeature = new Feature {
|
||||
Descriptor = new FeatureDescriptor {
|
||||
Name = "Testing",
|
||||
Extension = new ExtensionDescriptor {
|
||||
Name = "Testing",
|
||||
ExtensionType = "Module",
|
||||
}
|
||||
}
|
||||
};
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterInstance(new TestProvider()).WithMetadata("Feature", _testFeature);
|
||||
builder.RegisterInstance(new RouteCollection());
|
||||
builder.RegisterModule(new ShapeAttributeBindingModule());
|
||||
@@ -45,11 +58,11 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<ShapeAlteration> GetInitializers() {
|
||||
var strategy = _container.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder = new ShapeTableBuilder();
|
||||
static IEnumerable<ShapeAlteration> GetAlterationBuilders(IShapeTableProvider strategy) {
|
||||
IList<ShapeAlterationBuilder> alterationBuilders = new List<ShapeAlterationBuilder>();
|
||||
var builder = new ShapeTableBuilder(alterationBuilders, null);
|
||||
strategy.Discover(builder);
|
||||
return builder.Build();
|
||||
return alterationBuilders.Select(alterationBuilder => alterationBuilder.Build());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -60,10 +73,8 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
|
||||
[Test]
|
||||
public void InitializersHaveExpectedShapeTypeNames() {
|
||||
var strategy = _container.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder = new ShapeTableBuilder();
|
||||
strategy.Discover(builder);
|
||||
var initializers = builder.Build();
|
||||
var strategy = _container.Resolve<IShapeTableProvider>();
|
||||
var initializers = GetAlterationBuilders(strategy);
|
||||
Assert.That(initializers.Any(i => i.ShapeType == "Simple"));
|
||||
Assert.That(initializers.Any(i => i.ShapeType == "Renamed"));
|
||||
Assert.That(initializers.Any(i => i.ShapeType == "RenamedMethod"), Is.False);
|
||||
@@ -71,27 +82,21 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
|
||||
[Test]
|
||||
public void FeatureMetadataIsDetected() {
|
||||
var strategy = _container.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder = new ShapeTableBuilder();
|
||||
strategy.Discover(builder);
|
||||
var initializers = builder.Build();
|
||||
var strategy = _container.Resolve<IShapeTableProvider>();
|
||||
var initializers = GetAlterationBuilders(strategy);
|
||||
Assert.That(initializers.All(i => i.Feature == _testFeature));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LifetimeScopeContainersHaveMetadata() {
|
||||
var strategy = _container.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder = new ShapeTableBuilder();
|
||||
strategy.Discover(builder);
|
||||
var initializers = builder.Build();
|
||||
var strategy = _container.Resolve<IShapeTableProvider>();
|
||||
var initializers = GetAlterationBuilders(strategy);
|
||||
Assert.That(initializers.Any(i => i.ShapeType == "Simple"));
|
||||
|
||||
var childContainer = _container.BeginLifetimeScope();
|
||||
|
||||
var strategy2 = childContainer.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder2 = new ShapeTableBuilder();
|
||||
strategy2.Discover(builder2);
|
||||
var initializers2 = builder2.Build();
|
||||
var strategy2 = childContainer.Resolve<IShapeTableProvider>();
|
||||
var initializers2 = GetAlterationBuilders(strategy2);
|
||||
Assert.That(initializers2.Any(i => i.ShapeType == "Simple"));
|
||||
|
||||
Assert.That(strategy, Is.Not.SameAs(strategy2));
|
||||
@@ -99,7 +104,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
|
||||
[Test]
|
||||
public void BindingProvidedByStrategyInvokesMethod() {
|
||||
var initializers = GetInitializers();
|
||||
var initializers = GetAlterationBuilders(_container.Resolve<IShapeTableProvider>());
|
||||
|
||||
var shapeDescriptor = initializers.Where(i => i.ShapeType == "Simple")
|
||||
.Aggregate(new ShapeDescriptor { ShapeType = "Simple" }, (d, i) => { i.Alter(d); return d; });
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
_testViewEngine = new TestViewEngine();
|
||||
|
||||
builder.Register(ctx => _descriptor);
|
||||
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeDescriptorBindingStrategy>();
|
||||
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>();
|
||||
builder.RegisterInstance(_testViewEngine).As<IShapeTemplateViewEngine>();
|
||||
|
||||
@@ -84,12 +84,14 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
AddEnabledFeature("Alpha");
|
||||
|
||||
_testViewEngine.Add("~/Modules/Alpha/Views/AlphaShape.blah", null);
|
||||
var strategy = _container.Resolve<IShapeDescriptorBindingStrategy>();
|
||||
var builder = new ShapeTableBuilder();
|
||||
strategy.Discover(builder);
|
||||
var alterations = builder.Build();
|
||||
var strategy = _container.Resolve<IShapeTableProvider>();
|
||||
|
||||
Assert.That(alterations.Any(alt => alt.ShapeType == "AlphaShape"));
|
||||
IList<ShapeAlterationBuilder> alterationBuilders = new List<ShapeAlterationBuilder>();
|
||||
var builder = new ShapeTableBuilder(alterationBuilders,null);
|
||||
strategy.Discover(builder);
|
||||
var alterations = alterationBuilders.Select(alterationBuilder=>alterationBuilder.Build());
|
||||
|
||||
Assert.That(alterations.Any(alteration => alteration.ShapeType == "AlphaShape"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
@@ -17,6 +18,8 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
@@ -18,6 +19,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
_container = builder.Build();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new ShapeAttributeBindingModule());
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeDescriptorBindingStrategy>();
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
|
||||
|
||||
@@ -197,7 +197,6 @@
|
||||
<Compile Include="DisplayManagement\DefaultDisplayManagerTests.cs" />
|
||||
<Compile Include="ContainerTestBase.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\BasicShapeTemplateHarvesterTests.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\DefaultShapeTableFactoryTests.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\DefaultShapeTableManagerTests.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeAttributeBindingStrategyTests.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTemplateBindingStrategyTests.cs" />
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Orchard.Tests.UI {
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<PageWorkContext>().As<IWorkContextStateProvider>();
|
||||
//builder.RegisterType<CoreShapes>().As<IShapeDescriptorBindingStrategy>();
|
||||
//builder.RegisterType<CoreShapes>().As<IShapeTableProvider>();
|
||||
builder.RegisterType<NumberIsAlwaysFortyTwo>().As<IShapeFactoryEvents>();
|
||||
|
||||
throw new NotImplementedException("this test fixture needs to move to modules tests now");
|
||||
|
||||
@@ -14,31 +14,30 @@ using Orchard.UI.Zones;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
||||
public Feature Feature { get; set; }
|
||||
|
||||
public class CoreShapes : IShapeTableProvider {
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
// the root page shape named 'Layout' is wrapped with 'Document'
|
||||
// and has an automatic zone creating behavior
|
||||
builder.Describe.Named("Layout").From(Feature.Descriptor)
|
||||
builder.Describe("Layout")
|
||||
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(name => CreateZone(creating, name))))
|
||||
.OnCreated(created => {
|
||||
created.Shape.Head = created.New.DocumentZone();
|
||||
created.Shape.Body = created.New.DocumentZone();
|
||||
created.Shape.Tail = created.New.DocumentZone();
|
||||
created.Shape.Body.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
var page = created.Shape;
|
||||
page.Head = created.New.DocumentZone();
|
||||
page.Body = created.New.DocumentZone();
|
||||
page.Tail = created.New.DocumentZone();
|
||||
page.Content = created.New.Zone();
|
||||
|
||||
created.Shape.Content = created.New.Zone();
|
||||
created.Shape.Content.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
page.Body.Add(created.New.PlaceChildContent(Source: page), "5");
|
||||
page.Content.Add(created.New.PlaceChildContent(Source: page), "5");
|
||||
});
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
builder.Describe.Named("Zone").From(Feature.Descriptor)
|
||||
builder.Describe("Zone")
|
||||
.OnCreating(creating => creating.BaseType = typeof(Zone));
|
||||
|
||||
|
||||
// 'List' shapes start with several empty collections
|
||||
builder.Describe.Named("List").From(Feature.Descriptor)
|
||||
builder.Describe("List")
|
||||
.OnCreated(created => {
|
||||
created.Shape.Tag = "ul";
|
||||
created.Shape.ItemClasses = new List<string>();
|
||||
|
||||
@@ -81,10 +81,10 @@ namespace Orchard.Setup {
|
||||
builder.RegisterType<ConfiguredEnginesCache>().As<IConfiguredEnginesCache>();
|
||||
builder.RegisterType<PageWorkContext>().As<IWorkContextStateProvider>();
|
||||
|
||||
builder.RegisterType<CoreShapes>().As<IShapeDescriptorBindingStrategy>().WithProperty("Feature", Feature).WithMetadata("Feature", Feature);
|
||||
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeDescriptorBindingStrategy>();
|
||||
builder.RegisterType<CoreShapes>().As<IShapeTableProvider>().WithProperty("Feature", Feature).WithMetadata("Feature", Feature);
|
||||
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>();
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeDescriptorBindingStrategy>();
|
||||
builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterModule(new ShapeAttributeBindingModule());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
public class DefaultShapeTableFactory : IShapeTableFactory {
|
||||
public IDictionary<string, ShapeTable> CreateShapeTables() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,35 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Autofac.Features.Metadata;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
public class DefaultShapeTableManager : IShapeTableManager {
|
||||
private readonly IEnumerable<IShapeDescriptorBindingStrategy> _bindingStrategies;
|
||||
|
||||
public DefaultShapeTableManager(IEnumerable<IShapeDescriptorBindingStrategy> bindingStrategies) {
|
||||
public interface IFeatureMetadata {
|
||||
Feature Feature { get; }
|
||||
}
|
||||
|
||||
public class DefaultShapeTableManager : IShapeTableManager {
|
||||
private readonly IEnumerable<Meta<IShapeTableProvider, IFeatureMetadata>> _bindingStrategies;
|
||||
|
||||
public DefaultShapeTableManager(IEnumerable<Meta<IShapeTableProvider, IFeatureMetadata>> bindingStrategies) {
|
||||
_bindingStrategies = bindingStrategies;
|
||||
}
|
||||
|
||||
ConcurrentDictionary<string, ShapeTable> _tables = new ConcurrentDictionary<string, ShapeTable>();
|
||||
readonly ConcurrentDictionary<string, ShapeTable> _tables = new ConcurrentDictionary<string, ShapeTable>();
|
||||
|
||||
public ShapeTable GetShapeTable(string themeName) {
|
||||
return _tables.GetOrAdd(themeName ?? "", x => {
|
||||
var builder = new ShapeTableBuilder();
|
||||
var builderFactory = new ShapeTableBuilderFactory();
|
||||
foreach (var bindingStrategy in _bindingStrategies) {
|
||||
bindingStrategy.Discover(builder);
|
||||
var strategyDefaultFeature = bindingStrategy.Metadata.Feature;
|
||||
var builder = builderFactory.CreateTableBuilder(strategyDefaultFeature);
|
||||
bindingStrategy.Value.Discover(builder);
|
||||
}
|
||||
|
||||
var alterations = builder.Build()
|
||||
var alterations = builderFactory.BuildAlterations()
|
||||
.Where(alteration => IsModuleOrRequestedTheme(alteration, themeName));
|
||||
|
||||
var descriptors = alterations.GroupBy(alteration => alteration.ShapeType)
|
||||
@@ -36,15 +46,36 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static bool IsModuleOrRequestedTheme(ShapeAlteration alteration, string themeName) {
|
||||
if (alteration == null ||
|
||||
if (alteration == null ||
|
||||
alteration.Feature == null ||
|
||||
alteration.Feature.Extension == null) {
|
||||
alteration.Feature.Descriptor == null ||
|
||||
alteration.Feature.Descriptor.Extension == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return alteration.Feature.Extension.ExtensionType == "Module" ||
|
||||
(alteration.Feature.Extension.ExtensionType == "Theme" && alteration.Feature.Name == themeName);
|
||||
var extensionType = alteration.Feature.Descriptor.Extension.ExtensionType;
|
||||
var featureName = alteration.Feature.Descriptor.Name;
|
||||
|
||||
return extensionType == "Module" ||
|
||||
(extensionType == "Theme" && featureName == themeName);
|
||||
}
|
||||
|
||||
class ShapeTableBuilderFactory {
|
||||
readonly IList<ShapeAlterationBuilder> _alterationBuilders = new List<ShapeAlterationBuilder>();
|
||||
|
||||
public ShapeTableBuilder CreateTableBuilder(Feature feature) {
|
||||
return new ShapeTableBuilder(_alterationBuilders, feature);
|
||||
}
|
||||
|
||||
public IEnumerable<ShapeAlteration> BuildAlterations() {
|
||||
return _alterationBuilders.Select(b => b.Build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
|
||||
public interface IShapeTableManager : IDependency {
|
||||
ShapeTable GetShapeTable(string themeName);
|
||||
}
|
||||
|
||||
public interface IShapeTableFactory : IDependency {
|
||||
IDictionary<string, ShapeTable> CreateShapeTables();
|
||||
}
|
||||
|
||||
public interface IShapeDescriptorBindingStrategy : IDependency {
|
||||
public interface IShapeTableProvider : IDependency {
|
||||
void Discover(ShapeTableBuilder builder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
public class ShapeAlteration {
|
||||
private readonly IList<Action<ShapeDescriptor>> _configurations;
|
||||
|
||||
public ShapeAlteration(string shapeType, FeatureDescriptor feature, IList<Action<ShapeDescriptor>> configurations) {
|
||||
public ShapeAlteration(string shapeType, Feature feature, IList<Action<ShapeDescriptor>> configurations) {
|
||||
_configurations = configurations;
|
||||
ShapeType = shapeType;
|
||||
Feature = feature;
|
||||
}
|
||||
|
||||
public string ShapeType { get; private set; }
|
||||
public FeatureDescriptor Feature { get; private set; }
|
||||
public Feature Feature { get; private set; }
|
||||
public void Alter(ShapeDescriptor descriptor) {
|
||||
foreach (var configuration in _configurations) {
|
||||
configuration(descriptor);
|
||||
|
||||
@@ -7,16 +7,16 @@ using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
public class ShapeAlterationBuilder {
|
||||
protected FeatureDescriptor _feature;
|
||||
protected Feature _feature;
|
||||
protected string _shapeType;
|
||||
protected readonly IList<Action<ShapeDescriptor>> _configurations = new List<Action<ShapeDescriptor>>();
|
||||
|
||||
public ShapeAlterationBuilder Named(string shapeType) {
|
||||
public ShapeAlterationBuilder(Feature feature, string shapeType) {
|
||||
_feature = feature;
|
||||
_shapeType = shapeType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShapeAlterationBuilder From(FeatureDescriptor feature) {
|
||||
public ShapeAlterationBuilder From(Feature feature) {
|
||||
_feature = feature;
|
||||
return this;
|
||||
}
|
||||
@@ -60,5 +60,10 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
descriptor.Created = existing.Concat(new[] { action });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public ShapeAlteration Build() {
|
||||
return new ShapeAlteration(_shapeType, _feature, _configurations.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Mvc.Spooling;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
public class ShapeAttributeBindingStrategy : IShapeDescriptorBindingStrategy {
|
||||
public class ShapeAttributeBindingStrategy : IShapeTableProvider {
|
||||
private readonly IEnumerable<ShapeAttributeOccurrence> _shapeAttributeOccurrences;
|
||||
private readonly IComponentContext _componentContext;
|
||||
private readonly RouteCollection _routeCollection;
|
||||
@@ -37,9 +37,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
foreach (var iter in _shapeAttributeOccurrences) {
|
||||
var occurrence = iter;
|
||||
var shapeType = occurrence.ShapeAttribute.ShapeType ?? occurrence.MethodInfo.Name;
|
||||
builder.Describe
|
||||
.Named(shapeType)
|
||||
.From(occurrence.Feature.Descriptor)
|
||||
builder.Describe(shapeType)
|
||||
.From(occurrence.Feature)
|
||||
.BoundAs(
|
||||
occurrence.MethodInfo.DeclaringType.FullName + "::" + occurrence.MethodInfo.Name,
|
||||
descriptor => CreateDelegate(occurrence, descriptor));
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors {
|
||||
public class ShapeTableBuilder {
|
||||
readonly IList<ShapeAlterationBuilderImpl> _descriptorBuilders = new List<ShapeAlterationBuilderImpl>();
|
||||
readonly IList<ShapeAlterationBuilder> _alterationBuilders;
|
||||
readonly Feature _feature;
|
||||
|
||||
public ShapeAlterationBuilder Describe {
|
||||
get {
|
||||
var db = new ShapeAlterationBuilderImpl();
|
||||
_descriptorBuilders.Add(db);
|
||||
return db;
|
||||
}
|
||||
public ShapeTableBuilder(IList<ShapeAlterationBuilder> alterationBuilders, Feature feature) {
|
||||
_alterationBuilders = alterationBuilders;
|
||||
_feature = feature;
|
||||
}
|
||||
|
||||
public IEnumerable<ShapeAlteration> Build() {
|
||||
return _descriptorBuilders.Select(b => b.Build());
|
||||
public ShapeAlterationBuilder Describe(string shapeType) {
|
||||
var alterationBuilder = new ShapeAlterationBuilder(_feature, shapeType);
|
||||
_alterationBuilders.Add(alterationBuilder);
|
||||
return alterationBuilder;
|
||||
}
|
||||
|
||||
class ShapeAlterationBuilderImpl : ShapeAlterationBuilder {
|
||||
public ShapeAlteration Build() {
|
||||
return new ShapeAlteration(_shapeType, _feature, _configurations.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
public class ShapeTemplateBindingStrategy : IShapeDescriptorBindingStrategy {
|
||||
public class ShapeTemplateBindingStrategy : IShapeTableProvider {
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IEnumerable<IShapeTemplateHarvester> _harvesters;
|
||||
@@ -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 = Path.GetFileNameWithoutExtension(fileName), fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace('\\','/'), pathContext });
|
||||
return fileNames.Select(fileName => new { fileName = Path.GetFileNameWithoutExtension(fileName), fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace('\\', '/'), pathContext });
|
||||
}));
|
||||
|
||||
var shapeContexts = fileContexts.SelectMany(fileContext => {
|
||||
@@ -72,11 +72,10 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
var hit = iter;
|
||||
var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Name == hit.extensionDescriptor.Name);
|
||||
foreach (var featureDescriptor in featureDescriptors) {
|
||||
builder.Describe
|
||||
.From(featureDescriptor)
|
||||
.Named(iter.shapeContext.harvestShapeHit.ShapeType)
|
||||
builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
|
||||
.From(new Feature { Descriptor = featureDescriptor })
|
||||
.BoundAs(
|
||||
hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
|
||||
hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
|
||||
shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,6 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DataMigrations\FrameworkDataMigration.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\DefaultShapeTableFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingModule.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeOccurrence.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTemplateStrategy\IShapeTemplateHarvester.cs" />
|
||||
|
||||
Reference in New Issue
Block a user