- LiveWriter manifest action, register arbitrary links via resourcemanager, more lw work...

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-03-02 11:11:22 -08:00
parent bcce1c3a6c
commit 388bd803c6
13 changed files with 110 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ namespace Orchard.Core.Feeds.Services {
var sb = new StringBuilder();
foreach (var link in _links) {
var linkUrl = urlHelper.RouteUrl(link.RouteValues);
sb.Append("\r\n");
sb.Append(@"<link rel=""alternate"" type=""application/rss+xml""");
if (!string.IsNullOrEmpty(link.Title)) {
sb

View File

@@ -1,10 +1,13 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.Core.Feeds;
using Orchard.Logging;
using Orchard.Mvc.Results;
namespace Orchard.Blogs.Controllers {
@@ -20,8 +23,11 @@ namespace Orchard.Blogs.Controllers {
_services = services;
_blogService = blogService;
_feedManager = feedManager;
Logger = NullLogger.Instance;
}
protected ILogger Logger { get; set; }
public ActionResult List() {
var model = new BlogsViewModel {
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary"))
@@ -45,5 +51,23 @@ namespace Orchard.Blogs.Controllers {
return View(model);
}
public ActionResult LiveWriterManifest() {
Logger.Debug("Live Writer Manifest requested");
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
var options = new XElement(
XName.Get("options", manifestUri),
new XElement(XName.Get("clientType", manifestUri), "Metaweblog"),
new XElement(XName.Get("supportsSlug", manifestUri), "Yes"));
var doc = new XDocument(new XElement(
XName.Get("manifest", manifestUri),
options));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
return Content(doc.ToString(), "text/xml");
}
}
}

View File

@@ -14,6 +14,10 @@ namespace Orchard.Blogs.Extensions {
return urlHelper.Action("Item", "Blog", new {blogSlug, area = "Orchard.Blogs"});
}
public static string BlogLiveWriterManifest(this UrlHelper urlHelper, string blogSlug) {
return urlHelper.Action("LiveWriterManifest", "Blog", new { blogSlug, area = "Orchard.Blogs" });
}
public static string BlogArchiveYear(this UrlHelper urlHelper, string blogSlug, int year) {
return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug, archiveData = year.ToString(), area = "Orchard.Blogs" });
}

View File

@@ -192,6 +192,22 @@ namespace Orchard.Blogs {
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"{blogSlug}/wlwmanifest.xml",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "Blog"},
{"action", "LiveWriterManifest"}
},
new RouteValueDictionary {
{"blogSlug", new IsBlogConstraint(_containerProvider)}
},
new RouteValueDictionary {
{"area", "Orchard.Blogs"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"{blogSlug}/{postSlug}",

View File

@@ -1,6 +1,9 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Blog>>" %>
<%@ Import Namespace="Orchard.UI.Resources"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h1><%=Html.TitleForPage(Model.Item.Name) %></h1>
<% Html.RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest(Model.Item.Slug) });%>
<% Html.Zone("primary", ":manage :metadata");
Html.ZonesAny(); %>

View File

@@ -1,7 +1,9 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Blog>>" %>
<%@ Import Namespace="Orchard.UI.Resources"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.TitleForPage(Model.Item.Name) %></h2>
<% Html.RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest(Model.Item.Slug) });%>
<% Html.Zone("primary", ":manage :metadata");
Html.ZonesAny(); %>

View File

@@ -1,6 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Blog>>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.UI.Resources"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<% Html.RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest(Model.Item.Slug) });%>
<div class="bloginfo">
<h1><%=Html.TitleForPage(Model.Item.Name) %></h1>
</div>

View File

@@ -94,6 +94,10 @@ namespace Orchard.Mvc.Html {
html.Resolve<IResourceManager>().RegisterMeta(name, content);
}
public static void RegisterLink(this HtmlHelper html, LinkEntry entry) {
html.Resolve<IResourceManager>().RegisterLink(entry, html);
}
public static void RegisterStyle(this HtmlHelper html, string fileName) {
html.Resolve<IResourceManager>().RegisterStyle(fileName, html);
}

View File

@@ -300,6 +300,7 @@
<Compile Include="UI\PageTitle\IPageTitleBuilder.cs" />
<Compile Include="UI\PageTitle\PageTitleBuilder.cs" />
<Compile Include="UI\Resources\IResourceManager.cs" />
<Compile Include="UI\Resources\LinkEntry.cs" />
<Compile Include="UI\Resources\ResourceFilter.cs" />
<Compile Include="UI\Resources\ResourceManager.cs" />
<Compile Include="UI\Zones\DelegateZoneItem.cs" />

View File

@@ -1,14 +1,15 @@
using System.Web.Mvc;
using System.Web.Routing;
namespace Orchard.UI.Resources {
public interface IResourceManager : IDependency {
void RegisterMeta(string name, string content);
void RegisterStyle(string fileName, HtmlHelper html);
void RegisterLink(LinkEntry entry, HtmlHelper html);
void RegisterHeadScript(string fileName, HtmlHelper html);
void RegisterFootScript(string fileName, HtmlHelper html);
MvcHtmlString GetMetas();
MvcHtmlString GetStyles();
MvcHtmlString GetLinks(HtmlHelper html);
MvcHtmlString GetHeadScripts();
MvcHtmlString GetFootScripts();
}

View File

@@ -0,0 +1,7 @@
namespace Orchard.UI.Resources {
public class LinkEntry {
public string Rel { get; set; }
public string Type { get; set; }
public string Href { get; set; }
}
}

View File

@@ -20,6 +20,7 @@ namespace Orchard.UI.Resources {
model.Zones.AddAction("head:metas", html => html.ViewContext.Writer.Write(_resourceManager.GetMetas()));
model.Zones.AddAction("head:styles", html => html.ViewContext.Writer.Write(_resourceManager.GetStyles()));
model.Zones.AddAction("head:links", html => html.ViewContext.Writer.Write(_resourceManager.GetLinks(html)));
model.Zones.AddAction("head:scripts", html => html.ViewContext.Writer.Write(_resourceManager.GetHeadScripts()));
model.Zones.AddAction("body:after", html => {
html.ViewContext.Writer.Write(_resourceManager.GetFootScripts());

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Mvc.Html;
@@ -12,12 +13,14 @@ namespace Orchard.UI.Resources {
private const string ScriptFormat = "\r\n<script type=\"text/javascript\" src=\"{0}\"></script>";
private readonly Dictionary<string, string> _metas;
private readonly List<FileRegistrationContext> _styles;
private readonly List<LinkEntry> _links;
private readonly List<FileRegistrationContext> _headScripts;
private readonly List<FileRegistrationContext> _footScripts;
public ResourceManager() {
_metas = new Dictionary<string, string>(20) {{"generator", "Orchard"}};
_styles = new List<FileRegistrationContext>(10);
_links = new List<LinkEntry>();
_headScripts = new List<FileRegistrationContext>(10);
_footScripts = new List<FileRegistrationContext>(5);
}
@@ -37,6 +40,10 @@ namespace Orchard.UI.Resources {
_styles.Add(context);
}
public void RegisterLink(LinkEntry entry, HtmlHelper html) {
_links.Add(entry);
}
public void RegisterHeadScript(string fileName, HtmlHelper html) {
if (string.IsNullOrEmpty(fileName))
return;
@@ -67,6 +74,40 @@ namespace Orchard.UI.Resources {
return GetFiles(_styles, StyleFormat, "/styles/");
}
public MvcHtmlString GetLinks(HtmlHelper html) {
var sb = new StringBuilder();
foreach (var link in _links) {
sb.Append("\r\n");
sb.Append(@"<link");
if (!string.IsNullOrEmpty(link.Rel)) {
sb
.Append(@" rel=""")
.Append(html.AttributeEncode(link.Rel))
.Append(@"""");
}
if (!string.IsNullOrEmpty(link.Type)) {
sb
.Append(@" type=""")
.Append(html.AttributeEncode(link.Type))
.Append(@"""");
}
if (!string.IsNullOrEmpty(link.Href)) {
sb
.Append(@" href=""")
.Append(@"http://localhost:30320")
.Append(html.AttributeEncode(link.Href))
.Append(@"""");
}
sb.Append(@" />");
}
return MvcHtmlString.Create(sb.ToString());
}
public MvcHtmlString GetHeadScripts() {
return GetFiles(_headScripts, ScriptFormat, "/scripts/");
}