Adding Capture method for WebForms

--HG--
branch : theming
This commit is contained in:
Sebastien Ros
2010-09-13 17:59:51 -07:00
parent 7642c09570
commit 5776c5ab58
2 changed files with 21 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using Autofac;
using Orchard.DisplayManagement;
using Orchard.Localization;
@@ -50,11 +51,29 @@ namespace Orchard.Mvc {
}
public IDisposable Capture(Action<IHtmlString> callback) {
throw new NotImplementedException();
return new ViewContextSubstitution(Writer, callback);
}
}
public class ViewContextSubstitution : IDisposable {
private readonly HtmlTextWriter _context;
private readonly Action<IHtmlString> _callback;
private readonly TextWriter _oldWriter;
private readonly TextWriter _writer;
public ViewContextSubstitution(HtmlTextWriter context, Action<IHtmlString> callback) {
_context = context;
_oldWriter = _context.InnerWriter;
_callback = callback;
_context.InnerWriter = _writer = new StringWriter();
}
public void Dispose() {
_callback(new HtmlString(_writer.ToString()));
_context.InnerWriter = _oldWriter;
}
}
public class ViewPage : ViewPage<dynamic> {
}
}

View File

@@ -53,7 +53,7 @@ namespace Orchard.Mvc {
}
public IDisposable Capture(Action<IHtmlString> callback) {
throw new NotImplementedException();
return new ViewContextSubstitution(Writer, callback);
}
}