Adding a PlaceChildContent shape to Body and Content zones by default

--HG--
branch : theming
This commit is contained in:
Louis DeJardin
2010-09-09 11:58:26 -07:00
parent b78e47cad8
commit 91684d050b
9 changed files with 33 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html; using System.Web.Mvc.Html;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors; using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Shapes;
using Orchard.Environment.Extensions.Models; using Orchard.Environment.Extensions.Models;
using Orchard.UI; using Orchard.UI;
using Orchard.UI.Zones; using Orchard.UI.Zones;
@@ -21,8 +22,12 @@ namespace Orchard.Core.Shapes {
// the root page shape named 'Layout' is wrapped with 'Document' // the root page shape named 'Layout' is wrapped with 'Document'
// and has an automatic zone creating behavior // and has an automatic zone creating behavior
builder.Describe.Named("Layout").From(Feature.Descriptor) builder.Describe.Named("Layout").From(Feature.Descriptor)
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory))) .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 // 'Zone' shapes are built on the Zone base class
builder.Describe.Named("Zone").From(Feature.Descriptor) builder.Describe.Named("Zone").From(Feature.Descriptor)
@@ -31,12 +36,14 @@ namespace Orchard.Core.Shapes {
// 'List' shapes start with several empty collections // 'List' shapes start with several empty collections
builder.Describe.Named("List").From(Feature.Descriptor) builder.Describe.Named("List").From(Feature.Descriptor)
.OnCreated(created => { .OnCreated(created => {
created.Shape.Tag = "ol"; created.Shape.Tag = "ul";
created.Shape.Classes = new List<string>(); created.Shape.Classes = new List<string>();
created.Shape.Attributes = new Dictionary<string, string>(); created.Shape.Attributes = new Dictionary<string, string>();
created.Shape.ItemClasses = new List<string>(); created.Shape.ItemClasses = new List<string>();
created.Shape.ItemAttributes = new Dictionary<string, string>(); created.Shape.ItemAttributes = new Dictionary<string, string>();
}); });
} }
static object DetermineModel(HtmlHelper Html, object Model) { static object DetermineModel(HtmlHelper Html, object Model) {
@@ -66,7 +73,7 @@ namespace Orchard.Core.Shapes {
IEnumerable<string> ItemClasses, IEnumerable<string> ItemClasses,
IDictionary<string, string> ItemAttributes) { IDictionary<string, string> ItemAttributes) {
var listTagName = string.IsNullOrEmpty(Tag) ? "ol" : Tag; var listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
const string itemTagName = "li"; const string itemTagName = "li";
var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes); var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes);
@@ -90,6 +97,10 @@ namespace Orchard.Core.Shapes {
Output.Write(listTag.ToString(TagRenderMode.EndTag)); Output.Write(listTag.ToString(TagRenderMode.EndTag));
} }
[Shape]
public IHtmlString PlaceChildContent(dynamic Source) {
return Source.Metadata.ChildContent;
}
[Shape] [Shape]
public IHtmlString Partial(HtmlHelper Html, string TemplateName, object Model) { public IHtmlString Partial(HtmlHelper Html, string TemplateName, object Model) {

View File

@@ -15,7 +15,6 @@
<script>(function(d){d.className="dyn "+d.className.substring(7,d.length);})(document.documentElement);</script> <script>(function(d){d.className="dyn "+d.className.substring(7,d.length);})(document.documentElement);</script>
</head> </head>
<body> <body>
@{ Model.Body.Add(Model.Metadata.ChildContent, "5"); }
@Display(Model.Body) @Display(Model.Body)
</body> </body>
</html> </html>

View File

@@ -12,9 +12,7 @@
<div id="main"> <div id="main">
<div id="content-wrapper"> <div id="content-wrapper">
<div id="content"> <div id="content">
@{
Model.Content.Add(Model.Metadata.ChildContent, "5");
}
@Display(Model.Content) @Display(Model.Content)
</div> </div>
</div> </div>

View File

@@ -6,7 +6,6 @@
Model.Header.Add(New.Header()); Model.Header.Add(New.Header());
Model.Header.Add(New.Footer()); Model.Header.Add(New.Footer());
Model.Content.Add(Model.Metadata.ChildContent, "5");
%> %>
<div id="container"> <div id="container">

View File

@@ -13,7 +13,6 @@
<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() %>">
<% Model.Body.Add(Model.Metadata.ChildContent, "5"); %>
<%: Display(Model.Body) %> <%: Display(Model.Body) %>
</body> </body>
</html> </html>

View File

@@ -23,6 +23,5 @@
</div> </div>
</div> </div>
<div id="main"> <div id="main">
<% Model.Content.Add(Model.Metadata.ChildContent, "5"); %>
<%: Display(Model.Content) %> <%: Display(Model.Content) %>
</div> </div>

View File

@@ -4,8 +4,6 @@
<%@ Import Namespace="Orchard" %> <%@ Import Namespace="Orchard" %>
<%@ Import Namespace="Orchard.ContentManagement" %> <%@ Import Namespace="Orchard.ContentManagement" %>
<% <%
Model.Content.Add(Model.Metadata.ChildContent, "5");
// these are just hacked together to fire existing partials... can change // these are just hacked together to fire existing partials... can change
Model.Header.Add(Display.Header()); Model.Header.Add(Display.Header());

View File

@@ -1,4 +1,5 @@
using ClaySharp; using ClaySharp;
using ClaySharp.Implementation;
namespace Orchard.DisplayManagement { namespace Orchard.DisplayManagement {
/// <summary> /// <summary>
@@ -8,4 +9,10 @@ namespace Orchard.DisplayManagement {
public interface IShapeFactory : IDependency { public interface IShapeFactory : IDependency {
IShape Create(string shapeType, INamedEnumerable<object> parameters); 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());
}
}
} }

View File

@@ -18,6 +18,7 @@ namespace Orchard.DisplayManagement.Implementation {
public class ShapeCreatingContext { public class ShapeCreatingContext {
public IShapeFactory ShapeFactory { get; set; } public IShapeFactory ShapeFactory { get; set; }
public dynamic New { get; set; }
public string ShapeType { get; set; } public string ShapeType { get; set; }
public Type BaseType { get; set; } public Type BaseType { get; set; }
public IList<IClayBehavior> Behaviors { get; set; } public IList<IClayBehavior> Behaviors { get; set; }
@@ -26,6 +27,7 @@ namespace Orchard.DisplayManagement.Implementation {
public class ShapeCreatedContext { public class ShapeCreatedContext {
public IShapeFactory ShapeFactory { get; set; } public IShapeFactory ShapeFactory { get; set; }
public dynamic New { get; set; }
public string ShapeType { get; set; } public string ShapeType { get; set; }
public dynamic Shape { get; set; } public dynamic Shape { get; set; }
} }
@@ -35,10 +37,15 @@ namespace Orchard.DisplayManagement.Implementation {
public class DefaultShapeFactory : IShapeFactory { public class DefaultShapeFactory : IShapeFactory {
private readonly IEnumerable<Lazy<IShapeFactoryEvents>> _events; private readonly IEnumerable<Lazy<IShapeFactoryEvents>> _events;
private readonly IShapeTableManager _shapeTableManager; 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; _events = events;
_shapeTableManager = shapeTableManager; _shapeTableManager = shapeTableManager;
_shapeHelperFactory = shapeHelperFactory;
} }
public IShape Create(string shapeType, INamedEnumerable<object> parameters) { public IShape Create(string shapeType, INamedEnumerable<object> parameters) {
@@ -47,6 +54,7 @@ namespace Orchard.DisplayManagement.Implementation {
defaultShapeTable.Descriptors.TryGetValue(shapeType, out shapeDescriptor); defaultShapeTable.Descriptors.TryGetValue(shapeType, out shapeDescriptor);
var creatingContext = new ShapeCreatingContext { var creatingContext = new ShapeCreatingContext {
New = _shapeHelperFactory.Value.CreateHelper(),
ShapeFactory=this, ShapeFactory=this,
ShapeType = shapeType, ShapeType = shapeType,
OnCreated = new List<Action<ShapeCreatedContext>>() OnCreated = new List<Action<ShapeCreatedContext>>()
@@ -93,7 +101,7 @@ namespace Orchard.DisplayManagement.Implementation {
// create the new instance // create the new instance
var createdContext = new ShapeCreatedContext { var createdContext = new ShapeCreatedContext {
ShapeFactory = this, New = creatingContext.New,
ShapeType = creatingContext.ShapeType, ShapeType = creatingContext.ShapeType,
Shape = ClayActivator.CreateInstance(creatingContext.BaseType, creatingContext.Behaviors) Shape = ClayActivator.CreateInstance(creatingContext.BaseType, creatingContext.Behaviors)
}; };