Ejemplo n.º 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            FindCurrentExample();

            NavigationExample currentExample = ViewBag.CurrentExample;
            NavigationWidget  currentWidget  = ViewBag.CurrentWidget;

            if (currentWidget == null)
            {
                return;
            }

            ViewBag.Description = Description(ViewBag.Product, currentExample, currentWidget);

            var exampleFiles = new List <ExampleFile>();

            exampleFiles.AddRange(SourceCode());
            exampleFiles.AddRange(AdditionalSources(currentWidget.Sources));
            exampleFiles.AddRange(AdditionalSources(currentExample.Sources));
            ViewBag.ExampleFiles = exampleFiles.Where(file => file.Exists(ContentRootPath));

            if (currentWidget.Documentation != null && currentWidget.Documentation.ContainsKey(ViewBag.Product))
            {
                ViewBag.Documentation = "http://docs.telerik.com/aspnet-core/" + currentWidget.Documentation[ViewBag.Product];
            }

            if (currentWidget.Forum != null && currentWidget.Forum.ContainsKey(ViewBag.Product))
            {
                ViewBag.Forum = "http://www.telerik.com/forums/" + currentWidget.Forum[ViewBag.Product];
            }
        }
Ejemplo n.º 2
0
        public static string ProductExampleUrl(this IHtmlHelper html, NavigationExample example, string product)
        {
            var sectionAndExample = example.Url.Split('/');

            var url = string.Join("/", LiveSamplesRoot, product, sectionAndExample[0]);

            return(url);
        }
Ejemplo n.º 3
0
        protected void FindCurrentExample()
        {
            var found = false;

            NavigationExample current       = null;
            NavigationWidget  currentWidget = null;

            foreach (NavigationWidget widget in ViewBag.Navigation)
            {
                foreach (NavigationExample example in widget.Items)
                {
                    if (example.ShouldInclude())
                    {
                        examplesUrl.Add("~/" + example.Url);
                    }

                    if (!found && IsCurrentExample(example.Url))
                    {
                        current       = example;
                        currentWidget = widget;
                        found         = true;
                    }
                }
            }

            ViewBag.CurrentWidget = currentWidget;

            if (currentWidget == null)
            {
                return;
            }

            ViewBag.CurrentExample = current;

            if (current.Title != null)
            {
                if (current.Title.ContainsKey(MvcFlavor.AspNetCore))
                {
                    ViewBag.Title = current.Title[MvcFlavor.AspNetCore];
                }
            }
            else
            {
                ViewBag.Title = current.Text;
            }

            if (current.Meta != null)
            {
                if (current.Meta.ContainsKey(MvcFlavor.AspNetCore))
                {
                    ViewBag.Meta = current.Meta[MvcFlavor.AspNetCore];
                }
            }
        }
Ejemplo n.º 4
0
        protected string Description(string product, NavigationExample example, NavigationWidget widget)
        {
            if (example.Description != null && example.Description.ContainsKey(product))
            {
                return(example.Description[product]);
            }
            else if (widget.Description != null && widget.Description.ContainsKey(product))
            {
                return(widget.Description[product]);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static IHtmlContent ExampleLink(this IHtmlHelper html, NavigationExample example)
        {
            var href = html.ExampleUrl(example);

            var className = "";

            if (example.New)
            {
                className += "new-example";
            }

            if (example.Updated)
            {
                className += "updated-example";
            }

            var routeData         = html.ViewContext.RouteData;
            var currentAction     = routeData.Values["action"].ToString().ToLower().Replace("_", "-");
            var currentController = routeData.Values["controller"].ToString().ToLower().Replace("_", "-");

            if (href.EndsWith(currentController + "/" + currentAction))
            {
                className += " active";
            }

            StringBuilder link = new StringBuilder();

            link.Append("<a ");

            if (!String.IsNullOrEmpty(className))
            {
                link.Append("class=\"" + className + "\" ");
            }

            link.Append("href=\"" + href + "\">");

            if (example.New)
            {
                link.Append("<span class=\"new-widget\"></span>");
            }

            if (example.Updated)
            {
                link.Append("<span class=\"updated-widget\"></span>");
            }

            link.Append(example.Text).Append("</a>");

            return(html.Raw(link.ToString()));
        }
Ejemplo n.º 6
0
        public static string ExampleUrl(this IHtmlHelper html, NavigationExample example)
        {
            var sectionAndExample = example.Url.Split('/');

            return(new UrlHelper(html.ViewContext).ExampleUrl(sectionAndExample[0], sectionAndExample[1]));
        }