private static string ResolveViewMasterPagePath(ViewMasterPage viewMasterPage, string path) { string cacheKey = string.Format(CultureInfo.InvariantCulture , "HtmlSnippetExtension.ResolveViewMasterPagePath.{0}" , viewMasterPage.AppRelativeVirtualPath ); string cachedPath = HttpRuntime.Cache[cacheKey] as string; if (cachedPath != null) { return(cachedPath); } if (!path.EndsWith(".snippet", StringComparison.InvariantCultureIgnoreCase)) { path += ".snippet"; } if (!path.StartsWith("/", StringComparison.InvariantCulture)) { string appRelativeVirtualPath = viewMasterPage.AppRelativeVirtualPath.TrimStart('~'); Match match = masterPagePathRegex.Match(appRelativeVirtualPath); if (match.Success) { appRelativeVirtualPath = match.Groups["path"].Value; } path = appRelativeVirtualPath + path; } HttpRuntime.Cache[cacheKey] = path; return(path); }
public static string GetMetadata(this ViewMasterPage viewMasterPage, string path) { string cacheKey = string.Format("MetadataExtension.ViewMasterPage.{0}.{1}" , viewMasterPage.AppRelativeVirtualPath , path ); string cachedPath = HttpRuntime.Cache[cacheKey] as string; if (cachedPath != null) { path = cachedPath; } else { if (hiddenPathRegex.IsMatch(path)) { string appRelativeVirtualPath = viewMasterPage.AppRelativeVirtualPath.TrimStart('~'); Match match = virtualPathRegex.Match(appRelativeVirtualPath); if (match.Success) { appRelativeVirtualPath = match.Groups["path"].Value; } string metadataPath = Regex.Replace(appRelativeVirtualPath , @"(\/[^\/]+)$" , delegate(Match m) { return(string.Format("/_{0}", Regex.Replace(m.ToString().TrimStart('/'), @"[^\w\-_]", "_", RegexOptions.Compiled))); } , RegexOptions.Compiled ); path = metadataPath + path; } HttpRuntime.Cache[cacheKey] = path; } return(Metadata.Get(path)); }
public static string ClientTemplate(this ViewMasterPage viewMasterPage, string path, string id, object config = null) { string output = string.Format(CultureInfo.InvariantCulture , "<script type=\"text/html\" id=\"{0}\">\n{1}\n</script>" , id.SafeHtmlEncode() , HtmlSnippet.Get(null, null, ResolveViewMasterPagePath(viewMasterPage, path), config) ); return(output); }
public static object GetModel(ViewMasterPage page) { var baseVM = page.Model as BaseVM; if (baseVM != null) { return(baseVM.MainModel); } return(page.Model); }
public void GetViewDataFromPageThrows() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); vmp.Page = new Page(); // Assert Assert.Throws <InvalidOperationException>( delegate { object foo = vmp.ViewData; }, "A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage<TModel>."); }
public void ViewBagProperty_ReflectsViewData() { // Arrange ViewPage page = new ViewPage(); ViewMasterPage masterPage = new ViewMasterPage(); masterPage.Page = page; masterPage.ViewData["A"] = 1; // Act & Assert Assert.NotNull(masterPage.ViewBag); Assert.Equal(1, masterPage.ViewBag.A); }
public void GetModelFromViewPage() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); ViewPage vp = new ViewPage(); vmp.Page = vp; object model = new object(); vp.ViewData = new ViewDataDictionary(model); // Assert Assert.AreEqual(model, vmp.Model); }
public void GetModelFromViewPageStronglyTyped() { // Arrange ViewMasterPage <FooModel> vmp = new ViewMasterPage <FooModel>(); ViewPage vp = new ViewPage(); vmp.Page = vp; FooModel model = new FooModel(); vp.ViewData = new ViewDataDictionary(model); // Assert Assert.AreEqual(model, vmp.Model); }
public void GetViewDataFromPageThrows() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); vmp.Page = new Page(); // Assert ExceptionHelper.ExpectException <InvalidOperationException>( delegate { object foo = vmp.ViewData; }, "A ViewMasterPage can only be used with content pages that derive from ViewPage or ViewPage<TViewItem>."); }
public void GetViewDataFromViewPage() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); ViewPage vp = new ViewPage(); vmp.Page = vp; vp.ViewData = new ViewDataDictionary { { "a", "123" }, { "b", "456" } }; // Assert Assert.AreEqual("123", vmp.ViewData.Eval("a")); Assert.AreEqual("456", vmp.ViewData.Eval("b")); }
public void GetUrlHelperFromViewPage() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); ViewPage vp = new ViewPage(); vmp.Page = vp; RequestContext rc = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData()); UrlHelper urlHelper = new UrlHelper(rc); vp.Url = urlHelper; // Assert Assert.AreEqual(vmp.Url, urlHelper); }
public void GetHtmlHelperFromViewPage() { // Arrange ViewMasterPage vmp = new ViewMasterPage(); ViewPage vp = new ViewPage(); vmp.Page = vp; ViewContext vc = new Mock <ViewContext>().Object; HtmlHelper htmlHelper = new HtmlHelper(vc, vp); vp.Html = htmlHelper; // Assert Assert.AreEqual(vmp.Html, htmlHelper); }
public void ViewBagProperty_PropagatesChangesToViewData() { // Arrange ViewPage page = new ViewPage(); ViewMasterPage masterPage = new ViewMasterPage(); masterPage.Page = page; masterPage.ViewData["A"] = 1; // Act masterPage.ViewBag.A = "foo"; masterPage.ViewBag.B = 2; // Assert Assert.Equal("foo", masterPage.ViewData["A"]); Assert.Equal(2, masterPage.ViewData["B"]); }
public void GetUrlHelper_returns_UrlHelper_from_ViewMasterPage() { var page = new ViewPage { ViewContext = new ViewContext(), ViewData = new ViewDataDictionary() }; page.InitHelpers(); var masterPage = new ViewMasterPage { Page = page }; var url = masterPage.Html.GetUrlHelper(); url.Should().BeSameAs(page.Url); }
public void GetWriterFromViewPage() { // Arrange bool triggered = false; HtmlTextWriter writer = new HtmlTextWriter(System.IO.TextWriter.Null); ViewMasterPage vmp = new ViewMasterPage(); MockViewPage vp = new MockViewPage(); vp.RenderCallback = delegate() { triggered = true; Assert.AreEqual(writer, vmp.Writer); }; vmp.Page = vp; // Act & Assert Assert.IsNull(vmp.Writer); vp.RenderControl(writer); Assert.IsNull(vmp.Writer); Assert.IsTrue(triggered); }
public static string BreadCrumbs(this ViewMasterPage page) { var view = page.ViewContext.View as WebFormView; if (view == null || page.Model == null) { return(null); } var currentMainMenu = MainMenu.GetAll() .FirstOrDefault(x => x.HasModel(Common.Logic.BreadCrumbs.GetModel(page))); var breadCrumbs = new BreadCrumbs(page, currentMainMenu).Get(); if (breadCrumbs.IsEmpty()) { return(null); } var sp = " "; var sep = sp + ">" + sp; return(breadCrumbs.JoinWith(sep) .Replace(sep + Common.Logic.BreadCrumbs.Separator + sep, sp + Common.Logic.BreadCrumbs.Separator + sp) .Remove(sep + Common.Logic.BreadCrumbs.Separator)); }
public static bool IsAdmin(this ViewMasterPage master) { return(HttpContext.Current.IsAdmin()); }
public static ScriptReferenceExpression SiteScript(this ViewMasterPage viewMasterPage, string url) { return(new ScriptReferenceExpression().Add(url)); }
public static void RenderWidgets(this ViewMasterPage pg, string zone) { RenderWidgets(pg.Page as ViewPage, zone); }
public static StyledButtonExpression StyledButtonFor(this ViewMasterPage viewPage, string name) { return(new StyledButtonExpression(name).ElementId(name)); }
public static KonaSite SiteData(this ViewMasterPage pg) { return(pg.ViewData["SiteData"] as KonaSite); }
public static void UserSummaryView(this ViewMasterPage pg) { pg.Html.RenderPartial(ThemeExtensions.TemplatedLink(pg.ViewContext, "UserSummaryDisplay")); }
public static string SiteRoot(this ViewMasterPage pg) { return(SiteRoot(pg.ViewContext.HttpContext)); }
public static LinkExpression SiteCSS(this ViewMasterPage viewMasterPage, string url) { return(new LinkExpression().Href(url).AsStyleSheet()); }
public static Customer CurrentCustomer(this ViewMasterPage pg) { return(CurrentCustomer(pg.Page as IViewDataContainer)); }
public static Page CurrentPage(this ViewMasterPage pg) { return(CurrentPage(pg.Page as ViewPage)); }
public static string Image(this HtmlHelper helper, ViewMasterPage pg, string fileName, string attributes) { return Image(helper, pg.SiteRoot(), fileName, attributes); }
public static string PopulateTemplate(this ViewMasterPage viewMasterPage, string path, object data = null, object config = null) { path = ResolveViewMasterPagePath(viewMasterPage, path); return(HtmlSnippet.Populate(null, null, path, data, config));; }
public BreadCrumbs(ViewMasterPage page, MainMenu mainMenu) { _mainMenu = mainMenu; _helper = page.Html; _model = GetModel(page); }
public static string Script(this HtmlHelper helper, ViewMasterPage pg, string viewDir, string fileName) { return Script(helper, pg.SiteRoot(), viewDir, fileName); }
public static string GetReturnUrl(this ViewMasterPage pg) { return(GetReturnUrl(pg.Page as ViewPage)); }
public static IList <Page> SitePages(this ViewMasterPage pg) { return(SitePages(pg.Page as ViewPage)); }
public static string CSS(this HtmlHelper helper, ViewMasterPage pg, string fileName) { return CSS(helper, pg.SiteRoot(), fileName); }