From d4122ed1924ad3755f4099a6bde28bdffb41ad83 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 19 Sep 2011 13:40:14 -0700 Subject: [PATCH] #17620: Refactoring how the Title is generated in Document shape Work Item: 17620 --HG-- branch : 1.x --- src/Orchard.Web/Core/Shapes/Views/Document.cshtml | 12 ++++-------- src/Orchard/Mvc/Html/LayoutExtensions.cs | 2 +- src/Orchard/UI/PageTitle/IPageTitleBuilder.cs | 15 +++++++++++++++ src/Orchard/UI/PageTitle/PageTitleBuilder.cs | 9 ++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Orchard.Web/Core/Shapes/Views/Document.cshtml b/src/Orchard.Web/Core/Shapes/Views/Document.cshtml index 6ebe88be2..0d299361d 100644 --- a/src/Orchard.Web/Core/Shapes/Views/Document.cshtml +++ b/src/Orchard.Web/Core/Shapes/Views/Document.cshtml @@ -2,20 +2,16 @@ @using Orchard.UI.Resources; @{ RegisterLink(new LinkEntry {Type = "image/x-icon", Rel = "shortcut icon", Href = Url.Content("~/modules/orchard.themes/Content/orchard.ico")}); - //todo: (heskew) get conditions (as in conditional comments) hooked up for script tags too - Script.Include("html5.js").AtLocation(ResourceLocation.Head); + Script.Include("html5.js").AtHead(); - //a bit opinionated - only the site name on the homepage - var title = (Request.Path.TrimEnd('/') != Request.ApplicationPath && HasText(Model.Title) - ? Model.Title + WorkContext.CurrentSite.PageTitleSeparator - : "") + - WorkContext.CurrentSite.SiteName; + string title = Model.Title; + string siteName = WorkContext.CurrentSite.SiteName; } - @title + @Html.Title(title, siteName) @Display(Model.Head) diff --git a/src/Orchard/Mvc/Html/LayoutExtensions.cs b/src/Orchard/Mvc/Html/LayoutExtensions.cs index 93f4de20f..5a157cd8f 100644 --- a/src/Orchard/Mvc/Html/LayoutExtensions.cs +++ b/src/Orchard/Mvc/Html/LayoutExtensions.cs @@ -34,7 +34,7 @@ namespace Orchard.Mvc.Html { public static MvcHtmlString Title(this HtmlHelper html, params string[] titleParts) { IPageTitleBuilder pageTitleBuilder = html.Resolve(); - html.AppendTitleParts(titleParts); + html.AddTitleParts(titleParts); return MvcHtmlString.Create(html.Encode(pageTitleBuilder.GenerateTitle())); } diff --git a/src/Orchard/UI/PageTitle/IPageTitleBuilder.cs b/src/Orchard/UI/PageTitle/IPageTitleBuilder.cs index 2cfafb08d..c73e43e92 100644 --- a/src/Orchard/UI/PageTitle/IPageTitleBuilder.cs +++ b/src/Orchard/UI/PageTitle/IPageTitleBuilder.cs @@ -1,7 +1,22 @@ namespace Orchard.UI.PageTitle { public interface IPageTitleBuilder : IDependency { + + /// + /// Adds some strings at the end of the title. + /// + /// A set of strings to add at the end of the title. void AddTitleParts(params string[] titleParts); + + /// + /// Inserts some strings at the beginning of the title. + /// + /// A set of strings to insert at the beginning of the title. void AppendTitleParts(params string[] titleParts); + + /// + /// Concatenates every title parts using the separator defined in settings. + /// + /// A string representing the aggregate title for the current page. string GenerateTitle(); } } \ No newline at end of file diff --git a/src/Orchard/UI/PageTitle/PageTitleBuilder.cs b/src/Orchard/UI/PageTitle/PageTitleBuilder.cs index 090e3377f..4dec1c58f 100644 --- a/src/Orchard/UI/PageTitle/PageTitleBuilder.cs +++ b/src/Orchard/UI/PageTitle/PageTitleBuilder.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using Orchard.Settings; @@ -15,21 +16,23 @@ namespace Orchard.UI.PageTitle { } public void AddTitleParts(params string[] titleParts) { - if (titleParts != null) + if (titleParts.Length > 0) foreach (string titlePart in titleParts) if (!string.IsNullOrEmpty(titlePart)) _titleParts.Add(titlePart); } public void AppendTitleParts(params string[] titleParts) { - if (titleParts != null) + if (titleParts.Length > 0) foreach (string titlePart in titleParts) if (!string.IsNullOrEmpty(titlePart)) _titleParts.Insert(0, titlePart); } public string GenerateTitle() { - return string.Join(_titleSeparator, _titleParts.AsEnumerable().Reverse().ToArray()); + return _titleParts.Count == 0 + ? String.Empty + : String.Join(_titleSeparator, _titleParts.AsEnumerable().Reverse().ToArray()); } } } \ No newline at end of file