--HG--
branch : theming
This commit is contained in:
Sebastien Ros
2010-09-10 18:16:11 -07:00
8 changed files with 57 additions and 29 deletions

View File

@@ -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();
@@ -40,13 +41,19 @@ namespace Orchard.Core.Shapes {
builder.Describe.Named("List").From(Feature.Descriptor)
.OnCreated(created => {
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>();
});
}
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;
}

View File

@@ -1,3 +1,10 @@
<ul id="Menu-@Model.MenuName" class="Menu Menu-@Model.MenuName">
@DisplayChildren(Model)
</ul><!-- /Menu-@Model.MenuName -->
@{
// these should move somewhere else
Model.Id = "menu-" + Model.MenuName.ToLower();
Model.Classes.Add(Model.Id);
Model.Classes.Add("menu");
var tag = Html.Resolve<Orchard.DisplayManagement.Shapes.ITagBuilderFactory>().Create(Model, "ul");
}
@tag.StartElement
@DisplayChildren(Model)
@tag.EndElement <!-- /@Model.Id -->

View File

@@ -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<Orchard.DisplayManagement.Shapes.ITagBuilderFactory>().Create(Model, "div");
}
<div id="@id" class="Zone Zone-@Model.ZoneName">
@DisplayChildren(Model)
</div><!-- /@id -->
@tag.StartElement
@DisplayChildren(Model)
@tag.EndElement <!-- /@Model.Id -->

View File

@@ -310,9 +310,6 @@
<Content Include="Themes\TheAdmin\Styles\images\orchardLogo.gif" />
<Content Include="Themes\TheAdmin\Theme.png" />
<None Include="Themes\TheAdmin\Views\DumpShapeTable.cshtml" />
<None Include="Themes\TheAdmin\Views\MenuItem.cshtml" />
<None Include="Themes\TheAdmin\Views\Menu.cshtml" />
<None Include="Themes\TheAdmin\Views\Menu.ascx_" />
<Content Include="Themes\TheAdmin\Views\User.ascx" />
<Content Include="Themes\TheAdmin\Views\Header.ascx" />
<Content Include="Themes\Web.config" />

View File

@@ -1,3 +0,0 @@
<ul id="Menu-@Model.MenuName" class="Menu Menu-@Model.MenuName">
@DisplayChildren(Model)
</ul><!-- /Menu-@Model.MenuName -->

View File

@@ -1,9 +0,0 @@
@{
// odd formatting in this file is to cause more attractive results in the output.
var items = (IEnumerable<dynamic>)Enumerable.Cast<dynamic>(Model);
}
<li><a href="@Model.Href">@Model.Text</a>@{ if (items.Any()) {
<ul>
@DisplayChildren(Model)
</ul>}}
</li>

View File

@@ -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<string>())
tagBuilder.AddCssClass(cssClass);
if (!string.IsNullOrEmpty(shape.Id))
tagBuilder.GenerateId(shape.Id);
return tagBuilder;
}
}
}

View File

@@ -145,6 +145,7 @@
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptorAlterationBuilder.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeTable.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapeTableBuilder.cs" />
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
<Compile Include="Mvc\IOrchardViewPage.cs" />
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />