mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Added a page title builder and html helpers to build and display page title.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044209
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<title><%=Html.Title() %> - !!Safe Mode!!</title><%
|
<title><%=Html.Title("!!Safe Mode!!")%></title><%
|
||||||
Html.Zone("head", ":metas :styles :scripts"); %>
|
Html.Zone("head", ":metas :styles :scripts"); %>
|
||||||
</head>
|
</head>
|
||||||
<body><%
|
<body><%
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Mvc.ViewEngines;
|
using Orchard.Mvc.ViewEngines;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using Orchard.UI.PageTitle;
|
||||||
using Orchard.UI.Resources;
|
using Orchard.UI.Resources;
|
||||||
using Orchard.UI.Zones;
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
@@ -14,33 +15,36 @@ namespace Orchard.Mvc.Html {
|
|||||||
|
|
||||||
public static MvcHtmlString Body(this HtmlHelper html) {
|
public static MvcHtmlString Body(this HtmlHelper html) {
|
||||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
||||||
|
|
||||||
return MvcHtmlString.Create(layoutContext.BodyContent);
|
return MvcHtmlString.Create(layoutContext.BodyContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenderTitle(this HtmlHelper html) {
|
public static void AddTitleParts(this HtmlHelper html, params string[] titleParts) {
|
||||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
html.Resolve<IPageTitleBuilder>().AddTitleParts(titleParts);
|
||||||
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.Title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MvcHtmlString Title(this HtmlHelper html) {
|
public static MvcHtmlString Title(this HtmlHelper html, params string[] titleParts) {
|
||||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
IPageTitleBuilder pageTitleBuilder = html.Resolve<IPageTitleBuilder>();
|
||||||
return MvcHtmlString.Create(html.Encode(layoutContext.Title));
|
|
||||||
|
pageTitleBuilder.AddTitleParts(titleParts);
|
||||||
|
|
||||||
|
return MvcHtmlString.Create(pageTitleBuilder.GenerateTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : BaseViewModel {
|
||||||
//TODO: is IoC necessary for this to work properly?
|
IZoneManager manager = html.Resolve<IZoneManager>();
|
||||||
var manager = new ZoneManager();
|
|
||||||
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions);
|
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
||||||
Zone(html, zoneName, string.Empty);
|
html.Zone(zoneName, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, Action action) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, Action action) where TModel : BaseViewModel {
|
||||||
//TODO: again, IoC could move this AddAction (or similar) method out of the data-bearing object
|
//TODO: again, IoC could move this AddAction (or similar) method out of the data-bearing object
|
||||||
html.ViewData.Model.Zones.AddAction(zoneName, x => action());
|
html.ViewData.Model.Zones.AddAction(zoneName, x => action());
|
||||||
Zone(html, zoneName, string.Empty);
|
html.Zone(zoneName, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ZoneBody<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
public static void ZoneBody<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
||||||
|
@@ -5,7 +5,6 @@ namespace Orchard.Mvc.ViewEngines {
|
|||||||
public class OrchardLayoutContext {
|
public class OrchardLayoutContext {
|
||||||
private static readonly object _key = typeof(OrchardLayoutContext);
|
private static readonly object _key = typeof(OrchardLayoutContext);
|
||||||
|
|
||||||
public string Title { get; set; }
|
|
||||||
public string BodyContent { get; set; }
|
public string BodyContent { get; set; }
|
||||||
|
|
||||||
public static OrchardLayoutContext From(ControllerContext context) {
|
public static OrchardLayoutContext From(ControllerContext context) {
|
||||||
|
@@ -224,11 +224,14 @@
|
|||||||
<Compile Include="Mvc\ViewEngines\WebFormsViewEngineProvider.cs" />
|
<Compile Include="Mvc\ViewEngines\WebFormsViewEngineProvider.cs" />
|
||||||
<Compile Include="Mvc\ViewModels\AdminViewModel.cs" />
|
<Compile Include="Mvc\ViewModels\AdminViewModel.cs" />
|
||||||
<Compile Include="Mvc\ViewModels\BaseViewModel.cs" />
|
<Compile Include="Mvc\ViewModels\BaseViewModel.cs" />
|
||||||
|
<Compile Include="UI\PageTitle\IPageTitleBuilder.cs" />
|
||||||
|
<Compile Include="UI\PageTitle\PageTitleBuilder.cs" />
|
||||||
<Compile Include="UI\Resources\IResourceManager.cs" />
|
<Compile Include="UI\Resources\IResourceManager.cs" />
|
||||||
<Compile Include="UI\Resources\ResourceFilter.cs" />
|
<Compile Include="UI\Resources\ResourceFilter.cs" />
|
||||||
<Compile Include="UI\Resources\ResourceManager.cs" />
|
<Compile Include="UI\Resources\ResourceManager.cs" />
|
||||||
<Compile Include="UI\Zones\DelegateZoneItem.cs" />
|
<Compile Include="UI\Zones\DelegateZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
||||||
|
<Compile Include="UI\Zones\IZoneManager.cs" />
|
||||||
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
||||||
|
6
src/Orchard/UI/PageTitle/IPageTitleBuilder.cs
Normal file
6
src/Orchard/UI/PageTitle/IPageTitleBuilder.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Orchard.UI.PageTitle {
|
||||||
|
public interface IPageTitleBuilder : IDependency {
|
||||||
|
void AddTitleParts(params string[] titleParts);
|
||||||
|
string GenerateTitle();
|
||||||
|
}
|
||||||
|
}
|
25
src/Orchard/UI/PageTitle/PageTitleBuilder.cs
Normal file
25
src/Orchard/UI/PageTitle/PageTitleBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Orchard.UI.PageTitle {
|
||||||
|
public class PageTitleBuilder : IPageTitleBuilder {
|
||||||
|
private readonly List<string> _titleParts;
|
||||||
|
private readonly string _titleSeparator;
|
||||||
|
|
||||||
|
public PageTitleBuilder() {
|
||||||
|
_titleParts = new List<string>(5);
|
||||||
|
//TODO: (erikpo) Get this from a site setting
|
||||||
|
_titleSeparator = " - ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddTitleParts(params string[] titleParts) {
|
||||||
|
if (titleParts != null)
|
||||||
|
foreach (string titlePart in titleParts)
|
||||||
|
_titleParts.Add(titlePart);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GenerateTitle() {
|
||||||
|
return string.Join(_titleSeparator, _titleParts.AsEnumerable().Reverse().ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
src/Orchard/UI/Zones/IZoneManager.cs
Normal file
7
src/Orchard/UI/Zones/IZoneManager.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public interface IZoneManager : IDependency {
|
||||||
|
void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,11 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
|
||||||
namespace Orchard.UI.Zones {
|
namespace Orchard.UI.Zones {
|
||||||
public class ZoneManager {
|
public class ZoneManager : IZoneManager {
|
||||||
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions) {
|
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions) {
|
||||||
|
|
||||||
ZoneEntry zone;
|
ZoneEntry zone;
|
||||||
|
Reference in New Issue
Block a user