Blog pattern descriptors

--HG--
branch : autoroute
This commit is contained in:
randompete
2012-01-19 03:14:18 +00:00
parent 7aeb0ac658
commit 348d7a1fff
4 changed files with 81 additions and 65 deletions

View File

@@ -1,8 +1,8 @@
ffba6aa744a1153e5ba4324a5f8fe70da45b2bb8 src/Orchard.Web/Modules/Orchard.Alias
ce36031536b78ee9767801c720c142f3c515f2d0 src/Orchard.Web/Modules/Orchard.Autoroute
2f2f0961b1836c0813838c8d184f29041ca11175 src/Orchard.Web/Modules/Orchard.Autoroute
67bf9897ee9dd9483369aece729ad7c6f042941c src/Orchard.Web/Modules/Orchard.Forms
1d093e0b3327ecd5851a878e1eb6c64fbd683e05 src/Orchard.Web/Modules/Orchard.Projections
a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable
75b2107eb093154b35832e3ea6e8514d4a66426a src/Orchard.Web/Modules/Orchard.Rules
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
df77a7a8dbd846eb1f3af04a5ab4ca17ab0b8d9f src/Orchard.Web/Modules/Orchard.Tokens
28251b07a1c122ff34c0aa9c05cd8c8fce9b3c7a src/Orchard.Web/Modules/Orchard.Tokens

View File

@@ -57,7 +57,7 @@ namespace Orchard.Blogs.Handlers {
if (blogPost == null)
return;
// Note: DisplayRouteValues are simply inherited from CommonPart
// Note: DisplayRouteValues are still inherited from CommonPart. We shouldn't even need these overrides for admin routes. -PH
context.Metadata.CreateRouteValues = new RouteValueDictionary {
{"Area", "Orchard.Blogs"},

View File

@@ -135,6 +135,10 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
<Project>{66FCCD76-2761-47E3-8D11-B45D0001DDAA}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Placement.info">

View File

@@ -7,72 +7,84 @@ using System.Web.Routing;
using Orchard.ContentManagement;
using Orchard.Blogs.Models;
using Orchard.Core.Common.Models;
using Orchard.Autoroute.Services;
using Orchard.Localization;
namespace Orchard.Blogs.Routing {
public interface IRoutePatternProvider : IEventHandler {
void Routed(IContent content, String path, ICollection<Tuple<string, RouteValueDictionary>> aliases);
}
public class BlogAutoroutes : IRoutePatternProvider {
public void Routed(IContent content, string path, ICollection<Tuple<string, RouteValueDictionary>> aliases) {
// TODO: (PH:Autoroute) Cheap and it works. But could there be a better way?
if (content.Is<BlogPart>()) {
// Add RSD route
aliases.Add(Tuple.Create(
path + "/rsd",
new RouteValueDictionary {{"area", "Orchard.Blogs"},
{"controller", "RemoteBlogPublishing"},
{"action", "Rsd"},
{"blogId", content.Id}
}));
aliases.Add(Tuple.Create(
path + "/Archive",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", content.Id},
{"archiveData", ""}
}));
}
if (content.Is<BlogPostPart>()) {
var pathStart = "{Content.Container.Slug}/Archive/";
// Add Archives routes
var year = "{Content.Date.Format:yyyy}";
var month = "{Content.Date.Format:MM}";
var day = "{Content.Date.Format:dd}";
aliases.Add(Tuple.Create(
pathStart + String.Format("{0}", year),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", content.As<CommonPart>().Container.Id},
{"archiveData", String.Format("{0}",year)}
}));
aliases.Add(Tuple.Create(
pathStart + String.Format("{0}/{1}", year, month),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", content.As<CommonPart>().Container.Id},
{"archiveData", String.Format("{0}/{1}",year,month)}
}));
aliases.Add(Tuple.Create(
pathStart + String.Format("{0}/{1}/{2}", year, month, day),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", content.As<CommonPart>().Container.Id},
{"archiveData", String.Format("{0}/{1}/{2}",year,month,day)}
}));
}
public BlogAutoroutes() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
const string yearToken = "{Content.Date.Format:yyyy}";
const string monthToken = "{Content.Date.Format:MM}";
const string dayToken = "{Content.Date.Format:dd}";
const string idParentToken = "{Content.Container.Id}";
const string idToken = "{Content.Id}";
const string blogToken = "{Content.Slug}";
const string blogPostToken = "{Content.Container.Path}/{Content.Slug}";
public void Describe(DescribePatternContext describe) {
// TODO: (PH) Could implement RSD for non-blog content much more easily now the routing can be applied to any content item... (maybe need a RemotePublishingPart?)
// TODO: Must restrict these to appropriate parts/types...
describe.For("Content")
// .Where<IContent>(c => c.Is<BlogPart>())
.Pattern("Rsd", T("Remote Blog Publishing"), T("Remote Blog Publishing destination Url"),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "RemoteBlogPublishing"},
{"action", "Rsd"},
{"blogId", idToken}})
.Pattern("Archive", T("Blog Archives"), T("Displays a list of all blog archives"),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", idToken},
{"archiveData", ""}
})
;
describe.For("Content")
// .Where<IContent>(c => c.Is<BlogPostPart>())
.Pattern("ArchiveYear", T("Blog Archives by Year"), T("Displays a list of all blog archives for a particular year"),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", idParentToken},
{"archiveData", String.Format("{0}",yearToken)}
})
.Pattern("ArchiveMonth", T("Blog Archives by Month"), T("Displays a list of all blog archives for a particular year and month"),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", idParentToken},
{"archiveData", String.Format("{0}/{1}",yearToken,monthToken)}
})
.Pattern("ArchiveDay", T("Blog Archives by Day"), T("Displays a list of all blog archives for a particular date"),
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "ListByArchive"},
{"blogId", idParentToken},
{"archiveData", String.Format("{0}/{1}/{2}",yearToken,monthToken,dayToken)}
});
}
public void Suggest(SuggestPatternContext suggest) {
suggest.For("Content")
.Suggest("Rsd", "blog-title/rsd", blogToken + "/rsd", T("Rsd is a sub-path of the blog post"))
.Suggest("Archives", "blog-title/archives", blogToken + "/archives", T("Archives is a sub-path of the blog post"))
.Suggest("View", "blog-title", blogToken, T("Blog title"))
.Suggest("View", "blog-title/post-title", blogPostToken, T("Nested blog/post path"))
.Suggest("ArchivesYear", "blog-title/post-title/archives/yy", String.Format("{0}/archives/{1}",blogPostToken,yearToken), T("Archives year"))
.Suggest("ArchivesMonth", "blog-title/post-title/archives/yy/mm", String.Format("{0}/archives/{1}/{2}",blogPostToken,yearToken,monthToken), T("Archives year/month"))
.Suggest("ArchivesDay", "blog-title/post-title/archives/yy/mm/dd", String.Format("{0}/archives/{1}/{2}/{3}", blogPostToken, yearToken,monthToken,dayToken), T("Archives year/month/day"));
}
}
}