public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var formGroupContext = CreateFormGroupContext(); IHtmlContent content; bool haveError; // Since implementations can return a derived FormGroupContext ensure we set both a context item // for FormGroupContext and one for the specific type. // N.B. we cannot make this context type a generic parameter since it's internal. using (context.SetScopedContextItem(formGroupContext)) using (context.SetScopedContextItem(formGroupContext.GetType(), formGroupContext)) { var childContent = await output.GetChildContentAsync(); content = GenerateFormGroupContent(context, formGroupContext, output, childContent, out haveError); } var tagBuilder = CreateTagBuilder(haveError, content, output); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var detailsContext = new DetailsContext(); using (context.SetScopedContextItem(typeof(DetailsContext), detailsContext)) { await output.GetChildContentAsync(); } detailsContext.ThrowIfStagesIncomplete(); var tagBuilder = _htmlGenerator.GenerateDetails( Open, Id, detailsContext.Summary?.content, detailsContext.Summary?.attributes, detailsContext.Text?.content, detailsContext.Text?.attributes, output.Attributes.ToAttributesDictionary()); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (HeadingLevel < 1 || HeadingLevel > 6) { throw new InvalidOperationException( $"The '{HeadingLevelAttributeName}' attribute must be between 1 and 6."); } var panelContext = new PanelContext(); IHtmlContent childContent; using (context.SetScopedContextItem(typeof(PanelContext), panelContext)) { childContent = await output.GetChildContentAsync(); } if (panelContext.Title == null) { throw new InvalidOperationException("Missing <govuk-panel-title> element."); } var tagBuilder = _htmlGenerator.GeneratePanel( HeadingLevel, panelContext.Title, childContent, output.Attributes.ToAttributesDictionary()); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (Name == null && AspFor == null) { throw new InvalidOperationException( $"At least one of the '{NameAttributeName}' and '{AspForAttributeName}' attributes must be specified."); } FormGroupAttributes = output.Attributes.ToAttributesDictionary(); var builder = CreateFormGroupBuilder(); using (context.SetScopedContextItem(typeof(FormGroupBuilder), builder)) { await output.GetChildContentAsync(); } var tagBuilder = GenerateContent(context, builder); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var notificationBannerContext = new NotificationBannerContext(); TagHelperContent childContent; using (context.SetScopedContextItem(notificationBannerContext)) { childContent = await output.GetChildContentAsync(); } var tagBuilder = _htmlGenerator.GenerateNotificationBanner( Type, Role, DisableAutoFocus, notificationBannerContext.Title?.Id, notificationBannerContext.Title?.HeadingLevel, notificationBannerContext.Title?.Content, childContent.Snapshot(), output.Attributes.ToAttributeDictionary()); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var accordionContext = (AccordionContext)context.Items[typeof(AccordionContext)]; var itemContext = new AccordionItemContext(); TagHelperContent childContent; using (context.SetScopedContextItem(typeof(AccordionItemContext), itemContext)) { childContent = await output.GetChildContentAsync(); } if (itemContext.Heading == null) { throw new InvalidOperationException("Missing <govuk-accordion-item-heading> element."); } accordionContext.AddItem(new AccordionItem() { Attributes = output.Attributes.ToAttributesDictionary(), Content = childContent.Snapshot(), IsExpanded = IsExpanded, HeadingContent = itemContext.Heading.Value.content, HeadingAttributes = itemContext.Heading.Value.attributes, HeadingLevel = itemContext.Heading.Value.level, SummaryContent = itemContext.Summary?.content, SummaryAttributes = itemContext.Summary?.attributes }); output.SuppressOutput(); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var accordionContext = context.GetContextItem <AccordionContext>(); var itemContext = new AccordionItemContext(); TagHelperContent childContent; using (context.SetScopedContextItem(itemContext)) { childContent = await output.GetChildContentAsync(); } itemContext.ThrowIfIncomplete(); accordionContext.AddItem(new AccordionItem() { Expanded = Expanded, HeadingContent = itemContext.Heading !.Value.Content, HeadingAttributes = itemContext.Heading.Value.Attributes, SummaryContent = itemContext.Summary?.Content, SummaryAttributes = itemContext.Summary?.Attributes, Content = childContent.Snapshot(), Attributes = output.Attributes.ToAttributeDictionary() });
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (Id == null) { throw new InvalidOperationException($"The '{IdAttributeName}' attribute must be specified."); } var accordionContext = new AccordionContext(); using (context.SetScopedContextItem(typeof(AccordionContext), accordionContext)) { await output.GetChildContentAsync(); } var tagBuilder = _htmlGenerator.GenerateAccordion( Id, output.Attributes.ToAttributesDictionary(), accordionContext.Items); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var summaryListContext = context.GetContextItem <SummaryListContext>(); var rowContext = new SummaryListRowContext(); using (context.SetScopedContextItem(rowContext)) { await output.GetChildContentAsync(); } rowContext.ThrowIfIncomplete(); summaryListContext.AddRow(new SummaryListRow() { Actions = new SummaryListRowActions() { Items = rowContext.Actions, Attributes = rowContext.ActionsAttributes }, Attributes = output.Attributes.ToAttributeDictionary(), Key = new SummaryListRowKey() { Content = rowContext.Key !.Value.Content, Attributes = rowContext.Key !.Value.Attributes },
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var phaseBannerContext = new PhaseBannerContext(); IHtmlContent childContent; using (context.SetScopedContextItem(phaseBannerContext)) { childContent = await output.GetChildContentAsync(); } phaseBannerContext.ThrowIfIncomplete(); var tagBuilder = _htmlGenerator.GeneratePhaseBanner( phaseBannerContext.Tag?.Content, phaseBannerContext.Tag?.Attributes, childContent, output.Attributes.ToAttributeDictionary()); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (Value == null) { throw new InvalidOperationException($"The '{ValueAttributeName}' attribute must be specified."); } // REVIEW Consider throwing if Checked is null && there is no AspFor var radiosContext = (RadiosContext)context.Items[typeof(RadiosContext)]; var index = radiosContext.Items.Count; var resolvedId = Id ?? (index == 0 ? radiosContext.IdPrefix : $"{radiosContext.IdPrefix}-{index}"); var conditionalId = "conditional-" + resolvedId; var hintId = resolvedId + "-item-hint"; var resolvedChecked = IsChecked ?? (radiosContext.HaveModelExpression ? _modelHelper.GetModelValue( radiosContext.ViewContext, radiosContext.AspFor.ModelExplorer, radiosContext.AspFor.Name) == Value : false); var itemContext = new RadiosItemContext(); TagHelperContent childContent; using (context.SetScopedContextItem(typeof(RadiosItemContext), itemContext)) { childContent = await output.GetChildContentAsync(); } radiosContext.AddItem(new RadiosItem() { Attributes = output.Attributes.ToAttributesDictionary(), IsChecked = resolvedChecked, ConditionalContent = itemContext.Conditional?.content, ConditionalAttributes = itemContext.Conditional?.attributes, ConditionalId = conditionalId, Content = childContent.Snapshot(), IsDisabled = IsDisabled, HintAttributes = itemContext.Hint?.attributes, HintContent = itemContext.Hint?.content, HintId = hintId, Id = resolvedId, InputAttributes = InputAttributes, Value = Value }); if (itemContext.Conditional != null) { radiosContext.SetIsConditional(); } output.SuppressOutput(); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; TagHelperContent childContent; using (context.SetScopedContextItem(typeof(AccordionItemContext), itemContext)) { childContent = await output.GetChildContentAsync(); } if (!itemContext.TrySetSummary(output.Attributes.ToAttributesDictionary(), childContent.Snapshot())) { throw new InvalidOperationException($"Cannot render <{output.TagName}> here."); } output.SuppressOutput(); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var summaryListContext = new SummaryListContext(); using (context.SetScopedContextItem(typeof(SummaryListContext), summaryListContext)) { await output.GetChildContentAsync(); } var tagBuilder = _htmlGenerator.GenerateSummaryList( output.Attributes.ToAttributesDictionary(), summaryListContext.Rows); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var breadcrumbsContext = new BreadcrumbsContext(); using (context.SetScopedContextItem(breadcrumbsContext)) { await output.GetChildContentAsync(); } var tagBuilder = _htmlGenerator.GenerateBreadcrumbs( CollapseOnMobile, output.Attributes.ToAttributeDictionary(), breadcrumbsContext.Items); output.TagName = tagBuilder.TagName; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Clear(); output.MergeAttributes(tagBuilder); output.Content.SetHtmlContent(tagBuilder.InnerHtml); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var summaryListContext = (SummaryListContext)context.Items[typeof(SummaryListContext)]; var rowContext = new SummaryListRowContext(); using (context.SetScopedContextItem(typeof(SummaryListRowContext), rowContext)) { await output.GetChildContentAsync(); } summaryListContext.AddRow(new SummaryListRow() { Actions = rowContext.Actions, Attributes = output.Attributes.ToAttributesDictionary(), Key = rowContext.Key, Value = rowContext.Value }); output.SuppressOutput(); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (Level != null && (Level < 1 || Level > 6)) { throw new InvalidOperationException($"The '{LevelAttributeName}' attribute must be between 1 and 6."); } var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; TagHelperContent childContent; using (context.SetScopedContextItem(typeof(AccordionItemContext), itemContext)) { childContent = await output.GetChildContentAsync(); } if (!itemContext.TrySetHeading(Level, output.Attributes.ToAttributesDictionary(), childContent.Snapshot())) { throw new InvalidOperationException($"Cannot render <{output.TagName}> here."); } output.SuppressOutput(); }