Created
August 24, 2012 16:03
-
-
Save prabirshrestha/3452319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // goal to use this in both nancy and mvc | |
| @Html.Universal().PagedList(); | |
| // UnivesalHtmlHelper.dll | |
| public inteface IUniversalHtmlStringFactory { | |
| IUniversalHtmlString Create(string str); | |
| } | |
| public interface IUniversalHtmlString { | |
| string ToHtmlString(); | |
| } | |
| public class UniversalHtmlHelper { | |
| // set this to in bootstrapper in nancy or global.asax in mvc | |
| public static IUniversalHtmlStringFactory DefaultFactory { get; set; } | |
| // store stufs like httpcontext/nancycontext? you might want to add other properties too. | |
| // like url | |
| public object State {get;set;} | |
| } | |
| // Universal.PagdList.dll | |
| public static class Universal { | |
| public static IUniversalHtmlString PagedList(this UniversalHtmlHelper htmlHelper) { | |
| var html = "<li></li>"; | |
| return UniversalHtmlHelper.DefaultFactory.Create(html); | |
| } | |
| } | |
| // Universal.Providers.Mvc.dll | |
| public class UniversalHtmlStringToMvc : IUniversalHtlmString, IHtmlString { | |
| string str; | |
| public UniversalHtmlStringToMvc(string str) { | |
| this.str = new MvcHtmlString(str).ToString(); | |
| } | |
| public string ToHtmlString() { | |
| return this.str; | |
| } | |
| } | |
| public static MvcHtlmHelperExtesions { | |
| public static UniversalHtmlHelper Universal(this HtmlHelper htmlhelper) { | |
| return new UniversalHtmlHelper() { Stats = htmlhelper.HttpContext; | |
| } | |
| } | |
| // Universal.Providers.Nancy.dll | |
| public class UniversalHtmlStringToNancy: IUniversalHtlmString, INancyHtmlString { | |
| string str; | |
| public UniversalHtmlStringToMvc(string str) { | |
| this.str = new NancyHtmlString(str).ToString(); | |
| } | |
| public string ToHtmlString() { | |
| return this.str; | |
| } | |
| } | |
| public static NancyHtlmHelperExtesions { | |
| public static UniversalHtmlHelper Universal(this HtmlHelper htmlhelper) { | |
| return new UniversalHtmlHelper() { Stats = htmlhelper.NancyContext; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment