Ejemplo n.º 1
0
 private void AppendFirstPage(IHtmlContentBuilder builder, PaginationData data)
 {
     if (data.Index <= 1)
     {
         builder.AppendHtmlLine($"<li class=\"disabled\"><a href=\"javascript:void(0);\">{this.Text.First}</a></li>");
     }
     else
     {
         builder.AppendHtmlLine($"<li><a href=\"{GenerateUrl(1)}\">{this.Text.First}</a></li>");
     }
 }
Ejemplo n.º 2
0
        private void AppendPage(IHtmlContentBuilder builder, PaginationData data)
        {
            if (data.Index > 1 + data.PrePages)
            {
                builder.AppendHtmlLine("<li class=\"disabled\"><a href=\"javascript:void(0);\">...</a></li>");
            }

            for (var i = Math.Max(1, data.Index - data.PrePages); i < data.Index; ++i)
            {
                builder.AppendHtmlLine($"<li><a href=\"{GenerateUrl(i)}\">{i}</a></li>");
            }

            builder.AppendHtmlLine($"<li class=\"active\"><a>{data.Index}</a></li>");

            for (var i = data.Index + 1; i <= Math.Min(this.Pages, data.Index + data.PostPages); ++i)
            {
                builder.AppendHtmlLine($"<li><a href=\"{GenerateUrl(i)}\">{i}</a></li>");
            }

            if (data.Index < this.Pages - data.PostPages)
            {
                builder.AppendHtmlLine("<li class=\"disabled\"><a href=\"javascript:void(0);\">...</a></li>");
            }
        }
        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);
        }
Ejemplo n.º 4
0
        public static void AppendHtml5(this IHtmlContentBuilder builder, TagBuilder tag)
        {
            IHtmlContent newTag = tag;

            if (tag.TagName == "input")
            {
                newTag = tag.RenderStartTag();
            }

            using var writer = new StringWriter();

            newTag.WriteTo(writer, HtmlEncoder.Default);

            var value = writer.ToString();

            var newValue = value
                           .MakeHtml5("readonly")
                           .MakeHtml5("required")
                           .MakeHtml5("selected")
                           .MakeHtml5("disabled")
                           .MakeHtml5("data-nw-validation");

            builder.AppendHtmlLine(newValue);
        }
Ejemplo n.º 5
0
        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;
            }
        }
 private static IHtmlContentBuilder AppendStyleSheet(this IHtmlContentBuilder content, string path)
 {
     return(content.AppendHtmlLine($"<link href='{path}' rel='stylesheet' />"));
 }
 private static IHtmlContentBuilder AppendJavaScript(this IHtmlContentBuilder content, string path)
 {
     return(content.AppendHtmlLine($"<script src='{path}'></script>"));
 }
        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();
        }