Refactoring how default page classes are injected

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-28 12:56:50 -08:00
parent ffc7b4744f
commit be65b3a7eb
19 changed files with 52 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ using Orchard.Security;
using Orchard.Tests.Modules;
using Orchard.Tests.Stubs;
using Orchard.UI.Notify;
using Orchard.UI.PageClass;
namespace Orchard.Core.Tests.Body {
[TestFixture]
@@ -46,6 +47,8 @@ namespace Orchard.Core.Tests.Body {
builder.RegisterType<BodyPartHandler>().As<IContentHandler>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
}
[Test]

View File

@@ -39,6 +39,7 @@ using Orchard.Tests.Modules;
using System.Web.Mvc;
using Orchard.Tests.Stubs;
using Orchard.Themes;
using Orchard.UI.PageClass;
namespace Orchard.Core.Tests.Common.Providers {
[TestFixture]
@@ -75,6 +76,7 @@ namespace Orchard.Core.Tests.Common.Providers {
CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
};
builder.RegisterInstance<DefaultDisplayManagerTests.TestWorkContextAccessor>(new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext)).As<IWorkContextAccessor>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
DefaultShapeTableManagerTests.TestShapeProvider.FeatureShapes = new Dictionary<Feature, IEnumerable<string>> {

View File

@@ -17,6 +17,7 @@ using Orchard.Tasks;
using Orchard.Tasks.Scheduling;
using Orchard.Tests.Modules;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Core.Tests.Scheduling {
[TestFixture]
@@ -45,6 +46,7 @@ namespace Orchard.Core.Tests.Scheduling {
builder.RegisterInstance(_handler).As<IScheduledTaskHandler>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
}

View File

@@ -17,6 +17,7 @@ using Orchard.Environment.Extensions;
using Orchard.Tasks.Scheduling;
using Orchard.Tests.Modules;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Core.Tests.Scheduling {
[TestFixture]
@@ -48,6 +49,7 @@ namespace Orchard.Core.Tests.Scheduling {
builder.RegisterType<ScheduledTaskManager>().As<IScheduledTaskManager>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
}

View File

@@ -23,6 +23,7 @@ using Orchard.Environment.Extensions;
using Orchard.Security;
using Orchard.Tests.Stubs;
using Orchard.UI.Notify;
using Orchard.UI.PageClass;
namespace Orchard.Tests.Modules.Comments.Services {
[TestFixture]
@@ -49,6 +50,7 @@ namespace Orchard.Tests.Modules.Comments.Services {
builder.RegisterType<CommentPartHandler>().As<IContentHandler>();
builder.RegisterType<CommonPartHandler>().As<IContentHandler>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
}

View File

@@ -23,6 +23,7 @@ using Orchard.Messaging.Services;
using Orchard.Security;
using Orchard.Tests.Stubs;
using Orchard.Tests.Utility;
using Orchard.UI.PageClass;
using Orchard.Users.Handlers;
using Orchard.Users.Models;
using Orchard.Users.Services;
@@ -84,6 +85,7 @@ namespace Orchard.Tests.Modules.Users.Services {
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
_session = _sessionFactory.OpenSession();

View File

@@ -25,6 +25,7 @@ using Orchard.Security;
using Orchard.Security.Providers;
using Orchard.Tests.Stubs;
using Orchard.Tests.Utility;
using Orchard.UI.PageClass;
using Orchard.Users.Handlers;
using Orchard.Users.Models;
using Orchard.Users.Services;
@@ -96,6 +97,7 @@ namespace Orchard.Tests.Modules.Users.Services {
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterType<DefaultEncryptionService>().As<IEncryptionService>();

View File

@@ -21,6 +21,7 @@ using Orchard.Environment.Features;
using Orchard.Security;
using Orchard.Tests.Stubs;
using Orchard.UI.Notify;
using Orchard.UI.PageClass;
using Orchard.Widgets.Models;
using Orchard.Widgets.Services;
@@ -103,6 +104,7 @@ namespace Orchard.Tests.Modules.Widgets.Services {
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();
builder.RegisterType<StubLayerPartHandler>().As<IContentHandler>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
}

View File

@@ -17,6 +17,7 @@ using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Implementation;
using Orchard.Tests.Stubs;
using NHibernate.Impl;
using Orchard.UI.PageClass;
namespace Orchard.Tests.ContentManagement {
[TestFixture]
@@ -63,6 +64,7 @@ namespace Orchard.Tests.ContentManagement {
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
_session = _sessionFactory.OpenSession();

View File

@@ -21,6 +21,7 @@ using Orchard.DisplayManagement.Implementation;
using Orchard.DisplayManagement;
using System.Collections.Generic;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Tests.ContentManagement {
[TestFixture]
@@ -71,6 +72,7 @@ namespace Orchard.Tests.ContentManagement {
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();

View File

@@ -16,6 +16,7 @@ using Orchard.Tests.ContentManagement.Records;
using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Implementation;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Tests.ContentManagement {
[TestFixture]
@@ -62,6 +63,7 @@ namespace Orchard.Tests.ContentManagement {
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
_session = _sessionFactory.OpenSession();

View File

@@ -18,6 +18,7 @@ using Orchard.Tests.ContentManagement.Records;
using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Implementation;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Tests.ContentManagement {
[TestFixture]
@@ -66,6 +67,7 @@ namespace Orchard.Tests.ContentManagement {
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
_session = _sessionFactory.OpenSession();

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
@@ -11,6 +12,7 @@ using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Tests.DisplayManagement.Descriptors {
[TestFixture]
@@ -57,6 +59,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
.As<TestShapeProvider>()
.InstancePerLifetimeScope();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
}

View File

@@ -1,10 +1,4 @@
@using Orchard.ContentManagement
@using Orchard.Utility.Extensions
@{
ContentItem contentItem = Model.ContentItem;
Html.AddPageClassNames("edit-" + contentItem.ContentType.HtmlClassify());
}
<div class="edit-item">
<div class="edit-item">
<div class="edit-item-primary">
@if (Model.Content != null) {
<div class="edit-item-content">

View File

@@ -5,7 +5,6 @@
}
var contentTypeClassName = ((string)Model.ContentItem.ContentType).HtmlClassify();
Html.AddPageClassNames("display-" + contentTypeClassName);
}
<article class="content-item @contentTypeClassName">
<header>

View File

@@ -42,6 +42,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
@@ -18,6 +19,7 @@ using Orchard.Projections.Models;
using Orchard.Projections.Services;
using Orchard.Tests;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Projections.Tests.Services {
[TestFixture]
@@ -40,6 +42,7 @@ namespace Orchard.Projections.Tests.Services {
// ContentDefinitionManager
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<Signals>().As<ISignals>();

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
@@ -23,6 +24,7 @@ using Orchard.Projections.Models;
using Orchard.Projections.Services;
using Orchard.Tests;
using Orchard.Tests.Stubs;
using Orchard.UI.PageClass;
namespace Orchard.Projections.Tests.Services {
public class FieldIndexStorageTests : DatabaseEnabledTestsBase {
@@ -47,6 +49,7 @@ namespace Orchard.Projections.Tests.Services {
// ContentDefinitionManager
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<Signals>().As<ISignals>();

View File

@@ -7,10 +7,13 @@ using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
using Orchard.UI.PageClass;
using Orchard.UI.Zones;
using Orchard.Utility.Extensions;
namespace Orchard.ContentManagement {
public class DefaultContentDisplay : IContentDisplay {
private readonly IPageClassBuilder _pageClassBuilder;
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
private readonly IShapeFactory _shapeFactory;
private readonly Lazy<IShapeTableLocator> _shapeTableLocator;
@@ -20,13 +23,14 @@ namespace Orchard.ContentManagement {
private readonly IWorkContextAccessor _workContextAccessor;
public DefaultContentDisplay(
IPageClassBuilder pageClassBuilder,
Lazy<IEnumerable<IContentHandler>> handlers,
IShapeFactory shapeFactory,
Lazy<IShapeTableLocator> shapeTableLocator,
RequestContext requestContext,
IVirtualPathProvider virtualPathProvider,
IWorkContextAccessor workContextAccessor) {
_pageClassBuilder = pageClassBuilder;
_handlers = handlers;
_shapeFactory = shapeFactory;
_shapeTableLocator = shapeTableLocator;
@@ -48,6 +52,10 @@ namespace Orchard.ContentManagement {
var actualShapeType = stereotype;
var actualDisplayType = string.IsNullOrWhiteSpace(displayType) ? "Detail" : displayType;
if (actualDisplayType == "Detail") {
_pageClassBuilder.AddClassNames("detail-" + content.ContentItem.ContentType.HtmlClassify());
}
dynamic itemShape = CreateItemShape(actualShapeType);
itemShape.ContentItem = content.ContentItem;
itemShape.Metadata.DisplayType = actualDisplayType;
@@ -69,18 +77,20 @@ namespace Orchard.ContentManagement {
stereotype = "Content";
var actualShapeType = stereotype + "_Edit";
_pageClassBuilder.AddClassNames("edit-" + content.ContentItem.ContentType.HtmlClassify());
dynamic itemShape = CreateItemShape(actualShapeType);
itemShape.ContentItem = content.ContentItem;
// adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
((IShape)itemShape).Metadata.Alternates.Add(actualShapeType + "__" + content.ContentItem.ContentType);
var context = new BuildEditorContext(itemShape, content, groupId, _shapeFactory);
BindPlacement(context, null, stereotype);
_handlers.Value.Invoke(handler => handler.BuildEditor(context), Logger);
return context.Shape;
}
@@ -91,6 +101,7 @@ namespace Orchard.ContentManagement {
stereotype = "Content";
var actualShapeType = stereotype + "_Edit";
_pageClassBuilder.AddClassNames("edit-" + content.ContentItem.ContentType.HtmlClassify());
dynamic itemShape = CreateItemShape(actualShapeType);
itemShape.ContentItem = content.ContentItem;