2010-09-08 19:30:30 -07:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
2010-09-07 22:15:33 -07:00
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using System.Web.Mvc.Html;
|
|
|
|
|
|
using Orchard.DisplayManagement;
|
|
|
|
|
|
using Orchard.DisplayManagement.Descriptors;
|
2010-09-09 11:58:26 -07:00
|
|
|
|
using Orchard.DisplayManagement.Shapes;
|
2010-09-07 22:15:33 -07:00
|
|
|
|
using Orchard.Environment.Extensions.Models;
|
|
|
|
|
|
using Orchard.UI;
|
|
|
|
|
|
using Orchard.UI.Zones;
|
|
|
|
|
|
|
2010-09-08 19:30:30 -07:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
|
2010-09-07 22:15:33 -07:00
|
|
|
|
namespace Orchard.Core.Shapes {
|
|
|
|
|
|
public class CoreShapes : IShapeDescriptorBindingStrategy {
|
|
|
|
|
|
public Feature Feature { get; set; }
|
|
|
|
|
|
|
2010-09-08 19:30:30 -07:00
|
|
|
|
public void Discover(ShapeTableBuilder builder) {
|
2010-09-07 22:15:33 -07:00
|
|
|
|
// the root page shape named 'Layout' is wrapped with 'Document'
|
|
|
|
|
|
// and has an automatic zone creating behavior
|
|
|
|
|
|
builder.Describe.Named("Layout").From(Feature.Descriptor)
|
2010-09-09 11:58:26 -07:00
|
|
|
|
.Configure(descriptor => descriptor.Wrappers.Add("Document"))
|
2010-09-07 22:15:33 -07:00
|
|
|
|
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory)))
|
2010-09-09 11:58:26 -07:00
|
|
|
|
.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");
|
|
|
|
|
|
});
|
2010-09-07 22:15:33 -07:00
|
|
|
|
|
|
|
|
|
|
// 'Zone' shapes are built on the Zone base class
|
|
|
|
|
|
builder.Describe.Named("Zone").From(Feature.Descriptor)
|
|
|
|
|
|
.OnCreating(creating => creating.BaseType = typeof(Zone));
|
2010-09-08 19:30:30 -07:00
|
|
|
|
|
|
|
|
|
|
// 'List' shapes start with several empty collections
|
|
|
|
|
|
builder.Describe.Named("List").From(Feature.Descriptor)
|
|
|
|
|
|
.OnCreated(created => {
|
2010-09-09 11:58:26 -07:00
|
|
|
|
created.Shape.Tag = "ul";
|
2010-09-08 19:30:30 -07:00
|
|
|
|
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>();
|
|
|
|
|
|
});
|
2010-09-09 11:58:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
2010-09-07 22:15:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static object DetermineModel(HtmlHelper Html, object Model) {
|
|
|
|
|
|
bool isNull = ((dynamic)Model) == null;
|
|
|
|
|
|
return isNull ? Html.ViewData.Model : Model;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-09-08 19:30:30 -07:00
|
|
|
|
static TagBuilder GetTagBuilder(string tagName, string id, IEnumerable<string> classes, IDictionary<string, string> attributes) {
|
|
|
|
|
|
var tagBuilder = new TagBuilder(tagName);
|
|
|
|
|
|
tagBuilder.MergeAttributes(attributes, false);
|
|
|
|
|
|
foreach (var cssClass in classes ?? Enumerable.Empty<string>())
|
|
|
|
|
|
tagBuilder.AddCssClass(cssClass);
|
|
|
|
|
|
if (id != null)
|
|
|
|
|
|
tagBuilder.GenerateId(id);
|
|
|
|
|
|
return tagBuilder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Shape]
|
|
|
|
|
|
public void List(
|
|
|
|
|
|
dynamic Display,
|
|
|
|
|
|
TextWriter Output,
|
|
|
|
|
|
IEnumerable<dynamic> Items,
|
|
|
|
|
|
string Tag,
|
|
|
|
|
|
string Id,
|
|
|
|
|
|
IEnumerable<string> Classes,
|
|
|
|
|
|
IDictionary<string, string> Attributes,
|
|
|
|
|
|
IEnumerable<string> ItemClasses,
|
|
|
|
|
|
IDictionary<string, string> ItemAttributes) {
|
|
|
|
|
|
|
2010-09-09 11:58:26 -07:00
|
|
|
|
var listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
|
2010-09-08 19:30:30 -07:00
|
|
|
|
const string itemTagName = "li";
|
|
|
|
|
|
|
|
|
|
|
|
var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes);
|
|
|
|
|
|
Output.Write(listTag.ToString(TagRenderMode.StartTag));
|
|
|
|
|
|
|
|
|
|
|
|
if (Items != null) {
|
|
|
|
|
|
var count = Items.Count();
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
foreach (var item in Items) {
|
|
|
|
|
|
var itemTag = GetTagBuilder(itemTagName, null, ItemClasses, ItemAttributes);
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
|
itemTag.AddCssClass("first");
|
|
|
|
|
|
if (index == count - 1)
|
|
|
|
|
|
itemTag.AddCssClass("last");
|
|
|
|
|
|
Output.Write(itemTag.ToString(TagRenderMode.StartTag));
|
|
|
|
|
|
Output.Write(Display(item));
|
|
|
|
|
|
Output.Write(itemTag.ToString(TagRenderMode.EndTag));
|
|
|
|
|
|
++index;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Output.Write(listTag.ToString(TagRenderMode.EndTag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-09-09 11:58:26 -07:00
|
|
|
|
[Shape]
|
|
|
|
|
|
public IHtmlString PlaceChildContent(dynamic Source) {
|
|
|
|
|
|
return Source.Metadata.ChildContent;
|
|
|
|
|
|
}
|
2010-09-08 19:30:30 -07:00
|
|
|
|
|
2010-09-07 22:15:33 -07:00
|
|
|
|
[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));
|
|
|
|
|
|
}
|
2010-09-08 19:30:30 -07:00
|
|
|
|
|
2010-09-07 22:15:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|