mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Adding a "content-items" class name to the blog post list
--HG-- branch : dev
This commit is contained in:
@@ -5,10 +5,15 @@ using Orchard.Utility.Extensions;
|
|||||||
namespace Orchard.Tests.Utility.Extensions {
|
namespace Orchard.Tests.Utility.Extensions {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class StringExtensionsTests {
|
public class StringExtensionsTests {
|
||||||
|
[Test]
|
||||||
|
public void HtmlClassify_ValidReallySimpleClassNameReturnsSame() {
|
||||||
|
const string toClassify = "someclass";
|
||||||
|
Assert.That(toClassify.HtmlClassify(), Is.StringMatching(toClassify));
|
||||||
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void HtmlClassify_ValidSimpleClassNameReturnsSame() {
|
public void HtmlClassify_ValidSimpleClassNameReturnsSame() {
|
||||||
const string toClassify = "some-class";
|
const string toClassify = "some-class";
|
||||||
Assert.That(toClassify.HtmlClassify(), Is.StringMatching("some-class"));
|
Assert.That(toClassify.HtmlClassify(), Is.StringMatching(toClassify));
|
||||||
}
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void HtmlClassify_SimpleStringReturnsSimpleClassName() {
|
public void HtmlClassify_SimpleStringReturnsSimpleClassName() {
|
||||||
@@ -26,6 +31,16 @@ namespace Orchard.Tests.Utility.Extensions {
|
|||||||
Assert.That(toClassify.HtmlClassify(), Is.StringMatching(""));
|
Assert.That(toClassify.HtmlClassify(), Is.StringMatching(""));
|
||||||
}
|
}
|
||||||
[Test]
|
[Test]
|
||||||
|
public void HtmlClassify_LowerCamelCasedStringReturnsLowerHyphenatedClassName() {
|
||||||
|
const string toClassify = "camelCased";
|
||||||
|
Assert.That(toClassify.HtmlClassify(), Is.StringMatching("camel-cased"));
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void HtmlClassify_PascalCasedStringReturnsLowerHyphenatedClassName() {
|
||||||
|
const string toClassify = "PascalCased";
|
||||||
|
Assert.That(toClassify.HtmlClassify(), Is.StringMatching("pascal-cased"));
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
public void OrDefault_ReturnsDefaultForNull() {
|
public void OrDefault_ReturnsDefaultForNull() {
|
||||||
const string s = null;
|
const string s = null;
|
||||||
var def = new LocalizedString("test");
|
var def = new LocalizedString("test");
|
||||||
|
@@ -12,6 +12,7 @@ using Orchard.Settings;
|
|||||||
using Orchard.UI;
|
using Orchard.UI;
|
||||||
using Orchard.UI.Resources;
|
using Orchard.UI.Resources;
|
||||||
using Orchard.UI.Zones;
|
using Orchard.UI.Zones;
|
||||||
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
@@ -237,27 +238,29 @@ namespace Orchard.Core.Shapes {
|
|||||||
IEnumerable<string> ItemClasses,
|
IEnumerable<string> ItemClasses,
|
||||||
IDictionary<string, string> ItemAttributes) {
|
IDictionary<string, string> ItemAttributes) {
|
||||||
|
|
||||||
|
if (Items == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
|
var listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
|
||||||
const string itemTagName = "li";
|
const string itemTagName = "li";
|
||||||
|
|
||||||
var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes);
|
var listTag = GetTagBuilder(listTagName, Id, Classes, Attributes);
|
||||||
Output.Write(listTag.ToString(TagRenderMode.StartTag));
|
Output.Write(listTag.ToString(TagRenderMode.StartTag));
|
||||||
|
|
||||||
if (Items != null) {
|
var count = Items.Count();
|
||||||
var count = Items.Count();
|
var index = 0;
|
||||||
var index = 0;
|
foreach (var item in Items) {
|
||||||
foreach (var item in Items) {
|
var itemTag = GetTagBuilder(itemTagName, null, ItemClasses, ItemAttributes);
|
||||||
var itemTag = GetTagBuilder(itemTagName, null, ItemClasses, ItemAttributes);
|
if (index == 0)
|
||||||
if (index == 0)
|
itemTag.AddCssClass("first");
|
||||||
itemTag.AddCssClass("first");
|
if (index == count - 1)
|
||||||
if (index == count - 1)
|
itemTag.AddCssClass("last");
|
||||||
itemTag.AddCssClass("last");
|
Output.Write(itemTag.ToString(TagRenderMode.StartTag));
|
||||||
Output.Write(itemTag.ToString(TagRenderMode.StartTag));
|
Output.Write(Display(item));
|
||||||
Output.Write(Display(item));
|
Output.Write(itemTag.ToString(TagRenderMode.EndTag));
|
||||||
Output.Write(itemTag.ToString(TagRenderMode.EndTag));
|
++index;
|
||||||
++index;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Output.Write(listTag.ToString(TagRenderMode.EndTag));
|
Output.Write(listTag.ToString(TagRenderMode.EndTag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
@{
|
@{
|
||||||
IEnumerable<object> blogPosts = Model.ContentItems;
|
IEnumerable<object> blogPosts = Model.ContentItems;
|
||||||
|
Model.ContentItems.Classes.Add("content-items");
|
||||||
}
|
}
|
||||||
@Display(Model.ContentItems)
|
@Display(Model.ContentItems)
|
||||||
@if (blogPosts == null || blogPosts.Count() < 1) {
|
@if (blogPosts == null || blogPosts.Count() < 1) {
|
||||||
|
@@ -4,7 +4,7 @@ using Orchard.Localization;
|
|||||||
|
|
||||||
namespace Orchard.Utility.Extensions {
|
namespace Orchard.Utility.Extensions {
|
||||||
public static class StringExtensions {
|
public static class StringExtensions {
|
||||||
private static readonly Regex humps = new Regex("[A-Z][^A-Z]*");
|
private static readonly Regex humps = new Regex("(?:^[a-zA-Z][^A-Z]*|[A-Z][^A-Z]*)");
|
||||||
public static string CamelFriendly(this string camel) {
|
public static string CamelFriendly(this string camel) {
|
||||||
if (camel == null)
|
if (camel == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -29,7 +29,8 @@ namespace Orchard.Utility.Extensions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string HtmlClassify(this string text) {
|
public static string HtmlClassify(this string text) {
|
||||||
return Regex.Replace(text, @"[^a-zA-Z]+", m => m.Index == 0 ? "" : "-").ToLowerInvariant();
|
var friendlier = text.CamelFriendly();
|
||||||
|
return Regex.Replace(friendlier, @"[^a-zA-Z]+", m => m.Index == 0 ? "" : "-").ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNullOrEmptyTrimmed(this string text) {
|
public static bool IsNullOrEmptyTrimmed(this string text) {
|
||||||
|
Reference in New Issue
Block a user