public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var childContent = await output.GetChildContentAsync(); var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)]; modalContext.Body = childContent; output.SuppressOutput(); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (!Condition) { output.SuppressOutput(); } }
/// <inheritdoc /> public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } IHtmlContent content = null; // Create a cancellation token that will be used // to release the task from the memory cache. var tokenSource = new CancellationTokenSource(); if (Enabled) { var cacheKey = new CacheTagKey(this); content = await _distributedCacheService.ProcessContentAsync(output, cacheKey, GetDistributedCacheEntryOptions()); } else { content = await output.GetChildContentAsync(); } // Clear the contents of the "cache" element since we don't want to render it. output.SuppressOutput(); output.Content.SetHtmlContent(content); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (ShowIfNull != null) { output.SuppressOutput(); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { // If a condition is set and evaluates to false, don't render the tag. if (Condition.HasValue && !Condition.Value) { output.SuppressOutput(); } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var content = await output.GetChildContentAsync(); var collectionContext = (InputCollectionContext)context.Items[typeof(InputCollectionTagHelper)]; var localContext = new InputCollectionItemContext() { Label = Label, Content = content }; collectionContext.Items.Add(localContext); output.SuppressOutput(); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = null; if (Authorization == null) return; Int32? accountId = ViewContext.HttpContext.User.Id(); String area = Area ?? ViewContext.RouteData.Values["area"] as String; String action = Action ?? ViewContext.RouteData.Values["action"] as String; String controller = Controller ?? ViewContext.RouteData.Values["controller"] as String; if (!Authorization.IsAuthorizedFor(accountId, area, controller, action)) output.SuppressOutput(); }
public override async void Process(TagHelperContext context, TagHelperOutput output) { if (!context.Items.ContainsKey(typeof(MiniWebMenuContext))) { throw new InvalidOperationException($"Can only be used inside a tag with the {MiniWebMenuTagHelper.MiniWebMenuAttributename} attribute set"); } else { var modalContext = (MiniWebMenuContext)context.Items[typeof(MiniWebMenuContext)]; modalContext.ItemTemplate = await output.GetChildContentAsync(); output.SuppressOutput(); } }
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (String.IsNullOrEmpty(Name)) { throw new ArgumentException("The name attribute can't be empty"); } var childContent = await output.GetChildContentAsync(); var zone = _layoutAccessor.GetLayout().Zones[Name]; zone.Add(childContent, Position); // Don't render the zone tag or the inner content output.SuppressOutput(); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (ShowDismiss) { output.PreContent.AppendFormat(@"<button type='button' class='btn btn-default' data-dismiss='modal'>{0}</button>", DismissText); } var childContent = await output.GetChildContentAsync(); var footerContent = new DefaultTagHelperContent(); if (ShowDismiss) { footerContent.AppendFormat(@"<button type='button' class='btn btn-default' data-dismiss='modal'>{0}</button>", DismissText); } footerContent.AppendHtml(childContent); var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)]; modalContext.Footer = footerContent; output.SuppressOutput(); }
public override async void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } (_htmlHelper as IViewContextAware)?.Contextualize(ViewContext); await _htmlHelper.RenderPartialAsync("~/Views/Shared/_Editor.cshtml", _bricsContextAccessor.CurrentPage); output.SuppressOutput(); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (_webSite.IsAuthenticated(ViewContext.HttpContext.User)) { output.TagMode = TagMode.StartTagAndEndTag; //add the own contents. output.Content.AppendHtml(output.GetChildContentAsync().Result); (_htmlHelper as IViewContextAware )?.Contextualize(ViewContext); //admin content var content = _htmlHelper.Partial(_webSite.Configuration.EmbeddedResourcePath + MiniWebFileProvider.ADMIN_FILENAME); output.PreContent.AppendHtml(content); if (!IgnoreAdminStart) { output.Content.AppendHtml($"<script>$(function(){{$('{MiniWebAdminTag}').miniwebAdmin();}});</script>"); } } else { output.SuppressOutput(); } }
/// <inheritdoc /> public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } IHtmlContent content = null; if (Enabled) { var cacheKey = new CacheTagKey(this, context); MemoryCacheEntryOptions options; while (content == null) { Task<IHtmlContent> result = null; if (!MemoryCache.TryGetValue(cacheKey, out result)) { var tokenSource = new CancellationTokenSource(); // Create an entry link scope and flow it so that any tokens related to the cache entries // created within this scope get copied to this scope. options = GetMemoryCacheEntryOptions(); options.AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); var tcs = new TaskCompletionSource<IHtmlContent>(); // The returned value is ignored, we only do this so that // the compiler doesn't complain about the returned task // not being awaited var localTcs = MemoryCache.Set(cacheKey, tcs.Task, options); try { // The entry is set instead of assigning a value to the // task so that the expiration options are are not impacted // by the time it took to compute it. using (var entry = MemoryCache.CreateEntry(cacheKey)) { // The result is processed inside an entry // such that the tokens are inherited. result = ProcessContentAsync(output); content = await result; entry.SetOptions(options); entry.Value = result; } } catch { // Remove the worker task from the cache in case it can't complete. tokenSource.Cancel(); throw; } finally { // If an exception occurs, ensure the other awaiters // render the output by themselves. tcs.SetResult(null); } } else { // There is either some value already cached (as a Task) // or a worker processing the output. In the case of a worker, // the result will be null, and the request will try to acquire // the result from memory another time. content = await result; } } } else { content = await output.GetChildContentAsync(); } // Clear the contents of the "cache" element since we don't want to render it. output.SuppressOutput(); output.Content.SetHtmlContent(content); }
/// <summary> /// Synchronously executes the <see cref="TagHelper" /> with the given <paramref name="context" /> and /// <paramref name="output" />. /// </summary> /// <param name="context">Contains information associated with the current HTML tag.</param> /// <param name="output">A stateful HTML element used to generate an HTML tag.</param> public override void Process(TagHelperContext context, TagHelperOutput output) { // State check if (output.TagMode != TagMode.SelfClosing) { throw new InvalidOperationException($"The '{HtmlTagName}' tag must use self closing mode."); } // Get information and build up context var generator = GetRealGenerator(context); var options = GetRealOptions(context); CheckOptions(options); int currentPage, totalPage; GetPagingInfo(context, out currentPage, out totalPage); var pagerContext = new PagerGenerationContext(currentPage, totalPage, options, ViewContext, GenerationMode); // Generate result var result = generator.GeneratePager(pagerContext); // Disable default element output output.SuppressOutput(); // Append pager content output.PostElement.AppendHtml(result); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Include custom script url var setting = _resourceManager.Include("script", Src, DebugSrc); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Resource required var setting = _resourceManager.RegisterResource("script", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } setting.UseCdn(UseCdn); if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineScript(Name); definition.SetUrl(Src, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } } else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Custom script content var childContent = output.GetChildContentAsync().Result; var builder = new TagBuilder("script"); builder.InnerHtml.AppendHtml(childContent); builder.TagRenderMode = TagRenderMode.Normal; foreach (var attribute in output.Attributes) { builder.Attributes.Add(attribute.Name, attribute.Value.ToString()); } // If no type was specified, define a default one if (!builder.Attributes.ContainsKey("type")) { builder.Attributes.Add("type", "text/javascript"); } if (At == ResourceLocation.Head) { _resourceManager.RegisterHeadScript(builder); } else { _resourceManager.RegisterFootScript(builder); } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { if(PagingModel == null) { // allow for passing in the settings separately PagingModel = new PaginationSettings(); PagingModel.CurrentPage = PageNumber; PagingModel.ItemsPerPage = PageSize; PagingModel.TotalItems = TotalItems; PagingModel.MaxPagerItems = MaxPagerItems; PagingModel.SuppressEmptyNextPrev = SuppressEmptyNextPrev; PagingModel.SuppressInActiveFirstLast = SuppressInActiveFirstLast; } if(ShowFirstLast) { PagingModel.ShowFirstLast = true; } if(!ShowNumbered) { PagingModel.ShowNumbered = false; } if(UseReverseIncrement) { PagingModel.UseReverseIncrement = true; if(SuppressEmptyNextPrev) { PagingModel.SuppressEmptyNextPrev = true; } } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (SuppressEmptyPager && (totalPages <= 1)) { output.SuppressOutput(); return; } //change the cs-pager element into a ul output.TagName = "ul"; //prepare things needed by generatpageeurl function urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); List<PaginationLink> links = linkBuilder.BuildPaginationLinks( PagingModel, GeneratePageUrl, FirstPageText, FirstPageTitle, PreviousPageText, PreviousPageTitle, NextPageText, NextPageTitle, LastPageText, LastPageTitle, "..."); foreach(PaginationLink link in links) { var li = new TagBuilder("li"); if (link.IsCurrent) { li.AddCssClass(LiCurrentCssClass); } else { if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } else { if(!string.IsNullOrWhiteSpace(LiOtherCssClass)) { li.AddCssClass(LiOtherCssClass); } } } if(link.Text == PreviousPageText && !string.IsNullOrWhiteSpace(PreviousPageHtml)) { li.InnerHtml.AppendHtml(PreviousPageHtml); } else if(link.Text == NextPageText && !string.IsNullOrWhiteSpace(NextPageHtml)) { li.InnerHtml.AppendHtml(NextPageHtml); } else { if(!link.IsCurrent && link.Active) { var a = new TagBuilder("a"); if (link.Active && (link.Url.Length > 0)) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { a.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { a.InnerHtml.AppendHtml("»"); } else { a.InnerHtml.Append(link.Text); } if (link.Title.Length > 0) { a.MergeAttribute("title", link.Title); } if (AjaxTarget.Length > 0) { a.MergeAttribute("data-ajax", "true"); a.MergeAttribute("data-ajax-mode", AjaxMode); a.MergeAttribute("data-ajax-update", AjaxTarget); if (AjaxSuccess.Length > 0) { a.MergeAttribute("data-ajax-success", AjaxSuccess); } if (AjaxFailure.Length > 0) { a.MergeAttribute("data-ajax-failure", AjaxFailure); } if (AjaxBegin.Length > 0) { a.MergeAttribute("data-ajax-begin", AjaxBegin); } if (AjaxComplete.Length > 0) { a.MergeAttribute("data-ajax-complete", AjaxComplete); } if (AjaxLoading.Length > 0) { a.MergeAttribute("data-ajax-loading", AjaxLoading); } if (AjaxLoadingDuration.Length > 0) { a.MergeAttribute("data-ajax-loading-duration", AjaxLoadingDuration); } } li.InnerHtml.AppendHtml(a); } else { // current or not active var span = new TagBuilder("span"); if (link.Text == "«") { span.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { span.InnerHtml.AppendHtml("»"); } else { span.InnerHtml.Append(link.Text); } li.InnerHtml.AppendHtml(span); } } output.Content.AppendHtml(li); } output.Attributes.Clear(); output.Attributes.Add("class", UlCssClass); }
public void SuppressOutput_Sets_AllContent_ToNullOrEmpty() { // Arrange var tagHelperOutput = new TagHelperOutput("p"); tagHelperOutput.PreContent.Append("Pre Content"); tagHelperOutput.Content.Append("Content"); tagHelperOutput.PostContent.Append("Post Content"); // Act tagHelperOutput.SuppressOutput(); // Assert Assert.Null(tagHelperOutput.TagName); Assert.NotNull(tagHelperOutput.PreElement); Assert.Empty(tagHelperOutput.PreElement.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PreContent); Assert.Empty(tagHelperOutput.PreContent.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.Content); Assert.Empty(tagHelperOutput.Content.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PostContent); Assert.Empty(tagHelperOutput.PostContent.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PostElement); Assert.Empty(tagHelperOutput.PostElement.GetContent(new HtmlTestEncoder())); }
public override async void Process(TagHelperContext context, TagHelperOutput output) { //setup context MiniWebMenuContext menuContext = new MiniWebMenuContext(); context.Items.Add(typeof(MiniWebMenuContext), menuContext); var items = Enumerable.Empty<ISitePage>(); if (MenuRoot == "/") { items = _webSite.PageHierarchy.Where(p => p.VisibleInMenu() || _webSite.IsAuthenticated(ViewContext.HttpContext.User)); } else if (_webSite.Pages.Any(p => ("/" + p.Url) == MenuRoot)) { items = _webSite.Pages.First(p => ("/" + p.Url) == MenuRoot).Pages.Where(p => p.VisibleInMenu() || _webSite.IsAuthenticated(ViewContext.HttpContext.User)); } else { _webSite.Logger?.LogWarning($"No menuitems found for {MenuRoot}"); } if (items.Any()) { //remember the current model object currentModel = ViewContext.ViewData.Model; foreach (var page in items) { //override the model to the current child page ViewContext.ViewData.Model = page; //render child without cached results. await output.GetChildContentAsync(false); //get the current parsed ItemTemplate from the context output.Content.AppendHtml(menuContext.ItemTemplate); } //reset the current model ViewContext.ViewData.Model = currentModel; } else { output.SuppressOutput(); } }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } // Always strip the outer tag name as we never want <environment> to render output.TagName = null; if (string.IsNullOrWhiteSpace(Names)) { // No names specified, do nothing return; } var currentEnvironmentName = HostingEnvironment.EnvironmentName?.Trim(); if (string.IsNullOrEmpty(currentEnvironmentName)) { // No current environment name, do nothing return; } var tokenizer = new StringTokenizer(Names, NameSeparator); var hasEnvironments = false; foreach (var item in tokenizer) { var environment = item.Trim(); if (environment.HasValue && environment.Length > 0) { hasEnvironments = true; if (environment.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase)) { // Matching environment name found, do nothing return; } } } if (hasEnvironments) { // This instance had at least one non-empty environment specified but none of these // environments matched the current environment. Suppress the output in this case. output.SuppressOutput(); } }
public void SuppressOutput_PreventsTagOutput() { // Arrange var tagHelperOutput = new TagHelperOutput( "p", new TagHelperAttributeList { { "class", "btn" }, { "something", " spaced " } }, (cachedResult, encoder) => Task.FromResult<TagHelperContent>(new DefaultTagHelperContent())); tagHelperOutput.PreContent.Append("Pre Content"); tagHelperOutput.Content.Append("Content"); tagHelperOutput.PostContent.Append("Post Content"); // Act tagHelperOutput.SuppressOutput(); // Assert Assert.NotNull(tagHelperOutput.PreElement); Assert.Empty(tagHelperOutput.PreElement.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PreContent); Assert.Empty(tagHelperOutput.PreContent.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.Content); Assert.Empty(tagHelperOutput.Content.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PostContent); Assert.Empty(tagHelperOutput.PostContent.GetContent(new HtmlTestEncoder())); Assert.NotNull(tagHelperOutput.PostElement); Assert.Empty(tagHelperOutput.PostElement.GetContent(new HtmlTestEncoder())); }