mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding a PlaceChildContent shape to Body and Content zones by default
--HG-- branch : theming
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.UI;
|
||||
using Orchard.UI.Zones;
|
||||
@@ -21,8 +22,12 @@ namespace Orchard.Core.Shapes {
|
||||
// the root page shape named 'Layout' is wrapped with 'Document'
|
||||
// and has an automatic zone creating behavior
|
||||
builder.Describe.Named("Layout").From(Feature.Descriptor)
|
||||
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory)))
|
||||
.Configure(descriptor => descriptor.Wrappers.Add("Document"));
|
||||
.OnCreated(created => {
|
||||
created.Shape.Zones.Content.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
created.Shape.Zones.Body.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
});
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
builder.Describe.Named("Zone").From(Feature.Descriptor)
|
||||
@@ -31,12 +36,14 @@ namespace Orchard.Core.Shapes {
|
||||
// 'List' shapes start with several empty collections
|
||||
builder.Describe.Named("List").From(Feature.Descriptor)
|
||||
.OnCreated(created => {
|
||||
created.Shape.Tag = "ol";
|
||||
created.Shape.Tag = "ul";
|
||||
created.Shape.Classes = new List<string>();
|
||||
created.Shape.Attributes = new Dictionary<string, string>();
|
||||
created.Shape.ItemClasses = new List<string>();
|
||||
created.Shape.ItemAttributes = new Dictionary<string, string>();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
static object DetermineModel(HtmlHelper Html, object Model) {
|
||||
@@ -66,7 +73,7 @@ namespace Orchard.Core.Shapes {
|
||||
IEnumerable<string> ItemClasses,
|
||||
IDictionary<string, string> ItemAttributes) {
|
||||
|
||||
var listTagName = string.IsNullOrEmpty(Tag) ? "ol" : Tag;
|
||||
var listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
|
||||
const string itemTagName = "li";
|
||||
|
||||
var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes);
|
||||
@@ -90,6 +97,10 @@ namespace Orchard.Core.Shapes {
|
||||
Output.Write(listTag.ToString(TagRenderMode.EndTag));
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString PlaceChildContent(dynamic Source) {
|
||||
return Source.Metadata.ChildContent;
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Partial(HtmlHelper Html, string TemplateName, object Model) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<script>(function(d){d.className="dyn "+d.className.substring(7,d.length);})(document.documentElement);</script>
|
||||
</head>
|
||||
<body>
|
||||
@{ Model.Body.Add(Model.Metadata.ChildContent, "5"); }
|
||||
@Display(Model.Body)
|
||||
</body>
|
||||
</html>
|
||||
@@ -12,9 +12,7 @@
|
||||
<div id="main">
|
||||
<div id="content-wrapper">
|
||||
<div id="content">
|
||||
@{
|
||||
Model.Content.Add(Model.Metadata.ChildContent, "5");
|
||||
}
|
||||
|
||||
@Display(Model.Content)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
Model.Header.Add(New.Header());
|
||||
Model.Header.Add(New.Footer());
|
||||
Model.Content.Add(Model.Metadata.ChildContent, "5");
|
||||
%>
|
||||
|
||||
<div id="container">
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<script type="text/javascript">document.documentElement.className="dyn";</script>
|
||||
</head>
|
||||
<body class="<%: Html.ClassForPage() %>">
|
||||
<% Model.Body.Add(Model.Metadata.ChildContent, "5"); %>
|
||||
<%: Display(Model.Body) %>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -23,6 +23,5 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Model.Content.Add(Model.Metadata.ChildContent, "5"); %>
|
||||
<%: Display(Model.Content) %>
|
||||
</div>
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
<%@ Import Namespace="Orchard" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement" %>
|
||||
<%
|
||||
Model.Content.Add(Model.Metadata.ChildContent, "5");
|
||||
|
||||
// these are just hacked together to fire existing partials... can change
|
||||
Model.Header.Add(Display.Header());
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ClaySharp;
|
||||
using ClaySharp.Implementation;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
@@ -8,4 +9,10 @@ namespace Orchard.DisplayManagement {
|
||||
public interface IShapeFactory : IDependency {
|
||||
IShape Create(string shapeType, INamedEnumerable<object> parameters);
|
||||
}
|
||||
|
||||
public static class ShapeFactoryExtensions {
|
||||
public static IShape Create(this IShapeFactory factory, string shapeType) {
|
||||
return factory.Create(shapeType, Arguments.Empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
|
||||
public class ShapeCreatingContext {
|
||||
public IShapeFactory ShapeFactory { get; set; }
|
||||
public dynamic New { get; set; }
|
||||
public string ShapeType { get; set; }
|
||||
public Type BaseType { get; set; }
|
||||
public IList<IClayBehavior> Behaviors { get; set; }
|
||||
@@ -26,6 +27,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
|
||||
public class ShapeCreatedContext {
|
||||
public IShapeFactory ShapeFactory { get; set; }
|
||||
public dynamic New { get; set; }
|
||||
public string ShapeType { get; set; }
|
||||
public dynamic Shape { get; set; }
|
||||
}
|
||||
@@ -35,10 +37,15 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
public class DefaultShapeFactory : IShapeFactory {
|
||||
private readonly IEnumerable<Lazy<IShapeFactoryEvents>> _events;
|
||||
private readonly IShapeTableManager _shapeTableManager;
|
||||
private readonly Lazy<IShapeHelperFactory> _shapeHelperFactory;
|
||||
|
||||
public DefaultShapeFactory(IEnumerable<Lazy<IShapeFactoryEvents>> events, IShapeTableManager shapeTableManager) {
|
||||
public DefaultShapeFactory(
|
||||
IEnumerable<Lazy<IShapeFactoryEvents>> events,
|
||||
IShapeTableManager shapeTableManager,
|
||||
Lazy<IShapeHelperFactory> shapeHelperFactory) {
|
||||
_events = events;
|
||||
_shapeTableManager = shapeTableManager;
|
||||
_shapeHelperFactory = shapeHelperFactory;
|
||||
}
|
||||
|
||||
public IShape Create(string shapeType, INamedEnumerable<object> parameters) {
|
||||
@@ -47,7 +54,8 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
defaultShapeTable.Descriptors.TryGetValue(shapeType, out shapeDescriptor);
|
||||
|
||||
var creatingContext = new ShapeCreatingContext {
|
||||
ShapeFactory = this,
|
||||
New = _shapeHelperFactory.Value.CreateHelper(),
|
||||
ShapeFactory=this,
|
||||
ShapeType = shapeType,
|
||||
OnCreated = new List<Action<ShapeCreatedContext>>()
|
||||
};
|
||||
@@ -93,7 +101,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
|
||||
// create the new instance
|
||||
var createdContext = new ShapeCreatedContext {
|
||||
ShapeFactory = this,
|
||||
New = creatingContext.New,
|
||||
ShapeType = creatingContext.ShapeType,
|
||||
Shape = ClayActivator.CreateInstance(creatingContext.BaseType, creatingContext.Behaviors)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user