void IHtmlContentContainer.MoveTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _preElement?.MoveTo(destination); var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(TagName); if (!isTagNameNullOrWhitespace) { destination.AppendHtml("<"); destination.AppendHtml(TagName); // Perf: Avoid allocating enumerator, cache .Count as it goes via interface var count = Attributes.Count; for (var i = 0; i < count; i++) { var attribute = Attributes[i]; destination.AppendHtml(" "); attribute.MoveTo(destination); } if (TagMode == TagMode.SelfClosing) { destination.AppendHtml(" /"); } destination.AppendHtml(">"); } if (isTagNameNullOrWhitespace || TagMode == TagMode.StartTagAndEndTag) { _preContent?.MoveTo(destination); _content?.MoveTo(destination); _postContent?.MoveTo(destination); } if (!isTagNameNullOrWhitespace && TagMode == TagMode.StartTagAndEndTag) { destination.AppendHtml("</"); destination.AppendHtml(TagName); destination.AppendHtml(">"); } _postElement?.MoveTo(destination); // Depending on the code path we took, these might need to be cleared. _preContent?.Clear(); _content?.Clear(); _postContent?.Clear(); Attributes.Clear(); }
public void MoveTo(IHtmlContentBuilder builder) { TkDebug.AssertArgumentNull(builder, nameof(builder), this); // Perf: We have an efficient implementation when the destination is another view buffer, // we can just insert our pages as-is. if (builder is ViewBuffer other) { MoveTo(other); return; } for (var i = 0; i < Count; i++) { var page = this[i]; for (var j = 0; j < page.Count; j++) { var value = page.Buffer[j]; string valueAsString; IHtmlContentContainer valueAsContainer; if ((valueAsString = value.Value as string) != null) { builder.AppendHtml(valueAsString); } else if ((valueAsContainer = value.Value as IHtmlContentContainer) != null) { valueAsContainer.MoveTo(builder); } else { builder.AppendHtml((IHtmlContent)value.Value); } } } for (var i = 0; i < Count; i++) { var page = this[i]; Array.Clear(page.Buffer, 0, page.Count); fBufferScope.ReturnSegment(page.Buffer); } Clear(); }
public void RenderStylesheet(IHtmlContentBuilder builder) { var first = true; var styleSheets = DoGetRequiredResources("stylesheet"); foreach (var context in styleSheets) { if (!first) { builder.AppendHtml(System.Environment.NewLine); } first = false; builder.AppendHtml(context.GetHtmlContent(_options.ContentBasePath)); } }
public void RenderStylesheet(IHtmlContentBuilder builder, RequireSettings settings) { var first = true; var styleSheets = this.GetRequiredResources("stylesheet"); foreach (var context in styleSheets) { if (!first) { builder.AppendHtml(Environment.NewLine); } first = false; builder.AppendHtml(context.GetHtmlContent(settings, "/")); } }
public void ScriptRender(IHtmlContentBuilder htmlContentBuilder) { bool async = _optionalAttributes >> 2 == 1, defer = _optionalAttributes >> 3 == 1; if (async) { htmlContentBuilder.AppendHtml($"<script src='{_mainAttributeValue}' async></script>"); } else if (defer) { htmlContentBuilder.AppendHtml($"<script src='{_mainAttributeValue}' defer></script>"); } else { htmlContentBuilder.AppendHtml($"<script src='{_mainAttributeValue}'></script>"); } }
public void RenderHeadLink(IHtmlContentBuilder builder) { var first = true; var registeredLinks = DoGetRegisteredLinks(); for (var i = 0; i < registeredLinks.Count; i++) { var link = registeredLinks[i]; if (!first) { builder.AppendHtml(System.Environment.NewLine); } first = false; builder.AppendHtml(link.GetTag()); } }
/// <summary> /// Appends an <see cref="Environment.NewLine"/>. /// </summary> /// <param name="builder">The <see cref="IHtmlContentBuilder"/>.</param> /// <returns>The <see cref="IHtmlContentBuilder"/>.</returns> public static IHtmlContentBuilder AppendLine(this IHtmlContentBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.AppendHtml(HtmlString.NewLine); return(builder); }
/// <summary> /// Sets the content to the <see cref="string"/> value. The value is treated as HTML encoded as-provided, and /// no further encoding will be performed. /// </summary> /// <param name="builder">The <see cref="IHtmlContentBuilder"/>.</param> /// <param name="encoded">The HTML encoded <see cref="string"/> that replaces the content.</param> /// <returns>The <see cref="IHtmlContentBuilder"/>.</returns> public static IHtmlContentBuilder SetHtmlContent(this IHtmlContentBuilder builder, string encoded) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.Clear(); builder.AppendHtml(encoded); return(builder); }
public void RenderLocalScript(RequireSettings settings, IHtmlContentBuilder builder) { var localScripts = this.GetRequiredResources("script"); var first = true; foreach (var context in localScripts.Where(r => r.Settings.Location == ResourceLocation.Unspecified)) { if (_localScripts.Add(context.Settings.Name) || context.Settings.Name == settings.Name) { if (!first) { builder.AppendHtml(Environment.NewLine); } first = false; builder.AppendHtml(context.GetHtmlContent(_pathBase)); } } }
private async Task RenderControllerAction(string controller, string action, Rendering rendering, IHtmlContentBuilder output, ViewContext viewContext, PageData pageData) { var context = await GetViewContext(rendering, viewContext, pageData, new NullView(), viewContext.Writer); var toContext = _viewComponentHelper as IViewContextAware; if (toContext != null) { toContext.Contextualize(context); } try { var result = await _viewComponentHelper.InvokeAsync(action + ": " + controller); output.AppendHtml(result); } catch (InvalidOperationException exc) { output.AppendHtml($"<div class=\"alert alert-danger\"><strong>{exc.Message}</strong> not found!</div>"); } }
void IHtmlContentContainer.CopyTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _preElement?.CopyTo(destination); var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(TagName); if (!isTagNameNullOrWhitespace) { destination.AppendHtml("<"); destination.AppendHtml(TagName); // Perf: Avoid allocating enumerator for (var i = 0; i < Attributes.Count; i++) { var attribute = Attributes[i]; destination.AppendHtml(" "); attribute.CopyTo(destination); } if (TagMode == TagMode.SelfClosing) { destination.AppendHtml(" /"); } destination.AppendHtml(">"); } if (isTagNameNullOrWhitespace || TagMode == TagMode.StartTagAndEndTag) { _preContent?.CopyTo(destination); _content?.CopyTo(destination); _postContent?.CopyTo(destination); } if (!isTagNameNullOrWhitespace && TagMode == TagMode.StartTagAndEndTag) { destination.AppendHtml("</"); destination.AppendHtml(TagName); destination.AppendHtml(">"); } _postElement?.CopyTo(destination); }
public void RenderLocalScript(RequireSettings settings, IHtmlContentBuilder builder) { var localScripts = DoGetRequiredResources("script"); var first = true; foreach (var context in localScripts) { if (context.Settings.Location == ResourceLocation.Unspecified && (_localScripts.Add(context.Settings.Name) || context.Settings.Name == settings.Name)) { if (!first) { builder.AppendHtml(System.Environment.NewLine); } first = false; builder.AppendHtml(context.GetHtmlContent(_options.ContentBasePath)); } } }
private void AppendVersionedSrc( string srcName, string srcValue, HtmlAttributeValueStyle valueStyle, IHtmlContentBuilder builder) { srcValue = GetVersionedSrc(srcValue); builder.AppendHtml(" "); var attribute = new TagHelperAttribute(srcName, srcValue, valueStyle); attribute.CopyTo(builder); }
public void RenderFootScript(IHtmlContentBuilder builder) { var footScripts = DoGetRequiredResources("script"); var first = true; foreach (var context in footScripts) { if (context.Settings.Location != ResourceLocation.Foot) { continue; } if (!first) { builder.AppendHtml(System.Environment.NewLine); } first = false; builder.AppendHtml(context.GetHtmlContent(_options.ContentBasePath)); } var registeredFootScripts = DoGetRegisteredFootScripts(); for (var i = 0; i < registeredFootScripts.Count; i++) { var context = registeredFootScripts[i]; if (!first) { builder.AppendHtml(System.Environment.NewLine); } first = false; builder.AppendHtml(context); } }
private static void GetItemForRadioValues <TModel, TValue>(IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IList <SelectListItem> values, IHtmlContentBuilder builder) { foreach (var item in values) { var rbx = html.RadioButtonFor(expression, item.Value); var lbl = html.Label(item.Text); var div = new TagBuilder("div"); div.AddCssClass("multiple-choice"); div.InnerHtml.AppendHtml(rbx); div.InnerHtml.AppendHtml(lbl); builder.AppendHtml(div); } }
public void CopyTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (Pages == null) { return; } for (var i = 0; i < Pages.Count; i++) { var page = Pages[i]; for (var j = 0; j < page.Count; j++) { var value = page.Buffer[j]; string valueAsString; IHtmlContentContainer valueAsContainer; if ((valueAsString = value.Value as string) != null) { destination.AppendHtml(valueAsString); } else if ((valueAsContainer = value.Value as IHtmlContentContainer) != null) { valueAsContainer.CopyTo(destination); } else { destination.AppendHtml((IHtmlContent)value.Value); } } } }
internal static IHtmlContentBuilder AppendHtml(this IHtmlContentBuilder content, TagBuilder tag, string cssClass = null) { TagBuilder li = new TagBuilder("li") { TagRenderMode = TagRenderMode.Normal }; if (!string.IsNullOrEmpty(cssClass)) { li.AddCssClass(cssClass); } li.InnerHtml.AppendHtml(tag); content.AppendHtml(li); content.AppendHtmlLine(Environment.NewLine); return(content); }
void IHtmlContentContainer.MoveTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _preElement?.MoveTo(destination); var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(TagName); if (!isTagNameNullOrWhitespace) { destination.AppendHtml("<"); destination.AppendHtml(TagName); CopyAttributesTo(destination); if (TagMode == TagMode.SelfClosing) { destination.AppendHtml(" /"); } destination.AppendHtml(">"); } if (isTagNameNullOrWhitespace || TagMode == TagMode.StartTagAndEndTag) { _preContent?.MoveTo(destination); _content?.MoveTo(destination); _postContent?.MoveTo(destination); } if (!isTagNameNullOrWhitespace && TagMode == TagMode.StartTagAndEndTag) { destination.AppendHtml("</"); destination.AppendHtml(TagName); destination.AppendHtml(">"); } _postElement?.MoveTo(destination); // Depending on the code path we took, these might need to be cleared. _preContent?.Clear(); _content?.Clear(); _postContent?.Clear(); Attributes.Clear(); }
private static void GetItemForRadioValuesEnum <TModel, TValue>(IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IHtmlContentBuilder builder) { //By checking the underlying type, it means we can support nullable and non nullable enum values in the model. var enumType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); // values are extracted directly out of the enum. foreach (var item in Enum.GetValues(enumType)) { var rbx = html.RadioButtonFor(expression, item.ToString()); var lbl = html.Label(item.ToString()); var div = new TagBuilder("div"); div.AddCssClass("multiple-choice"); div.InnerHtml.AppendHtml(rbx); div.InnerHtml.AppendHtml(lbl); builder.AppendHtml(div); } }
void IHtmlContentContainer.CopyTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _preElement?.CopyTo(destination); var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(TagName); if (!isTagNameNullOrWhitespace) { destination.AppendHtml("<"); destination.AppendHtml(TagName); CopyAttributesTo(destination); if (TagMode == TagMode.SelfClosing) { destination.AppendHtml(" /"); } destination.AppendHtml(">"); } if (isTagNameNullOrWhitespace || TagMode == TagMode.StartTagAndEndTag) { _preContent?.CopyTo(destination); _content?.CopyTo(destination); _postContent?.CopyTo(destination); } if (!isTagNameNullOrWhitespace && TagMode == TagMode.StartTagAndEndTag) { destination.AppendHtml("</"); destination.AppendHtml(TagName); destination.AppendHtml(">"); } _postElement?.CopyTo(destination); }
private static void MoveToCore(object entry, IHtmlContentBuilder destination) { if (entry == null) { return; } if (entry is string entryAsString) { destination.Append(entryAsString); } else if (entry is IHtmlContentContainer entryAsContainer) { entryAsContainer.MoveTo(destination); } else { destination.AppendHtml((IHtmlContent)entry); } }
private void MoveToCore(object entry, IHtmlContentBuilder destination) { if (entry == null) { return; } string entryAsString; IHtmlContentContainer entryAsContainer; if ((entryAsString = entry as string) != null) { destination.Append(entryAsString); } else if ((entryAsContainer = entry as IHtmlContentContainer) != null) { entryAsContainer.MoveTo(destination); } else { destination.AppendHtml((IHtmlContent)entry); } }
/// <summary> /// Appends the specified <paramref name="format"/> to the existing content after replacing each format /// item with the HTML encoded <see cref="string"/> representation of the corresponding item in the /// <paramref name="args"/> array. /// </summary> /// <param name="builder">The <see cref="IHtmlContentBuilder"/>.</param> /// <param name="format"> /// The composite format <see cref="string"/> (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx). /// The format string is assumed to be HTML encoded as-provided, and no further encoding will be performed. /// </param> /// <param name="args"> /// The object array to format. Each element in the array will be formatted and then HTML encoded. /// </param> /// <returns>A reference to this instance after the append operation has completed.</returns> public static IHtmlContentBuilder AppendFormat( this IHtmlContentBuilder builder, string format, params object[] args) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (format == null) { throw new ArgumentNullException(nameof(format)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } builder.AppendHtml(new HtmlFormattableString(format, args)); return(builder); }
private void CopyAttributesTo(IHtmlContentBuilder destination) { StringWriter stringWriter = null; // Perf: Avoid allocating enumerator for (var i = 0; i < (Attributes.Count); i++) { var attribute = Attributes[i]; destination.AppendHtml(" "); destination.AppendHtml(attribute.Name); if (attribute.Minimized) { continue; } destination.AppendHtml("=\""); var value = attribute.Value; var htmlContent = value as IHtmlContent; if (htmlContent != null) { // Perf: static text in a bound attribute go down this path. Avoid allocating if possible (common case). var htmlEncodedString = value as HtmlEncodedString; if (htmlEncodedString != null && !htmlEncodedString.Value.Contains("\"")) { destination.AppendHtml(htmlEncodedString); } else { // Perf: We'll share this writer implementation for all attributes since // they can't nest. stringWriter = stringWriter ?? new StringWriter(); destination.AppendHtml(new AttributeContent(htmlContent, stringWriter)); } } else if (value != null) { destination.Append(value.ToString()); } destination.AppendHtml("\""); } }
void IHtmlContentContainer.MoveTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _preElement?.MoveTo(destination); var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(TagName); if (!isTagNameNullOrWhitespace) { destination.AppendHtml("<"); destination.AppendHtml(TagName); // Perf: Avoid allocating enumerator for (var i = 0; i < Attributes.Count; i++) { var attribute = Attributes[i]; destination.AppendHtml(" "); attribute.MoveTo(destination); } if (TagMode == TagMode.SelfClosing) { destination.AppendHtml(" /"); } destination.AppendHtml(">"); } if (isTagNameNullOrWhitespace || TagMode == TagMode.StartTagAndEndTag) { _preContent?.MoveTo(destination); _content?.MoveTo(destination); _postContent?.MoveTo(destination); } if (!isTagNameNullOrWhitespace && TagMode == TagMode.StartTagAndEndTag) { destination.AppendHtml("</"); destination.AppendHtml(TagName); destination.AppendHtml(">"); } _postElement?.MoveTo(destination); // Depending on the code path we took, these might need to be cleared. _preContent?.Clear(); _content?.Clear(); _postContent?.Clear(); Attributes.Clear(); }
private static IHtmlContentBuilder AppendJavaScript(this IHtmlContentBuilder content, string path) { return(content.AppendHtml($"\n<script src='{path}'></script>")); }
private static IHtmlContentBuilder AppendStyleSheet(this IHtmlContentBuilder content, string path) { return(content.AppendHtml($"\n<link href='{path}' rel='stylesheet' />")); }
/// <inheritdoc /> public void MoveTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } for (var i = 0; i < Entries.Count; i++) { var entry = Entries[i]; string entryAsString; IHtmlContentContainer entryAsContainer; if ((entryAsString = entry as string) != null) { destination.Append(entryAsString); } else if ((entryAsContainer = entry as IHtmlContentContainer) != null) { // Since we're moving, do a deep flatten. entryAsContainer.MoveTo(destination); } else { // Only string, IHtmlContent values can be added to the buffer. destination.AppendHtml((IHtmlContent)entry); } } Entries.Clear(); }
public async Task PopulateHtmlTagAsync(ITagBuilderOptions options, ReadOnlyTagHelperAttributeList attributeList, Asset asset, IHtmlContentBuilder output) { TagBuilder tagBuilder = null; var outputMode = options.Output; if (!this.Options.BundleStylesheets && !this.Options.MinifyStylesheets) { outputMode = OptimizationTagOutput.Tag; } else if (OptimizationTagOutput.Tag == outputMode && (this.Options.BundleStylesheets || this.Options.MinifyStylesheets)) { outputMode = OptimizationTagOutput.StaticFile; } switch (outputMode) { case OptimizationTagOutput.Default: //same as OptimizationTagOutput.Inline string content = await asset.ReadContentAsStringAsync(); output.AppendHtmlLine($"<style>{content}</style>"); break; case OptimizationTagOutput.Tag: tagBuilder = new TagBuilder("link"); tagBuilder.TagRenderMode = TagRenderMode.SelfClosing; tagBuilder.Attributes.Add("rel", "stylesheet"); tagBuilder.Attributes.Add("type", "text/css"); tagBuilder.Attributes.Add("href", asset.GetWebLocation(this.Options)); output.AppendHtml(tagBuilder); break; case OptimizationTagOutput.StaticFile: case OptimizationTagOutput.Loader: string webPath = null; PathString relativeFilePath = new PathString(this.Options.StaticAssetsPath).Add($"/{asset.Name}"); var assetFileInfo = this.HostingEnvironment.WebRootFileProvider.GetFileInfo(relativeFilePath); if (!assetFileInfo.Exists) { content = await asset.ReadContentAsStringAsync(); await File.WriteAllTextAsync(assetFileInfo.PhysicalPath, content, Encoding.UTF8); } if (string.IsNullOrWhiteSpace(this.Options.AssetRootUrl)) { webPath = this.HttpContextAccessor.HttpContext.Request.PathBase.Add(relativeFilePath); } else { if (!Uri.TryCreate(this.Options.AssetRootUrl, UriKind.Absolute, out Uri cdnRootUri)) { throw new UriFormatException($"'{this.Options.AssetRootUrl}' is an invalid Uri. An absolute Uri is expected."); } Uri.TryCreate(cdnRootUri, $"{asset.Name}", out Uri webPathUri); webPath = webPathUri.ToString(); } tagBuilder = new TagBuilder("link"); tagBuilder.TagRenderMode = TagRenderMode.SelfClosing; tagBuilder.Attributes.Add("rel", "stylesheet"); tagBuilder.Attributes.Add("type", "text/css"); tagBuilder.Attributes.Add("href", webPath); output.AppendHtml(tagBuilder); break; } }
public void CopyTo(IHtmlContentBuilder destination) { foreach (var entry in Entries) { destination.AppendHtml(entry); } }
public static IHtmlContent CardView <TModel>(this IHtmlHelper html, IEnumerable <TModel> dataList, Func <TModel, IHtmlContent> operatingBuilder = default) { var type = typeof(TModel); var columnMeta = DataListHelper.GetDataColumnMeta(type); var groupMeta = DataListHelper.GetDataMeta(type); var group = new TagBuilder("div"); group.AddCssClass("card-deck"); if (groupMeta.HtmlAttribute != null) { group.MergeAttributes(groupMeta.HtmlAttribute, true); } if (dataList != null) { foreach (var item in dataList) { var card = new TagBuilder("div"); card.AddCssClass("card"); TagBuilder header = null; TagBuilder body = null; TagBuilder listGroup = null; TagBuilder footer = null; IHtmlContentBuilder root = null; foreach (var column in columnMeta.FindAll(p => p.Attribute != null)) { switch (column.CardContentContainer) { case CardContentContainer.Root: root ??= new HtmlContentBuilder(); root.AppendHtml(column.GetValue(type, item)); break; case CardContentContainer.Header: header ??= new TagBuilder("div"); var headerItem = new TagBuilder("div"); headerItem.AddCssClass("card-text"); if (column.ContentHtmlAttribute != null) { headerItem.MergeAttributes(column.ContentHtmlAttribute, true); } headerItem.InnerHtml.AppendHtml(column.GetValue(type, item)); header.InnerHtml.AppendHtml(headerItem); break; case CardContentContainer.Body: body ??= new TagBuilder("div"); var bodyItem = new TagBuilder("div"); bodyItem.AddCssClass("card-text"); if (column.ContentHtmlAttribute != null) { bodyItem.MergeAttributes(column.ContentHtmlAttribute, true); } bodyItem.InnerHtml.AppendHtml(column.GetValue(type, item)); body.InnerHtml.AppendHtml(bodyItem); break; case CardContentContainer.ListGroup: listGroup ??= new TagBuilder("ul"); var listItem = new TagBuilder("li"); listItem.AddCssClass("list-group-item"); if (column.ContentHtmlAttribute != null) { listItem.MergeAttributes(column.ContentHtmlAttribute, true); } listItem.InnerHtml.AppendHtml(column.GetValue(type, item)); listGroup.InnerHtml.AppendHtml(listItem); break; case CardContentContainer.Footer: footer ??= new TagBuilder("div"); var footerItem = new TagBuilder("div"); footerItem.AddCssClass("text-muted"); if (column.ContentHtmlAttribute != null) { footerItem.MergeAttributes(column.ContentHtmlAttribute, true); } footerItem.InnerHtml.AppendHtml(column.GetValue(type, item)); footer.InnerHtml.AppendHtml(footerItem); break; } } if (header != null) { header.AddCssClass("card-header"); card.InnerHtml.AppendHtml(header); } if (root != null) { card.InnerHtml.AppendHtml(root); } if (body != null) { body.AddCssClass("card-body"); card.InnerHtml.AppendHtml(body); } if (listGroup != null) { listGroup.AddCssClass("list-group list-group-flush"); card.InnerHtml.AppendHtml(listGroup); } if (operatingBuilder != null) { card.InnerHtml.AppendHtml(operatingBuilder(item)); } if (footer != null) { footer.AddCssClass("card-footer"); card.InnerHtml.AppendHtml(footer); } group.InnerHtml.AppendHtml(card); } } return(group); }
public void TitleRender(IHtmlContentBuilder htmlContentBuilder) { htmlContentBuilder.AppendHtml($"<title>{_mainAttributeValue}</title>"); }
public async Task DoRender(string placeholderName, bool isDynamic, IHtmlContentBuilder output, ViewContext viewContext) { if (viewContext?.ViewData == null) { output.Append("ViewContext/ViewData cannot be null"); return; } if (isDynamic && viewContext.ViewData[BocUniqueId] == null) { output.Append("Nested placeholders must be inside a known component"); return; } var placeholderStack = viewContext.ViewData[BocPlaceholderStack] as Stack <string>; if (placeholderStack == null) { placeholderStack = (Stack <string>)(viewContext.ViewData[BocPlaceholderStack] = new Stack <string>()); } var usedName = isDynamic ? placeholderName + "_" + (Guid)viewContext.ViewData[BocUniqueId] : placeholderName; placeholderStack.Push(usedName); var placeHolderKey = placeholderStack.Count > 1 ? "/" + string.Join("/", placeholderStack.ToArray().Reverse()) : usedName; var pathandQuery = viewContext.HttpContext.Request.Path.Value + viewContext.HttpContext.Request.QueryString; var pageData = await GetPageData(pathandQuery); if (pageData == null || string.IsNullOrEmpty(placeHolderKey)) { output.AppendHtml("UNABLE TO LOAD PLACEHOLDER " + placeHolderKey); return; } RenderingChrome?placeholderChrome = null; if (viewContext.HttpContext.IsInCmsMode()) { placeholderChrome = await _sitecoreService.Get <RenderingChrome>(pathandQuery + (pathandQuery.Contains("?") ? "&" : "?") + "placeholderKey=" + placeHolderKey, _baseAddress); if (placeholderChrome.HasValue) { output.AppendHtmlLine(placeholderChrome.Value.Start); } } foreach (var rendering in pageData.Renderings.Where(r => usedName.Equals(r.Placeholder, StringComparison.OrdinalIgnoreCase) || placeHolderKey.Equals(r.Placeholder, StringComparison.OrdinalIgnoreCase))) { if (viewContext.HttpContext.IsInCmsMode() && rendering.RenderingChrome != null) { output.AppendHtmlLine(rendering.RenderingChrome.Value.Start); } JToken path = null; if (rendering.RenderingItem.TryGetValue("Path", out path)) { await RenderPartialView(path.Value <string>(), rendering, output, viewContext, pageData); } else { JToken controller = null; JToken controllerAction = null; if (rendering.RenderingItem.TryGetValue("Controller", out controller) && rendering.RenderingItem.TryGetValue("Controller Action", out controllerAction)) { await RenderControllerAction(controller.Value <string>(), controllerAction.Value <string>(), rendering, output, viewContext, pageData); } } if (viewContext.HttpContext.IsInCmsMode() && rendering.RenderingChrome != null) { output.AppendHtmlLine(rendering.RenderingChrome.Value.End); } } if (placeholderChrome.HasValue) { output.AppendHtmlLine(placeholderChrome.Value.End); } placeholderStack.Pop(); }
/// <inheritdoc /> public void CopyTo(IHtmlContentBuilder destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } destination.AppendHtml(Name); if (ValueStyle == HtmlAttributeValueStyle.Minimized) { return; } var valuePrefix = GetAttributeValuePrefix(ValueStyle); if (valuePrefix != null) { destination.AppendHtml(valuePrefix); } string valueAsString; IHtmlContentContainer valueAsHtmlContainer; IHtmlContent valueAsHtmlContent; if ((valueAsString = Value as string) != null) { destination.Append(valueAsString); } else if ((valueAsHtmlContainer = Value as IHtmlContentContainer) != null) { valueAsHtmlContainer.CopyTo(destination); } else if ((valueAsHtmlContent = Value as IHtmlContent) != null) { destination.AppendHtml(valueAsHtmlContent); } else if (Value != null) { destination.Append(Value.ToString()); } var valueSuffix = GetAttributeValueSuffix(ValueStyle); if (valueSuffix != null) { destination.AppendHtml(valueSuffix); } }