diff --git a/src/Orchard.Web/Core/Shapes/CoreShapes.cs b/src/Orchard.Web/Core/Shapes/CoreShapes.cs index d186e8a52..f9a9ba788 100644 --- a/src/Orchard.Web/Core/Shapes/CoreShapes.cs +++ b/src/Orchard.Web/Core/Shapes/CoreShapes.cs @@ -6,6 +6,7 @@ using System.Web.Mvc; using System.Web.Mvc.Html; using Orchard.DisplayManagement; using Orchard.DisplayManagement.Descriptors; +using Orchard.DisplayManagement.Implementation; using Orchard.Environment.Extensions.Models; using Orchard.UI; using Orchard.UI.Zones; @@ -21,7 +22,7 @@ namespace Orchard.Core.Shapes { // 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(name => creating.New.Zone()))) + .OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(name => CreateZone(creating, name)))) .OnCreated(created => { created.Shape.Head = created.New.DocumentZone(); created.Shape.Body = created.New.DocumentZone(); @@ -35,18 +36,24 @@ namespace Orchard.Core.Shapes { // 'Zone' shapes are built on the Zone base class builder.Describe.Named("Zone").From(Feature.Descriptor) .OnCreating(creating => creating.BaseType = typeof(Zone)); - + // 'List' shapes start with several empty collections builder.Describe.Named("List").From(Feature.Descriptor) .OnCreated(created => { created.Shape.Tag = "ul"; - created.Shape.Classes = new List(); - created.Shape.Attributes = new Dictionary(); created.Shape.ItemClasses = new List(); created.Shape.ItemAttributes = new Dictionary(); }); + } + private object CreateZone(ShapeCreatingContext context, string zoneName) { + var name = zoneName.ToLower(); + var zone = context.New.Zone(); + zone.Id = "zone-" + name; + zone.Classes.Add(zone.Id); + zone.Classes.Add("zone"); + return zone; } diff --git a/src/Orchard.Web/Core/Shapes/Views/Menu.cshtml b/src/Orchard.Web/Core/Shapes/Views/Menu.cshtml index d8393d562..d3178883a 100644 --- a/src/Orchard.Web/Core/Shapes/Views/Menu.cshtml +++ b/src/Orchard.Web/Core/Shapes/Views/Menu.cshtml @@ -1,3 +1,10 @@ - +@{ + // these should move somewhere else + Model.Id = "menu-" + Model.MenuName.ToLower(); + Model.Classes.Add(Model.Id); + Model.Classes.Add("menu"); + var tag = Html.Resolve().Create(Model, "ul"); +} +@tag.StartElement +@DisplayChildren(Model) +@tag.EndElement diff --git a/src/Orchard.Web/Core/Shapes/Views/Zone.cshtml b/src/Orchard.Web/Core/Shapes/Views/Zone.cshtml index b1441a0b4..00ac19431 100644 --- a/src/Orchard.Web/Core/Shapes/Views/Zone.cshtml +++ b/src/Orchard.Web/Core/Shapes/Views/Zone.cshtml @@ -1,9 +1,6 @@ @{ - var id = Model.Id; - if (id == null && Model.ZoneName != null) { - id = (Model.Parent.Id == null ? "" : Model.Parent.Id + "-") + "Zone-" + Model.ZoneName; - } + var tag = Html.Resolve().Create(Model, "div"); } -
- @DisplayChildren(Model) -
+@tag.StartElement +@DisplayChildren(Model) +@tag.EndElement diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index bf3bfff67..cae3f82bd 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -310,9 +310,6 @@ - - - diff --git a/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml b/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml deleted file mode 100644 index d8393d562..000000000 --- a/src/Orchard.Web/Themes/TheAdmin/Views/Menu.cshtml +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/src/Orchard.Web/Themes/TheAdmin/Views/MenuItem.cshtml b/src/Orchard.Web/Themes/TheAdmin/Views/MenuItem.cshtml deleted file mode 100644 index 77867458b..000000000 --- a/src/Orchard.Web/Themes/TheAdmin/Views/MenuItem.cshtml +++ /dev/null @@ -1,9 +0,0 @@ -@{ - // odd formatting in this file is to cause more attractive results in the output. - var items = (IEnumerable)Enumerable.Cast(Model); -} -
  • @Model.Text@{ if (items.Any()) { -
      - @DisplayChildren(Model) -
    }} -
  • diff --git a/src/Orchard/DisplayManagement/Shapes/ITagBuilderFactory.cs b/src/Orchard/DisplayManagement/Shapes/ITagBuilderFactory.cs new file mode 100644 index 000000000..f7aa79039 --- /dev/null +++ b/src/Orchard/DisplayManagement/Shapes/ITagBuilderFactory.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Mvc; + +namespace Orchard.DisplayManagement.Shapes { + public interface ITagBuilderFactory : IDependency { + TagBuilder Create(dynamic shape, string tagName); + } + + public class TagBuilder : System.Web.Mvc.TagBuilder { + public TagBuilder(string tagName) : base(tagName) { } + + public IHtmlString StartElement { get { return new HtmlString(ToString(TagRenderMode.StartTag)); } } + public IHtmlString EndElement { get { return new HtmlString(ToString(TagRenderMode.EndTag)); } } + } + + public class TagBuilderFactory : ITagBuilderFactory { + public TagBuilder Create(dynamic shape, string tagName) { + var tagBuilder = new TagBuilder(tagName); + tagBuilder.MergeAttributes(shape.Attributes, false); + foreach (var cssClass in shape.Classes ?? Enumerable.Empty()) + tagBuilder.AddCssClass(cssClass); + if (!string.IsNullOrEmpty(shape.Id)) + tagBuilder.GenerateId(shape.Id); + return tagBuilder; + } + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index e70b81b2f..0307c297b 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -145,6 +145,7 @@ +