Make PublishedDate and PublishedWhen shape methods

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-10-18 17:36:42 -07:00
parent 1bda590fda
commit 6789347981
7 changed files with 23 additions and 12 deletions

View File

@@ -1,15 +1,26 @@
using System; using System;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.Html; using Orchard.Mvc.Html;
namespace Orchard.Core.Common.Extensions { namespace Orchard.Core.Common.Extensions {
public static class HtmlHelperExtensions { public class Shapes {
public static LocalizedString PublishedState(this HtmlHelper htmlHelper, DateTime? versionPublishedUtc, Localizer T) { public Shapes() {
return htmlHelper.DateTime(versionPublishedUtc, T("Draft")); T = NullLocalizer.Instance;
} }
public static LocalizedString PublishedWhen(this HtmlHelper htmlHelper, DateTime? versionPublishedUtc, Localizer T) {
return htmlHelper.DateTimeRelative(versionPublishedUtc, T("as a Draft"), T); public Localizer T { get; set; }
[Shape]
public IHtmlString PublishedState(HtmlHelper Html, DateTime? versionPublishedUtc) {
return Html.DateTime(versionPublishedUtc, T("Draft"));
}
[Shape]
public IHtmlString PublishedWhen(dynamic Display, HtmlHelper Html, DateTime? versionPublishedUtc) {
return Display.DateTimeRelative(dateTime: versionPublishedUtc, defaultIfNull: T("as a Draft"));
} }
} }
} }

View File

@@ -1,2 +1,2 @@
@using Orchard.Core.Common.Extensions; @using Orchard.Core.Common.Extensions;
<div class="published">@Html.PublishedState((DateTime?)Model.ContentPart.VersionPublishedUtc, T)</div> <div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>

View File

@@ -1,2 +1,2 @@
@using Orchard.Core.Common.Extensions; @using Orchard.Core.Common.Extensions;
<div class="published">@Html.PublishedState((DateTime?)Model.ContentPart.VersionPublishedUtc, T)</div> <div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>

View File

@@ -3,5 +3,5 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<% <%
if (Model.Creator != null) { if (Model.Creator != null) {
%><%=_Encoded(" | Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model)) %><% %><%=_Encoded(" | Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(versionPublishedUtc: Model))%><%
} %> } %>

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Core.Common.Extensions" %> <%@ Import Namespace="Orchard.Core.Common.Extensions" %>
<h3><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h3> <h3><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h3>
<div class="meta"><%: Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div> <div class="meta"><%: Display.PublishedState(versionPublishedUtc: Model.Item)%> | <%Html.Zone("meta");%></div>
<div class="postsummary"> <div class="postsummary">
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
</div> </div>

View File

@@ -3,5 +3,5 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><% <%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
if (Model.Creator != null) { if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><% %><%: T("Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(versionPublishedUtc: Model))%><%
} %> } %>

View File

@@ -8,7 +8,7 @@
<!-- TODO: Meta should be it's own shape and not part of the blog summary view. Theme authors will need access to it. --> <!-- TODO: Meta should be it's own shape and not part of the blog summary view. Theme authors will need access to it. -->
<div class="meta"> <div class="meta">
@Html.PublishedState(new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart))), T) @Display.PublishedState(versionPublishedUtc: new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart))))
@Display(Model.meta) @Display(Model.meta)
</div> </div>