private void WriteItem(TabStripItem item, IHtmlNode parentTag, ITabStripHtmlBuilder builder) { if (ItemAction != null) { ItemAction(item); } var accessible = true; if (this.SecurityTrimming) { accessible = item.IsAccessible(Authorization, ViewContext); } if (item.Visible && accessible) { IHtmlNode itemTag = builder.ItemTag(item).AppendTo(parentTag.Children[0]); builder.ItemInnerTag(item).AppendTo(itemTag); if (item.Template.HasValue() || item.ContentUrl.HasValue()) { builder.ItemContentTag(item).AppendTo(parentTag); } } }
public static TabStrip CreateTabStrip(HtmlTextWriter writer, ITabStripHtmlBuilder renderer) { Mock <HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext(); if (writer != null) { httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny <TextWriter>())).Returns(writer); } urlGenerator = new Mock <IUrlGenerator>(); authorization = new Mock <INavigationItemAuthorization>(); Mock <ITabStripHtmlBuilderFactory> tabStripRendererFactory = new Mock <ITabStripHtmlBuilderFactory>(); Mock <IViewDataContainer> viewDataContainer = new Mock <IViewDataContainer>(); var viewDataDinctionary = new ViewDataDictionary(); viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap()); viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary); Mock <IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock <IClientSideObjectWriterFactory>(); clientSideObjectWriter = new Mock <IClientSideObjectWriter>(); viewContext = TestHelper.CreateViewContext(); viewContext.ViewData = viewDataDinctionary; authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny <INavigatable>())).Returns(true); clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TextWriter>())).Returns(clientSideObjectWriter.Object); TabStrip tabStrip = new TabStrip(viewContext, clientSideObjectWriterFactory.Object, urlGenerator.Object, authorization.Object, tabStripRendererFactory.Object); renderer = renderer ?? new TabStripHtmlBuilder(tabStrip, new Mock <IActionMethodCache>().Object); tabStripRendererFactory.Setup(f => f.Create(It.IsAny <TabStrip>())).Returns(renderer); return(tabStrip); }
public static TabStrip CreateTabStrip(HtmlTextWriter writer, ITabStripHtmlBuilder renderer) { Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext(); if (writer != null) { httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(writer); } urlGenerator = new Mock<IUrlGenerator>(); authorization = new Mock<INavigationItemAuthorization>(); Mock<ITabStripHtmlBuilderFactory> tabStripRendererFactory = new Mock<ITabStripHtmlBuilderFactory>(); Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>(); var viewDataDinctionary = new ViewDataDictionary(); viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap()); viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary); Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>(); clientSideObjectWriter = new Mock<IClientSideObjectWriter>(); viewContext = TestHelper.CreateViewContext(); viewContext.ViewData = viewDataDinctionary; authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny<INavigatable>())).Returns(true); clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter.Object); TabStrip tabStrip = new TabStrip(viewContext, clientSideObjectWriterFactory.Object, urlGenerator.Object, authorization.Object, tabStripRendererFactory.Object); renderer = renderer ?? new TabStripHtmlBuilder(tabStrip, new Mock<IActionMethodCache>().Object); tabStripRendererFactory.Setup(f => f.Create(It.IsAny<TabStrip>())).Returns(renderer); return tabStrip; }
protected override void WriteHtml(HtmlTextWriter writer) { Guard.IsNotNull(writer, "writer"); if (Items.Any()) { ITabStripHtmlBuilder builder = builderFactory.Create(this); int itemIndex = 0; bool isPathHighlighted = false; IHtmlNode tabStripTag = builder.TabStripTag(); //this loop is required because of SelectedIndex feature. if (HighlightPath) { Items.Each(HighlightSelectedItem); } Items.Each(item => { if (!isPathHighlighted) { if (itemIndex == this.SelectedIndex) { item.Selected = true; } itemIndex++; } WriteItem(item, tabStripTag, builder); }); tabStripTag.WriteTo(writer); } base.WriteHtml(writer); }