Converting local navs to a new core shape (AKA making louis happy :))

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2011-02-11 14:13:38 -08:00
parent 042968453b
commit 14a7ada113
10 changed files with 118 additions and 14 deletions

View File

@@ -372,6 +372,12 @@
<ItemGroup>
<Content Include="Shapes\Views\ShapeResult\Display.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Shapes\Views\LocalMenu.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Shapes\Views\LocalMenuItem.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -85,6 +85,22 @@ namespace Orchard.Core.Shapes {
menuItem.Metadata.Alternates.Add("MenuItem__" + menu.MenuName);
});
builder.Describe("LocalMenu")
.OnDisplaying(displaying => {
var menu = displaying.Shape;
string menuName = menu.MenuName;
menu.Classes.Add("localmenu-" + menuName.HtmlClassify());
menu.Classes.Add("localmenu");
menu.Metadata.Alternates.Add("LocalMenu__" + menuName);
});
builder.Describe("LocalMenuItem")
.OnDisplaying(displaying => {
var menuItem = displaying.Shape;
var menu = menuItem.Menu;
menuItem.Metadata.Alternates.Add("LocalMenuItem__" + menu.MenuName);
});
// 'List' shapes start with several empty collections
builder.Describe("List")
.OnCreated(created => {

View File

@@ -0,0 +1,10 @@
@{
// Model is Model.Menu from the layout (Layout.Menu)
var tag = Tag(Model, "ul");
}
<nav>
@tag.StartElement
@* see MenuItem shape template *@
@DisplayChildren(Model)
@tag.EndElement
</nav>

View File

@@ -0,0 +1,22 @@
@{
// odd formatting in this file is to cause more attractive results in the output.
var items = (IEnumerable<dynamic>)Enumerable.Cast<dynamic>(Model);
}
@{
if (!HasText(Model.Text)) {
@DisplayChildren(Model)
} else {
if (Model.Href.TrimEnd('/').ToUpperInvariant() == Request.Path.TrimEnd('/').ToUpperInvariant()) {
Model.Classes.Add("current");
}
var tag = Tag(Model, "li");
@tag.StartElement
<a href="@Model.Href">@Model.Text</a>
if (items.Any()) {
<ul>
@DisplayChildren(Model)
</ul>
}
@tag.EndElement
}
}