Esempio n. 1
0
 public BreadcrumbHelper(
     IPageDataContextRetriever pageDataContextRetriever,
     IPageUrlRetriever pageUrlRetriever,
     IBreadcrumbsRenderer breadcrumbsRenderer,
     IPageRetriever pageRetriever,
     BreadcrumbsWidgetProperties breadcrumbsWidgetProperties)
 {
     this.pageDataContextRetriever = pageDataContextRetriever;
     this.pageUrlRetriever         = pageUrlRetriever;
     this.breadcrumbsRenderer      = breadcrumbsRenderer;
     this.pageRetriever            = pageRetriever;
     Properties = breadcrumbsWidgetProperties;
 }
Esempio n. 2
0
        private IHtmlContent GetBreadcrumbContent(BreadcrumbsWidgetProperties props)
        {
            if (props is null)
            {
                throw new ArgumentNullException(nameof(props));
            }

            var current   = pageDataContextRetriever.Retrieve <TreeNode>().Page;
            var hierarchy = CacheHelper.Cache((cs) => {
                ICollection <string> cacheDependencies = new List <string>();
                var list           = GetHierarchy(current, props.ShowSiteLink, props.ShowContainers, ref cacheDependencies);
                cs.CacheDependency = CacheHelper.GetCacheDependency(cacheDependencies);
                return(list);
            }, new CacheSettings(120, GetCacheKey(current.DocumentID, props.ShowSiteLink, props.ShowContainers)));

            var header = breadcrumbsRenderer.RenderOpeningTag(props.ContainerClass);
            var footer = breadcrumbsRenderer.RenderClosingTag();
            var sb     = new StringBuilder();

            foreach (BreadcrumbItem bci in hierarchy)
            {
                sb.Append(breadcrumbsRenderer.RenderSeparator(props.Separator));
                if (bci.IsCurrentPage)
                {
                    sb.Append(breadcrumbsRenderer.RenderCurrentPage(bci, props.BreadcrumbItemClass, props.CurrentPageClass));
                }
                else if (bci.IsSiteLink)
                {
                    sb.Append(breadcrumbsRenderer.RenderSiteLink(bci, props.BreadcrumbItemClass));
                }
                else if (string.IsNullOrEmpty(bci.Url))
                {
                    sb.Append(breadcrumbsRenderer.RenderItemWithoutLink(bci, props.BreadcrumbItemClass));
                }
                else
                {
                    sb.Append(breadcrumbsRenderer.RenderItem(bci, props.BreadcrumbItemClass));
                }
            }

            // Remove first separator
            var body = TrimSeparator(sb.ToString().Trim(), props.Separator);

            return(new HtmlString($"{header}{body}{footer}"));
        }
        public static void AddBreadcrumbs(
            this IServiceCollection services,
            Action <BreadcrumbsWidgetProperties> configure = null,
            IBreadcrumbsRenderer renderer = null)
        {
            services.AddSingleton <BreadcrumbHelper>();

            // Register renderer
            if (renderer is null)
            {
                renderer = new DefaultBreadcrumbsRenderer();
            }
            services.AddSingleton(renderer);

            // Register widget properties
            var props = new BreadcrumbsWidgetProperties().SetDefaults();

            if (configure is object)
            {
                configure(props);
            }
            services.AddSingleton(props);
        }
Esempio n. 4
0
 /// <summary>
 /// Returns breadrumb HTML using the manually provided BreadcrumbsWidgetProperties
 /// </summary>
 /// <param name="props"></param>
 /// <returns></returns>
 public IHtmlContent GetBreadcrumbs(BreadcrumbsWidgetProperties props)
 {
     return(GetBreadcrumbContent(props));
 }