mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
A little more MvcHtmlString/IHtmlString cleanup for the UnorderedList<T> HtmlHelper extensions
--HG-- branch : dev
This commit is contained in:
@@ -142,7 +142,7 @@ namespace Orchard.Tests.Mvc.Html {
|
||||
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
|
||||
|
||||
//act
|
||||
var result = html.UnorderedList((IEnumerable<string>)null, (a, b) => "", "test");
|
||||
var result = html.UnorderedList((IEnumerable<string>)null, (a, b) => MvcHtmlString.Create(""), "test");
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(string.Empty, result.ToString());
|
||||
@@ -156,7 +156,7 @@ namespace Orchard.Tests.Mvc.Html {
|
||||
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
|
||||
|
||||
//act
|
||||
var result = html.UnorderedList(new string[]{}, (a, b) => "", "test");
|
||||
var result = html.UnorderedList(new string[] { }, (a, b) => MvcHtmlString.Create(""), "test");
|
||||
|
||||
//assert
|
||||
Assert.AreEqual(string.Empty, result.ToString());
|
||||
|
@@ -4,6 +4,6 @@
|
||||
<div class="manage"><%: Html.ActionLink(T("Create new type").ToString(), "CreateType", null, new { @class = "button primaryAction" })%></div>
|
||||
<%=Html.UnorderedList(
|
||||
Model.Types,
|
||||
(t,i) => Html.DisplayFor(m => t).ToHtmlString(),
|
||||
(t,i) => Html.DisplayFor(m => t),
|
||||
"contentItems"
|
||||
) %>
|
@@ -6,7 +6,7 @@
|
||||
<h2><%:T("Cultures this site supports") %></h2>
|
||||
<%: Html.UnorderedList(
|
||||
Model.SiteCultures.OrderBy(s => s),
|
||||
(s, i) => Html.DisplayFor(scvm => s, s == Model.CurrentCulture ? "CurrentCulture" : "RemovableCulture", "").ToString(),
|
||||
(s, i) => Html.DisplayFor(scvm => s, s == Model.CurrentCulture ? "CurrentCulture" : "RemovableCulture", ""),
|
||||
"site-cultures", "culture", "odd")%>
|
||||
<% using (Html.BeginFormAntiForgeryPost("AddCulture")) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Orchard.Mvc.ViewUserControl<BlogArchivesViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<% Html.RegisterStyle("archives.css"); %>
|
||||
<% Html.RegisterFootScript("archives.js"); %>
|
||||
<div class="archives">
|
||||
@@ -23,13 +22,13 @@
|
||||
<li class="previous">
|
||||
<h4><%=year %> <span>(<%=yearMonths.Sum(ym => ym.Value) %>)</span></h4><%
|
||||
} %>
|
||||
<%: Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.Blog.Slug, t.Key.Year, t.Key.Month)).ToString(), "archiveMonthList") %>
|
||||
<%: Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.Blog.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") %>
|
||||
</li><%
|
||||
} %>
|
||||
</ul><%
|
||||
}
|
||||
else { %>
|
||||
<%: Html.UnorderedList(Model.Archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.Blog.Slug, t.Key.Year, t.Key.Month)).ToString(), "archiveMonthList") %><%
|
||||
<%: Html.UnorderedList(Model.Archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.Blog.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") %><%
|
||||
}
|
||||
}
|
||||
else { %>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogsViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%if (Model.Blogs.Count() > 0) { %>
|
||||
<%: Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayForItem(b).ToHtmlString(), "blogs contentItems") %><%
|
||||
<%: Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayForItem(b), "blogs contentItems") %><%
|
||||
}
|
||||
else { %>
|
||||
<p><%: T("No blogs found.") %></p><%
|
||||
|
@@ -20,7 +20,7 @@ if (Model.Entries.Count() > 0) { %>
|
||||
});
|
||||
|
||||
// Display the summary for the blog post
|
||||
return Html.DisplayForItem(entry.ContentItemViewModel).ToHtmlString();
|
||||
return Html.DisplayForItem(entry.ContentItemViewModel);
|
||||
}, "blogs contentItems")%><%
|
||||
} else { %>
|
||||
<div class="info message"><%:T("There are no blogs for you to see. Want to <a href=\"{0}\">add one</a>?", Url.BlogCreate())%></div><%
|
||||
|
@@ -11,4 +11,4 @@
|
||||
%>
|
||||
</div>
|
||||
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c).ToHtmlString(), "blogPosts contentItems")%>
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c), "blogPosts contentItems")%>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<ContentItemViewModel<BlogPost>>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "blogPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
|
||||
<% if (Model.Count() < 1) { %><div class="info message"><%: T("There are no posts for this blog.") %></div><% } %>
|
||||
|
@@ -44,7 +44,7 @@
|
||||
<h4><%: T("Depends on:")%></h4>
|
||||
<%: Html.UnorderedList(
|
||||
feature.Descriptor.Dependencies.OrderBy(s => s),
|
||||
(s, i) => Html.Link(s, string.Format("#{0}", s.AsFeatureId(n => T(n)))).ToString(),
|
||||
(s, i) => Html.Link(s, string.Format("#{0}", s.AsFeatureId(n => T(n)))),
|
||||
"",
|
||||
"dependency",
|
||||
"") %>
|
||||
|
@@ -2,4 +2,4 @@
|
||||
<%@ Import Namespace="Orchard.Sandbox.ViewModels" %>
|
||||
<h1><%: Html.TitleForPage(T("Sandbox Pages").ToString()) %></h1>
|
||||
<p><%: Html.ActionLink(T("Add new page").ToString(), "create") %></p>
|
||||
<%: Html.UnorderedList(Model.Pages, (sp, i) => Html.DisplayForItem(sp).ToHtmlString(), "pages contentItems") %>
|
||||
<%: Html.UnorderedList(Model.Pages, (sp, i) => Html.DisplayForItem(sp), "pages contentItems") %>
|
||||
|
@@ -12,6 +12,6 @@ if (!string.IsNullOrWhiteSpace(Model.Query)) {
|
||||
}
|
||||
}
|
||||
if (Model.PageOfResults != null && Model.PageOfResults.Count() > 0) { %>
|
||||
<%=Html.UnorderedList(Model.PageOfResults, (r, i) => Html.DisplayForItem(r.Content).ToHtmlString() , "search-results contentItems") %>
|
||||
<%=Html.UnorderedList(Model.PageOfResults, (r, i) => Html.DisplayForItem(r.Content) , "search-results contentItems") %>
|
||||
<%=Html.Pager(Model.PageOfResults, Model.PageOfResults.PageNumber, Model.DefaultPageSize, new {q = Model.Query}) %><%
|
||||
} %>
|
@@ -8,6 +8,6 @@
|
||||
"Search",
|
||||
new { tagName = t.TagName },
|
||||
new { @class = "" /* todo: (heskew) classify according to tag use */ }
|
||||
).ToHtmlString(),
|
||||
),
|
||||
"tagCloud")
|
||||
%>
|
@@ -2,4 +2,4 @@
|
||||
<%@ Import Namespace="Orchard.Tags.ViewModels"%>
|
||||
<% Html.AddTitleParts(T("Tags").ToString(), T("Contents tagged with {0}", Model.TagName).ToString()); %>
|
||||
<h1 class="page-title"><%: T("Contents tagged with <span>{0}</span>", Html.Encode(Model.TagName)) %></h1>
|
||||
<%: Html.UnorderedList(Model.Items, (c, i) => Html.DisplayForItem(c).ToHtmlString(), "taggedPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model.Items, (c, i) => Html.DisplayForItem(c), "taggedPosts contentItems") %>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<ContentItemViewModel<BlogPost>>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "blogPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
|
||||
<% if (Model.Count() < 1) { %><p><%: T("There are no posts for this blog.") %></p><% } %>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<ContentItemViewModel<BlogPost>>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "blogPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
|
||||
<% if (Model.Count() < 1) { %><p><%: T("There are no posts for this blog.") %></p><% } %>
|
||||
|
@@ -11,4 +11,4 @@
|
||||
%>
|
||||
</div>
|
||||
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c).ToHtmlString(), "blogPosts contentItems")%>
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c), "blogPosts contentItems")%>
|
||||
|
@@ -2,5 +2,5 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "blogPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
|
||||
<% if (Model.Count() < 1) { %><p><%: T("There are no posts for this blog.") %></p><% } %>
|
||||
|
@@ -7,7 +7,7 @@ foreach (var comment in Model) { %>
|
||||
<p><%: comment.Record.CommentText %></p>
|
||||
</div>
|
||||
<div class="commentauthor">
|
||||
<span class="who"><%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%></span> <span>said <%: Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
|
||||
<span class="who"><%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%></span> <span>said <%: Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).ToString(), "#")%></span>
|
||||
</div>
|
||||
</li><%
|
||||
} %>
|
||||
|
@@ -11,4 +11,4 @@
|
||||
%>
|
||||
</div>
|
||||
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c).ToHtmlString(), "blogPosts contentItems")%>
|
||||
<%: Html.UnorderedList(Model.BlogPosts, (c, i) => Html.DisplayForItem(c), "blogPosts contentItems")%>
|
||||
|
@@ -2,5 +2,5 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "blogPosts contentItems") %>
|
||||
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
|
||||
<% if (Model.Count() < 1) { %><p><%: T("There are no posts for this blog.") %></p><% } %>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Orchard.Mvc.ViewUserControl<BlogArchivesViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<% Html.RegisterStyle("archives.css"); %>
|
||||
<% Html.RegisterFootScript("archives.js"); %>
|
||||
<div class="archives">
|
||||
|
@@ -121,15 +121,23 @@ namespace Orchard.Mvc.Html {
|
||||
|
||||
#region UnorderedList
|
||||
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, string> generateContent, string cssClass) {
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, MvcHtmlString> generateContent, string cssClass) {
|
||||
return htmlHelper.UnorderedList(items, generateContent, cssClass, null, null);
|
||||
}
|
||||
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, string> generateContent, string cssClass, string itemCssClass, string alternatingItemCssClass) {
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, MvcHtmlString> generateContent, string cssClass, string itemCssClass, string alternatingItemCssClass) {
|
||||
return UnorderedList(items, (t, i) => generateContent(t, i) as IHtmlString, cssClass, t => itemCssClass, t => alternatingItemCssClass);
|
||||
}
|
||||
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, IHtmlString> generateContent, string cssClass) {
|
||||
return htmlHelper.UnorderedList(items, generateContent, cssClass, null, null);
|
||||
}
|
||||
|
||||
public static IHtmlString UnorderedList<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, Func<T, int, IHtmlString> generateContent, string cssClass, string itemCssClass, string alternatingItemCssClass) {
|
||||
return UnorderedList(items, generateContent, cssClass, t => itemCssClass, t => alternatingItemCssClass);
|
||||
}
|
||||
|
||||
private static IHtmlString UnorderedList<T>(IEnumerable<T> items, Func<T, int, string> generateContent, string cssClass, Func<T, string> generateItemCssClass, Func<T, string> generateAlternatingItemCssClass) {
|
||||
private static IHtmlString UnorderedList<T>(IEnumerable<T> items, Func<T, int, IHtmlString> generateContent, string cssClass, Func<T, string> generateItemCssClass, Func<T, string> generateAlternatingItemCssClass) {
|
||||
if (items == null || !items.Any()) return new HtmlString(string.Empty);
|
||||
|
||||
var sb = new StringBuilder(250);
|
||||
|
Reference in New Issue
Block a user