mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
Adding some shape definitions into Orchard.Shapes
A few details of Layout/Document/Zone shapes are described Three utility shapes are provided as [Shape] methods An IOrchardViewPage interface is introduced to ensure all base view classes have the same minimum number of methods and properties available --HG-- branch : theming
This commit is contained in:
@@ -23,8 +23,10 @@ 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<IShapeDescriptorBindingStrategy>();
|
||||
builder.RegisterType<NumberIsAlwaysFortyTwo>().As<IShapeFactoryEvents>();
|
||||
|
||||
throw new NotImplementedException("this test fixture needs to move to modules tests now");
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
|
||||
@@ -223,6 +223,7 @@
|
||||
<Compile Include="Settings\Models\SiteSettingsPart.cs" />
|
||||
<Compile Include="Settings\Services\SiteService.cs" />
|
||||
<Compile Include="Settings\ViewModels\SettingsIndexViewModel.cs" />
|
||||
<Compile Include="Shapes\CoreShapes.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\HomeController.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
|
||||
<Compile Include="XmlRpc\IXmlRpcHandler.cs" />
|
||||
@@ -345,6 +346,10 @@
|
||||
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Clay\src\ClaySharp\ClaySharp.csproj">
|
||||
<Project>{76BCD43B-7BA5-4B63-B1E1-861641CA2686}</Project>
|
||||
<Name>ClaySharp</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Orchard\Orchard.Framework.csproj">
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard.Framework</Name>
|
||||
|
||||
46
src/Orchard.Web/Core/Shapes/CoreShapes.cs
Normal file
46
src/Orchard.Web/Core/Shapes/CoreShapes.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.UI;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
||||
public Feature Feature { get; set; }
|
||||
|
||||
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)
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory)))
|
||||
.Configure(descriptor => descriptor.Wrappers.Add("Document"));
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
builder.Describe.Named("Zone").From(Feature.Descriptor)
|
||||
.OnCreating(creating => creating.BaseType = typeof(Zone));
|
||||
}
|
||||
|
||||
static object DetermineModel(HtmlHelper Html, object Model) {
|
||||
bool isNull = ((dynamic)Model) == null;
|
||||
return isNull ? Html.ViewData.Model : Model;
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Partial(HtmlHelper Html, string TemplateName, object Model) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString DisplayTemplate(HtmlHelper Html, string TemplateName, object Model, string Prefix) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString EditorTemplate(HtmlHelper Html, string TemplateName, object Model, string Prefix) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Orchard.Commands.Builtin;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Shapes;
|
||||
using Orchard.Data.Migration.Interpreters;
|
||||
using Orchard.Data.Providers;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
@@ -309,6 +309,7 @@
|
||||
<Content Include="Themes\TheAdmin\Styles\images\backgroundHeader.gif" />
|
||||
<Content Include="Themes\TheAdmin\Styles\images\orchardLogo.gif" />
|
||||
<Content Include="Themes\TheAdmin\Theme.png" />
|
||||
<None Include="Themes\TheAdmin\Views\DumpShapeTable.cshtml" />
|
||||
<None Include="Themes\TheAdmin\Views\MenuItem.cshtml" />
|
||||
<None Include="Themes\TheAdmin\Views\Menu.cshtml" />
|
||||
<None Include="Themes\TheAdmin\Views\Menu.ascx_" />
|
||||
|
||||
18
src/Orchard.Web/Themes/TheAdmin/Views/DumpShapeTable.cshtml
Normal file
18
src/Orchard.Web/Themes/TheAdmin/Views/DumpShapeTable.cshtml
Normal file
@@ -0,0 +1,18 @@
|
||||
@using Orchard
|
||||
@using Orchard.DisplayManagement.Descriptors
|
||||
@{
|
||||
var workContext = ViewContext.GetWorkContext();
|
||||
var shapeTable = workContext.Resolve<IShapeTableManager>().GetShapeTable(workContext.CurrentTheme.ThemeName);
|
||||
|
||||
<ul>
|
||||
@foreach(var descriptor in shapeTable.Descriptors) {
|
||||
<li>@descriptor.Key : @descriptor.Value.BindingSource
|
||||
@if(descriptor.Value.FrameTypes.Any()){
|
||||
foreach(var ft in descriptor.Value.FrameTypes) {
|
||||
@(" +"+ft)
|
||||
}
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@@ -1,26 +1,45 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.DisplayManagement.Descriptors" %>
|
||||
<%@ Import Namespace="Orchard" %>
|
||||
<%
|
||||
Model.Content.Add(Model.Metadata.ChildContent, "5");
|
||||
Model.Content.Add(Model.Metadata.ChildContent, "5");
|
||||
|
||||
// these are just hacked together to fire existing partials... can change
|
||||
Model.Header.Add(Display.Header());
|
||||
Model.Header.Add(Display.User(CurrentUser:Html.Resolve<IAuthenticationService>().GetAuthenticatedUser()), "after");
|
||||
// these are just hacked together to fire existing partials... can change
|
||||
Model.Header.Add(Display.Header());
|
||||
|
||||
Html.RegisterStyle("site.css", "1");
|
||||
Html.RegisterStyle("ie.css", "1").WithCondition("if (lte IE 8)").ForMedia("screen, projection");
|
||||
Html.RegisterStyle("ie6.css", "1").WithCondition("if (lte IE 6)").ForMedia("screen, projection");
|
||||
Html.RegisterFootScript("admin.js", "1");
|
||||
var thisUser = Html.Resolve<IAuthenticationService>().GetAuthenticatedUser();
|
||||
|
||||
// these are just hacked together to fire existing partials... can change
|
||||
Model.Header.Add(Display.User(CurrentUser: thisUser), "after");
|
||||
|
||||
//Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||
//Model.Zones.AddRenderPartial("header:after", "User", Model); // todo: (heskew) should be a user display or widget
|
||||
Model.CurrentUser = thisUser;
|
||||
Model.Header.Add(Display.Partial(TemplateName: "User"), "after");
|
||||
|
||||
var userDisplay = thisUser.ContentItem.ContentManager.BuildDisplayModel(thisUser, "Detail");
|
||||
Model.Content.Add(userDisplay);
|
||||
|
||||
Html.RegisterStyle("site.css", "1");
|
||||
Html.RegisterStyle("ie.css", "1").WithCondition("if (lte IE 8)").ForMedia("screen, projection");
|
||||
Html.RegisterStyle("ie6.css", "1").WithCondition("if (lte IE 6)").ForMedia("screen, projection");
|
||||
Html.RegisterFootScript("admin.js", "1");
|
||||
|
||||
// these are just hacked together to fire existing partials... can change
|
||||
|
||||
//Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||
//Model.Zones.AddRenderPartial("header:after", "User", Model); // todo: (heskew) should be a user display or widget
|
||||
%>
|
||||
<div id="header" role="banner"><%: Display(Model.Header) %></div>
|
||||
<div id="header" role="banner">
|
||||
<%: Display(Model.Header) %></div>
|
||||
<div id="content">
|
||||
<div id="navshortcut"><a href="#Menu-admin"><%: T("Skip to navigation") %></a></div>
|
||||
<div id="main" role="main"><%: Display(Model.Content) %></div>
|
||||
<div id="menu"><%: Display(Model.Navigation) %></div>
|
||||
<div id="navshortcut">
|
||||
<a href="#Menu-admin">
|
||||
<%: T("Skip to navigation") %></a></div>
|
||||
<div id="main" role="main">
|
||||
<%: Display(Model.Content) %></div>
|
||||
<div id="menu">
|
||||
<%: Display(Model.Navigation) %></div>
|
||||
</div>
|
||||
<div id="footer" role="contentinfo"><%: Display(Model.Footer) %></div>
|
||||
<div id="footer" role="contentinfo">
|
||||
<%: Display(Model.Footer) %></div>
|
||||
|
||||
<%: Display.DumpShapeTable() %>
|
||||
|
||||
@@ -20,15 +20,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
sa,
|
||||
mi,
|
||||
registration,
|
||||
() => GetFeatureDescriptor(registration))))
|
||||
() => GetFeature(registration))))
|
||||
.ToArray();
|
||||
|
||||
if (occurrences.Any())
|
||||
_occurrences.AddRange(occurrences);
|
||||
}
|
||||
|
||||
private static FeatureDescriptor GetFeatureDescriptor(IComponentRegistration registration) {
|
||||
object value; return registration.Metadata.TryGetValue("Feature", out value) ? value as FeatureDescriptor : null;
|
||||
private static Feature GetFeature(IComponentRegistration registration) {
|
||||
object value; return registration.Metadata.TryGetValue("Feature", out value) ? value as Feature : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
var shapeType = occurrence.ShapeAttribute.ShapeType ?? occurrence.MethodInfo.Name;
|
||||
builder.Describe
|
||||
.Named(shapeType)
|
||||
.From(occurrence.Feature)
|
||||
.From(occurrence.Feature.Descriptor)
|
||||
.BoundAs(
|
||||
occurrence.MethodInfo.DeclaringType.FullName + "::" + occurrence.MethodInfo.Name,
|
||||
descriptor => CreateDelegate(occurrence, descriptor));
|
||||
|
||||
@@ -5,9 +5,9 @@ using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
public class ShapeAttributeOccurrence {
|
||||
private readonly Func<FeatureDescriptor> _feature;
|
||||
private readonly Func<Feature> _feature;
|
||||
|
||||
public ShapeAttributeOccurrence(ShapeAttribute shapeAttribute, MethodInfo methodInfo, IComponentRegistration registration, Func<FeatureDescriptor> feature) {
|
||||
public ShapeAttributeOccurrence(ShapeAttribute shapeAttribute, MethodInfo methodInfo, IComponentRegistration registration, Func<Feature> feature) {
|
||||
ShapeAttribute = shapeAttribute;
|
||||
MethodInfo = methodInfo;
|
||||
Registration = registration;
|
||||
@@ -17,6 +17,6 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
public ShapeAttribute ShapeAttribute { get; private set; }
|
||||
public MethodInfo MethodInfo { get; private set; }
|
||||
public IComponentRegistration Registration { get; private set; }
|
||||
public FeatureDescriptor Feature { get { return _feature(); } }
|
||||
public Feature Feature { get { return _feature(); } }
|
||||
}
|
||||
}
|
||||
12
src/Orchard/Mvc/IOrchardViewPage.cs
Normal file
12
src/Orchard/Mvc/IOrchardViewPage.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
/// <summary>
|
||||
/// This interface ensures all base view pages implement the
|
||||
/// same set of additional members
|
||||
/// </summary>
|
||||
public interface IOrchardViewPage {
|
||||
Localizer T { get; }
|
||||
dynamic Display { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
|
||||
public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel> {
|
||||
public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>, IOrchardViewPage {
|
||||
private object _display;
|
||||
private object _new;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
|
||||
@@ -8,7 +8,7 @@ using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class ViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> {
|
||||
public class ViewPage<TModel> : System.Web.Mvc.ViewPage<TModel>, IOrchardViewPage {
|
||||
private object _display;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class ViewUserControl<TModel> : System.Web.Mvc.ViewUserControl<TModel> {
|
||||
public class ViewUserControl<TModel> : System.Web.Mvc.ViewUserControl<TModel>,IOrchardViewPage {
|
||||
private object _display;
|
||||
private object _new;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
|
||||
@@ -145,6 +145,7 @@
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptorAlterationBuilder.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTable.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTableBuilder.cs" />
|
||||
<Compile Include="Mvc\IOrchardViewPage.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />
|
||||
<Compile Include="UI\Zones\PageWorkContext.cs" />
|
||||
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Linq;
|
||||
using ClaySharp.Implementation;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.UI.Zones {
|
||||
public class PageWorkContext : IWorkContextStateProvider {
|
||||
@@ -19,23 +17,4 @@ namespace Orchard.UI.Zones {
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
var feature = new FeatureDescriptor {
|
||||
Name = "Orchard.Framework",
|
||||
Extension = new ExtensionDescriptor {
|
||||
Name = "Orchard.Framework",
|
||||
ExtensionType = "Module",
|
||||
}
|
||||
};
|
||||
|
||||
builder.Describe.Named("Layout").From(feature)
|
||||
.OnCreating(context => context.Behaviors.Add(new ZoneHoldingBehavior(context.ShapeFactory)))
|
||||
.Configure(d => d.FrameTypes.Add("Document"));
|
||||
|
||||
builder.Describe.Named("Zone").From(feature)
|
||||
.OnCreating(context => context.BaseType = typeof(Zone));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user