mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding Frames collection to shape descriptor and metadata
--HG-- branch : theming
This commit is contained in:
@@ -1 +1 @@
|
|||||||
3bc513c8049ad19173130a0e0e6a5486ee8247d2 Clay
|
cf89a75f4158f045c90fb7e5ee1a766623abaa71 Clay
|
||||||
|
@@ -7,6 +7,7 @@ using NUnit.Framework;
|
|||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.DisplayManagement.Descriptors;
|
using Orchard.DisplayManagement.Descriptors;
|
||||||
using Orchard.DisplayManagement.Implementation;
|
using Orchard.DisplayManagement.Implementation;
|
||||||
|
using Orchard.DisplayManagement.Shapes;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.UI.Zones;
|
using Orchard.UI.Zones;
|
||||||
@@ -33,7 +34,7 @@ namespace Orchard.Tests.UI {
|
|||||||
[Test]
|
[Test]
|
||||||
public void WorkContextPageIsLayoutShape() {
|
public void WorkContextPageIsLayoutShape() {
|
||||||
var page = _workContext.Page;
|
var page = _workContext.Page;
|
||||||
IShapeMetadata pageMetadata = page.Metadata;
|
ShapeMetadata pageMetadata = page.Metadata;
|
||||||
Assert.That(pageMetadata.Type, Is.EqualTo("Layout"));
|
Assert.That(pageMetadata.Type, Is.EqualTo("Layout"));
|
||||||
Assert.That(page.Metadata.Type, Is.EqualTo("Layout"));
|
Assert.That(page.Metadata.Type, Is.EqualTo("Layout"));
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,20 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BaseViewModel>" %>
|
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"
|
<%@ Import Namespace="Orchard.Mvc.Html"
|
||||||
%><!DOCTYPE html>
|
%><!DOCTYPE html>
|
||||||
<html lang="en" class="static">
|
<html lang="en" class="static">
|
||||||
<head>
|
<head>
|
||||||
<title><%: Html.Title() %></title>
|
<title><%: Html.Title() %></title>
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="<%=ResolveUrl("../Content/orchard.ico") %>" /><%
|
<link rel="shortcut icon" type="image/x-icon" href="<%=ResolveUrl("../Content/orchard.ico") %>" />
|
||||||
|
<%--<%
|
||||||
//todo: (heskew) have resource modules that can be leaned on (like a jQuery module that knows about various CDNs and jQuery's version and min naming schemes)
|
//todo: (heskew) have resource modules that can be leaned on (like a jQuery module that knows about various CDNs and jQuery's version and min naming schemes)
|
||||||
//todo: (heskew) this is an interim solution to inlude jQuery in every page and still allow that to be overriden in some theme by it containing a headScripts partial
|
//todo: (heskew) this is an interim solution to inlude jQuery in every page and still allow that to be overriden in some theme by it containing a headScripts partial
|
||||||
Html.Zone("head", ":metas :styles :scripts"); %>
|
Html.Zone("head", ":metas :styles :scripts"); %>--%>
|
||||||
|
<%:Display(Model.Head) %>
|
||||||
<script type="text/javascript">document.documentElement.className="dyn";</script>
|
<script type="text/javascript">document.documentElement.className="dyn";</script>
|
||||||
</head>
|
</head>
|
||||||
<body class="<%: Html.ClassForPage() %>"><%
|
<body class="<%: Html.ClassForPage() %>">
|
||||||
Html.ZoneBody("body"); %>
|
<% Model.Body.Add(Model.Metadata.ChildContent, "5"); %>
|
||||||
|
<%: Display(Model.Body) %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
|
||||||
|
|
||||||
<%-- //todo: (heskew) this should really be using the IResourceManager if it's to be a theme especially for the jquery dep (w/out needing to copy into this theme...)
|
<%-- //todo: (heskew) this should really be using the IResourceManager if it's to be a theme especially for the jquery dep (w/out needing to copy into this theme...)
|
||||||
var jquery = ResolveUrl("~/Modules/Orchard.Themes/Scripts/jquery-1.4.2.js");
|
var jquery = ResolveUrl("~/Modules/Orchard.Themes/Scripts/jquery-1.4.2.js");
|
||||||
Model.Zones.AddAction("head:scripts", html =>
|
Model.Zones.AddAction("head:scripts", html =>
|
||||||
@@ -16,11 +15,14 @@
|
|||||||
var ie6Css = ResolveUrl("../Styles/ie6.css");
|
var ie6Css = ResolveUrl("../Styles/ie6.css");
|
||||||
Model.Zones.AddAction("head:styles", html =>
|
Model.Zones.AddAction("head:styles", html =>
|
||||||
html.ViewContext.Writer.Write(@"<!--[if lte IE 6]><link rel=""stylesheet"" type=""text/css"" media=""screen, projection"" href=""" + ie6Css + @"""/><![endif]-->"));
|
html.ViewContext.Writer.Write(@"<!--[if lte IE 6]><link rel=""stylesheet"" type=""text/css"" media=""screen, projection"" href=""" + ie6Css + @"""/><![endif]-->"));
|
||||||
--%>
|
--%>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<div id="branding"><h1>Welcome to Orchard</h1></div>
|
<div id="branding">
|
||||||
|
<h1>
|
||||||
|
Welcome to Orchard</h1>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
<% Model.Content.Add(Model.Metadata.ChildContent, "5"); %>
|
||||||
<%: Display(Model.Content) %>
|
<%: Display(Model.Content) %>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
|
||||||
<div class="zone zone-<%:Model.ZoneName %>">
|
<div class="zone zone-<%:Model.ZoneName %>">
|
||||||
<%foreach (var item in Model.Items) {%><%:Display(item)%><%}%>
|
<%foreach (var item in Model) {%><%:Display(item)%><%}%>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,10 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Orchard.DisplayManagement.Implementation;
|
using Orchard.DisplayManagement.Implementation;
|
||||||
|
|
||||||
namespace Orchard.DisplayManagement.Descriptors {
|
namespace Orchard.DisplayManagement.Descriptors {
|
||||||
public class ShapeDescriptor {
|
public class ShapeDescriptor {
|
||||||
|
public ShapeDescriptor() {
|
||||||
|
Creating = Enumerable.Empty<Action<ShapeCreatingContext>>();
|
||||||
|
Created = Enumerable.Empty<Action<ShapeCreatedContext>>();
|
||||||
|
FrameTypes = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
public string ShapeType { get; set; }
|
public string ShapeType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -16,7 +23,8 @@ namespace Orchard.DisplayManagement.Descriptors {
|
|||||||
public Func<DisplayContext, IHtmlString> Binding { get; set; }
|
public Func<DisplayContext, IHtmlString> Binding { get; set; }
|
||||||
|
|
||||||
public IEnumerable<Action<ShapeCreatingContext>> Creating {get;set;}
|
public IEnumerable<Action<ShapeCreatingContext>> Creating {get;set;}
|
||||||
|
|
||||||
public IEnumerable<Action<ShapeCreatedContext>> Created {get;set;}
|
public IEnumerable<Action<ShapeCreatedContext>> Created {get;set;}
|
||||||
|
|
||||||
|
public IList<string> FrameTypes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,10 +1,12 @@
|
|||||||
namespace Orchard.DisplayManagement {
|
using Orchard.DisplayManagement.Shapes;
|
||||||
|
|
||||||
|
namespace Orchard.DisplayManagement {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface present on dynamic shapes.
|
/// Interface present on dynamic shapes.
|
||||||
/// May be used to access attributes in a strongly typed fashion.
|
/// May be used to access attributes in a strongly typed fashion.
|
||||||
/// Note: Anything on this interface is a reserved word for the purpose of shape properties
|
/// Note: Anything on this interface is a reserved word for the purpose of shape properties
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IShape {
|
public interface IShape {
|
||||||
IShapeMetadata Metadata { get; set; }
|
ShapeMetadata Metadata { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +0,0 @@
|
|||||||
namespace Orchard.DisplayManagement {
|
|
||||||
public interface IShapeMetadata {
|
|
||||||
string Type { get; set; }
|
|
||||||
string Position { get; set; }
|
|
||||||
bool WasExecuted { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -51,10 +51,20 @@ namespace Orchard.DisplayManagement.Implementation {
|
|||||||
|
|
||||||
ShapeDescriptor shapeDescriptor;
|
ShapeDescriptor shapeDescriptor;
|
||||||
if (shapeTable.Descriptors.TryGetValue(shapeMetadata.Type, out shapeDescriptor)) {
|
if (shapeTable.Descriptors.TryGetValue(shapeMetadata.Type, out shapeDescriptor)) {
|
||||||
return Process(shapeDescriptor, shape, context);
|
shape.Metadata.ChildContent = Process(shapeDescriptor, shape, context);
|
||||||
}
|
}
|
||||||
//postproc / content html alteration/wrapping/etc
|
else {
|
||||||
throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
|
throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var frameType in shape.Metadata.FrameTypes) {
|
||||||
|
ShapeDescriptor frameDescriptor;
|
||||||
|
if (shapeTable.Descriptors.TryGetValue(frameType, out frameDescriptor)) {
|
||||||
|
shape.Metadata.ChildContent = Process(frameDescriptor, shape, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shape.Metadata.ChildContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IHtmlString CoerceHtmlString(object value) {
|
private IHtmlString CoerceHtmlString(object value) {
|
||||||
@@ -83,9 +93,10 @@ namespace Orchard.DisplayManagement.Implementation {
|
|||||||
public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion) {
|
public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion) {
|
||||||
// adjust the normal csharp convert binder to allow failure to become null.
|
// adjust the normal csharp convert binder to allow failure to become null.
|
||||||
// this causes the same net effect as the "as" keyword, but may be applied to dynamic objects
|
// this causes the same net effect as the "as" keyword, but may be applied to dynamic objects
|
||||||
return _innerBinder.FallbackConvert(
|
var result = _innerBinder.FallbackConvert(
|
||||||
target,
|
target,
|
||||||
errorSuggestion ?? new DynamicMetaObject(Expression.Default(_innerBinder.ReturnType), GetTypeRestriction(target)));
|
errorSuggestion ?? new DynamicMetaObject(Expression.Default(_innerBinder.ReturnType), GetTypeRestriction(target)));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BindingRestrictions GetTypeRestriction(DynamicMetaObject obj) {
|
static BindingRestrictions GetTypeRestriction(DynamicMetaObject obj) {
|
||||||
|
@@ -85,7 +85,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
|||||||
foreach (var ev in _events) {
|
foreach (var ev in _events) {
|
||||||
ev.Value.Creating(creatingContext);
|
ev.Value.Creating(creatingContext);
|
||||||
}
|
}
|
||||||
if (shapeDescriptor != null && shapeDescriptor.Creating != null) {
|
if (shapeDescriptor != null) {
|
||||||
foreach (var ev in shapeDescriptor.Creating) {
|
foreach (var ev in shapeDescriptor.Creating) {
|
||||||
ev(creatingContext);
|
ev(creatingContext);
|
||||||
}
|
}
|
||||||
@@ -97,13 +97,17 @@ namespace Orchard.DisplayManagement.Implementation {
|
|||||||
ShapeType = creatingContext.ShapeType,
|
ShapeType = creatingContext.ShapeType,
|
||||||
Shape = ClayActivator.CreateInstance(creatingContext.BaseType, creatingContext.Behaviors)
|
Shape = ClayActivator.CreateInstance(creatingContext.BaseType, creatingContext.Behaviors)
|
||||||
};
|
};
|
||||||
createdContext.Shape.Metadata = new ShapeMetadata { Type = shapeType };
|
var shapeMetadata = new ShapeMetadata { Type = shapeType };
|
||||||
|
createdContext.Shape.Metadata = shapeMetadata;
|
||||||
|
|
||||||
|
if (shapeDescriptor != null)
|
||||||
|
shapeMetadata.FrameTypes = shapeMetadata.FrameTypes.Concat(shapeDescriptor.FrameTypes).ToList();
|
||||||
|
|
||||||
// "created" events provides default values and new object initialization
|
// "created" events provides default values and new object initialization
|
||||||
foreach (var ev in _events) {
|
foreach (var ev in _events) {
|
||||||
ev.Value.Created(createdContext);
|
ev.Value.Created(createdContext);
|
||||||
}
|
}
|
||||||
if (shapeDescriptor != null && shapeDescriptor.Created != null) {
|
if (shapeDescriptor != null) {
|
||||||
foreach (var ev in shapeDescriptor.Created) {
|
foreach (var ev in shapeDescriptor.Created) {
|
||||||
ev(createdContext);
|
ev(createdContext);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
namespace Orchard.DisplayManagement.Shapes {
|
namespace Orchard.DisplayManagement.Shapes {
|
||||||
public class Shape : IShape {
|
public class Shape : IShape {
|
||||||
public virtual IShapeMetadata Metadata { get; set; }
|
public virtual ShapeMetadata Metadata { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,18 @@
|
|||||||
namespace Orchard.DisplayManagement.Shapes {
|
using System.Collections.Generic;
|
||||||
public class ShapeMetadata : IShapeMetadata {
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Orchard.DisplayManagement.Shapes {
|
||||||
|
public class ShapeMetadata {
|
||||||
|
public ShapeMetadata() {
|
||||||
|
FrameTypes = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
public string Position { get; set; }
|
public string Position { get; set; }
|
||||||
|
public IList<string> FrameTypes { get; set; }
|
||||||
|
|
||||||
public bool WasExecuted { get; set; }
|
public bool WasExecuted { get; set; }
|
||||||
|
public IHtmlString ChildContent { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -27,23 +27,24 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) {
|
public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) {
|
||||||
var findBody = _themeAwareViewEngine.FindPartialView(controllerContext, viewName, useCache, true);
|
var viewResult = _themeAwareViewEngine.FindPartialView(controllerContext, viewName, useCache, true);
|
||||||
|
|
||||||
if (findBody.View == null) {
|
if (viewResult.View == null) {
|
||||||
return findBody;
|
return viewResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
var layoutView = new LayoutView((viewContext, writer, viewDataContainer) => {
|
var layoutView = new LayoutView((viewContext, writer, viewDataContainer) => {
|
||||||
var buffer = new StringWriter();
|
var buffer = new StringWriter();
|
||||||
findBody.View.Render(viewContext, buffer);
|
|
||||||
|
|
||||||
_workContext.Page.Zones.Content.Add(new HtmlString(buffer.ToString()), "5");
|
viewResult.View.Render(viewContext, buffer);
|
||||||
|
|
||||||
|
_workContext.Page.Metadata.ChildContent = new HtmlString(buffer.ToString());
|
||||||
|
|
||||||
var display = _displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
|
var display = _displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
|
||||||
IHtmlString result = display(_workContext.Page);
|
IHtmlString result = display(_workContext.Page);
|
||||||
writer.Write(result.ToHtmlString());
|
writer.Write(result.ToHtmlString());
|
||||||
|
|
||||||
}, (context, view) => findBody.ViewEngine.ReleaseView(context, findBody.View));
|
}, (context, view) => viewResult.ViewEngine.ReleaseView(context, viewResult.View));
|
||||||
|
|
||||||
return new ViewEngineResult(layoutView, this);
|
return new ViewEngineResult(layoutView, this);
|
||||||
}
|
}
|
||||||
|
@@ -36,4 +36,7 @@ namespace Orchard.Mvc {
|
|||||||
return Authorizer.Authorize(permission);
|
return Authorizer.Authorize(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ViewPage : ViewPage<dynamic> {
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
|
@@ -391,7 +391,6 @@
|
|||||||
<Compile Include="DisplayManagement\IShapeHelperFactory.cs" />
|
<Compile Include="DisplayManagement\IShapeHelperFactory.cs" />
|
||||||
<Compile Include="DisplayManagement\IDisplayHelperFactory.cs" />
|
<Compile Include="DisplayManagement\IDisplayHelperFactory.cs" />
|
||||||
<Compile Include="DisplayManagement\IShape.cs" />
|
<Compile Include="DisplayManagement\IShape.cs" />
|
||||||
<Compile Include="DisplayManagement\IShapeMetadata.cs" />
|
|
||||||
<Compile Include="DisplayManagement\Shapes\Shape.cs" />
|
<Compile Include="DisplayManagement\Shapes\Shape.cs" />
|
||||||
<Compile Include="DisplayManagement\Shapes\ShapeMetadata.cs" />
|
<Compile Include="DisplayManagement\Shapes\ShapeMetadata.cs" />
|
||||||
<Compile Include="DisplayManagement\Descriptors\DefaultShapeTableManager.cs" />
|
<Compile Include="DisplayManagement\Descriptors\DefaultShapeTableManager.cs" />
|
||||||
|
@@ -25,7 +25,7 @@ namespace Orchard.UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IZone {
|
public interface IZone : IEnumerable {
|
||||||
string ZoneName { get; set; }
|
string ZoneName { get; set; }
|
||||||
IZone Add(object item);
|
IZone Add(object item);
|
||||||
IZone Add(object item, string position);
|
IZone Add(object item, string position);
|
||||||
@@ -63,5 +63,9 @@ namespace Orchard.UI {
|
|||||||
return _items;
|
return _items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerator GetEnumerator() {
|
||||||
|
return _items.GetEnumerator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,14 +23,16 @@ namespace Orchard.UI.Zones {
|
|||||||
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
||||||
public void Discover(ShapeTableBuilder builder) {
|
public void Discover(ShapeTableBuilder builder) {
|
||||||
var feature = new FeatureDescriptor {
|
var feature = new FeatureDescriptor {
|
||||||
|
Name = "Orchard.Framework",
|
||||||
|
Extension = new ExtensionDescriptor {
|
||||||
Name = "Orchard.Framework",
|
Name = "Orchard.Framework",
|
||||||
Extension = new ExtensionDescriptor {
|
ExtensionType = "Module",
|
||||||
Name = "Orchard.Framework",
|
}
|
||||||
ExtensionType = "Module",
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
builder.Describe.Named("Layout").From(feature)
|
builder.Describe.Named("Layout").From(feature)
|
||||||
.OnCreating(context => context.Behaviors.Add(new ZoneHoldingBehavior(context.ShapeFactory)));
|
.OnCreating(context => context.Behaviors.Add(new ZoneHoldingBehavior(context.ShapeFactory)))
|
||||||
|
.Configure(d => d.FrameTypes.Add("Document"));
|
||||||
|
|
||||||
builder.Describe.Named("Zone").From(feature)
|
builder.Describe.Named("Zone").From(feature)
|
||||||
.OnCreating(context => context.BaseType = typeof(Zone));
|
.OnCreating(context => context.BaseType = typeof(Zone));
|
||||||
|
Reference in New Issue
Block a user