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 no scripts were added, suppress the contents if (!_httpContextAccessor.HttpContext.Items.ContainsKey(InlineScriptConcatenatorTagHelper.ViewDataKey)) { output.SuppressOutput(); return; } //Otherwise get all the scripts for the page var scripts = _httpContextAccessor.HttpContext.Items[InlineScriptConcatenatorTagHelper.ViewDataKey] as IDictionary<string, NamedScriptInfo>; if (null == scripts) { output.SuppressOutput(); return; } //Concatenate all of them and set them as the contents of this tag var allScripts = string.Join("\r\n", OrderedScripts(scripts.Values).Select(os => os.Script)); output.TagMode = TagMode.StartTagAndEndTag; //HACK:Need to figure out how to get rid of the script tags for the placeholder element allScripts = $"</script><!--Rendered Scripts Output START-->\r\n{allScripts}\r\n</script><!--Rendered Scripts Output END--><script>";//HACK:ugly var unminifiedContent = output.Content.SetHtmlContent(allScripts); Debug.WriteLine(unminifiedContent.GetContent()); //TODO:Impliment dynamic minification (Assuming that some scenarios will be sped up, and others slowed down. Leave choice to user) }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (ShowIfNull != null) { output.SuppressOutput(); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (HideIf) { 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(); } }
protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) { if (ListGroupContext.ChildDetectionMode) { ListGroupContext.RenderAsDiv = true; output.SuppressOutput(); } else RenderOutput(output); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.Attributes.RemoveAll(MARKER_ATTRIBUTE); var tagHelperOutput = new TagHelperOutput(output.TagName, output.Attributes, output.GetChildContentAsync); _manager.Scripts.Add(tagHelperOutput); output.SuppressOutput(); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (this.ViewContext == null || this.For == null) return; output.SuppressOutput(); output.Content.Clear(); output.Content.Append(this.GenerateInput(this.ViewContext, this.For, null, "password")); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (this.ViewContext == null || this.For == null || this.Options == null) return; output.SuppressOutput(); output.Content.Clear(); output.Content.Append(this.GenerateField()); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (ViewContext.HttpContext.User.Identity.IsAuthenticated && ViewContext.HttpContext.User.IsInRole(Role)) { base.Process(context, output); return; } output.SuppressOutput(); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (ViewContext.HttpContext.User.Identity.IsAuthenticated && ViewContext.HttpContext.User.IsInRole(Role)) { base.Process(context, output); return; } output.SuppressOutput(); output.Content.Append("<h3>You must login first</h3>"); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var result = await AngularRenderer.RenderToString( nodeServices: this.nodeServices, componentModuleName: this.ModuleName, componentExportName: this.ExportName, componentTagName: output.TagName, requestUrl: UriHelper.GetEncodedUrl(this.contextAccessor.HttpContext.Request) ); output.SuppressOutput(); output.PostElement.AppendHtml(result); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (!string.IsNullOrEmpty(Policy)) { var canSee = await authorizationService.AuthorizeAsync(HttpContextAccessor.HttpContext.User, Policy); if (!canSee) { output.SuppressOutput(); } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { var varVal = Environment.GetEnvironmentVariable("Hosting:Environment"); if (varVal == NamesValue || (string.IsNullOrEmpty(NamesValue) && string.IsNullOrEmpty(varVal))) { var childContent = output.GetChildContentAsync().Result; output.Content.AppendHtml(childContent.GetContent()); } else { output.SuppressOutput(); } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { string url = await GetGiphyUrl(_config.ApiKey, SearchTerm); if (string.IsNullOrWhiteSpace(url)) { output.SuppressOutput(); } else { output.TagName = "img"; output.TagMode = TagMode.SelfClosing; output.Attributes["src"] = url; } }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "label"; var item = DbContext.CachedDistrictList().FirstOrDefault(x => x.Id == DistrictId); if (item == null) { output.SuppressOutput(); } else { output.Content.SetHtmlContent(item.Name); } }
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 void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) throw new ArgumentNullException(nameof(context)); if (output == null) throw new ArgumentNullException(nameof(output)); var httpContext = _httpContextAccessor.HttpContext; var userAgent = httpContext.Request.Headers["User-Agent"]; output.TagName = null; if (!_ieUserAgentExpression.IsMatch(userAgent)) { 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.Append(childContent); var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)]; modalContext.Footer = footerContent; output.SuppressOutput(); }
protected override async Task BootstrapProcessAsync(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); Content = (await output.GetChildContentAsync()).GetContent(); PaginationContext.Items.Add(this); }
/// <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)); } TagHelperContent result = null; if (Enabled) { var key = GenerateKey(context); if (!MemoryCache.TryGetValue(key, out result)) { // 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. using (var link = MemoryCache.CreateLinkingScope()) { result = await output.GetChildContentAsync(); MemoryCache.Set(key, result, GetMemoryCacheEntryOptions(link)); } } } // Clear the contents of the "cache" element since we don't want to render it. output.SuppressOutput(); if (Enabled) { output.Content.SetContent(result); } else { result = await output.GetChildContentAsync(); output.Content.SetContent(result); } }
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; } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (totalPages <= 1) { output.SuppressOutput(); return; } //change the cs-pager element into a ul output.TagName = "ul"; string querySeparator; //prepare things needed by generatpageeurl function TagBuilder linkTemplate = GenerateLinkTemplate(); baseHref = linkTemplate.Attributes["href"] ?? string.Empty; querySeparator = baseHref.Contains("?") ? "&" : "?"; baseHref = baseHref + querySeparator + PageNumberParam + "="; 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); } if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } var a = new TagBuilder("a"); if(link.Url.Length > 0) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { //a.InnerHtml = "«"; a.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { //a.InnerHtml = "»"; 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); } li.InnerHtml.Append(a); output.Content.Append(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 void SuppressOutput_PreventsTagOutput() { // Arrange var tagHelperOutput = new TagHelperOutput("p", new TagHelperAttributeList { { "class", "btn" }, { "something", " spaced " } }, (cachedResult) => 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())); }
/// <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 environments = Names.Split(NameSeparator, StringSplitOptions.RemoveEmptyEntries) .Where(name => !string.IsNullOrWhiteSpace(name)); if (!environments.Any()) { // Names contains only commas or empty entries, do nothing return; } var currentEnvironmentName = HostingEnvironment.EnvironmentName?.Trim(); if (string.IsNullOrWhiteSpace(currentEnvironmentName)) { // No current environment name, do nothing return; } if (environments.Any(name => string.Equals(name.Trim(), currentEnvironmentName, StringComparison.OrdinalIgnoreCase))) { // Matching environment name found, do nothing return; } // No matching environment name found, suppress all output 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(); } }