Beispiel #1
0
 void CallModifiers(XDocument html, IReadOnlyPage page)
 {
     foreach (var modifier in modifiers)
     {
         modifier.Modify(html, page);
     }
 }
 XElement GetLinkOrSpan(IReadOnlyPage page, IReadOnlyPage currentPage)
 {
     if (page.Path == currentPage.Path)
     {
         return new XElement("span", page.NavigationText);
     }
     else
     {
         return new XElement("a", new XAttribute("href", UrlBase + page.Path), page.NavigationText);
     }
 }
 XElement SubMenu(IReadOnlyPage page, IReadOnlyPage currentPage, int level)
 {
     if (IsUserAdmin || page.Count(c => c.Navigation) > 0)
     {
         return new XElement("ul", BuildMenu(page, currentPage, level));
     }
     else
     {
         return null;
     }
 }
Beispiel #4
0
 XElement GetLinkOrSpan(IReadOnlyPage page, IReadOnlyPage currentPage)
 {
     if (page.Path == currentPage.Path)
     {
         return(new XElement("span", page.NavigationText));
     }
     else
     {
         return(new XElement("a", new XAttribute("href", UrlBase + page.Path), page.NavigationText));
     }
 }
Beispiel #5
0
 XElement SubMenu(IReadOnlyPage page, IReadOnlyPage currentPage, int level)
 {
     if (IsUserAdmin || page.Count(c => c.Navigation) > 0)
     {
         return(new XElement("ul", BuildMenu(page, currentPage, level)));
     }
     else
     {
         return(null);
     }
 }
 IEnumerable<XElement> BuildMenu(IEnumerable<IReadOnlyPage> pages, IReadOnlyPage currentPage, int level)
 {
     return from page in pages
            where IsUserAdmin || page.Navigation
            select new XElement("li",
                (IsUserAdmin ? new XAttribute("data-path", page.Path) : null),
                new XAttribute("class", "level-" + level + (page.Path == currentPage.Path || page.Contains(currentPage) ? " current" : "")),
                (page.Navigation ? null : new XAttribute("style", "display:none")),
                GetLinkOrSpan(page, currentPage),
                SubMenu(page, currentPage, level + 1)
            );
 }
Beispiel #7
0
 public bool Contains(IReadOnlyPage page)
 {
     foreach (var child in Pages)
     {
         if (child == page)
         {
             return(true);
         }
         if (child.Contains(page))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #8
0
 bool IReadOnlyPage.Contains(IReadOnlyPage page)
 {
     foreach (IReadOnlyPage child in this)
     {
         if (child == page)
         {
             return(true);
         }
         if (child.Contains(page))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
        void AddPageNameClassToBody(IReadOnlyPage page, XDocument html)
        {
            var path     = page.Path.Replace('/', '_');
            var cssClass = "page-" + path;

            var body = html.Root.Element("body");

            if (body.Attribute("class") == null)
            {
                body.Add(new XAttribute("class", cssClass));
            }
            else
            {
                body.Attribute("class").Value += " " + cssClass;
            }
        }
Beispiel #10
0
 IEnumerable <XElement> BuildMenu(IEnumerable <IReadOnlyPage> pages, IReadOnlyPage currentPage, int level)
 {
     return(from page in pages
            where IsUserAdmin || page.Navigation
            let classes = new[] {
         page.Path.Replace('/', '_'),
         "level-" + level,
         (page.Path == currentPage.Path || page.Contains(currentPage) ? "current" : "")
     }
            select new XElement("li",
                                (IsUserAdmin ? new XAttribute("data-path", page.Path) : null),
                                new XAttribute("class", string.Join(" ", classes)),
                                (page.Navigation ? null : new XAttribute("style", "display:none")),
                                GetLinkOrSpan(page, currentPage),
                                SubMenu(page, currentPage, level + 1)
                                ));
 }
Beispiel #11
0
        void AddDescriptionMetaTag(IReadOnlyPage page, XDocument html)
        {
            if (string.IsNullOrEmpty(page.Description)) return;

            var head = html.Root.Element("head");
            var title = head.Element("title");
            var meta = new XElement("meta",
                new XAttribute("name", "description"),
                new XAttribute("content", page.Description));
            if (title != null)
            {
                title.AddAfterSelf(meta);
            }
            else
            {
                head.AddFirst(meta);
            }
        }
Beispiel #12
0
        public IReadOnlyPage FindCurrentPageAtLevel(int level, IReadOnlyPage currentPage)
        {
            if (level < 1)
            {
                throw new ArgumentOutOfRangeException("level", level, "level must be greater than zero.");
            }
            foreach (var page in this)
            {
                if (page == currentPage)
                {
                    return(page);
                }

                var p = FindCurrentPageAtLevel(1, level - 1, page, currentPage);
                if (p != null)
                {
                    return(p);
                }
            }
            return(null);
        }
Beispiel #13
0
        void AddDescriptionMetaTag(IReadOnlyPage page, XDocument html)
        {
            if (string.IsNullOrEmpty(page.Description))
            {
                return;
            }

            var head  = html.Root.Element("head");
            var title = head.Element("title");
            var meta  = new XElement("meta",
                                     new XAttribute("name", "description"),
                                     new XAttribute("content", page.Description));

            if (title != null)
            {
                title.AddAfterSelf(meta);
            }
            else
            {
                head.AddFirst(meta);
            }
        }
Beispiel #14
0
 IReadOnlyPage FindCurrentPageAtLevel(int currentLevel, int wantedLevel, IReadOnlyPage container, IReadOnlyPage currentPage)
 {
     foreach (var page in container)
     {
         if (page == currentPage)
         {
             return((IReadOnlyPage)container);
         }
         if (page.Contains(currentPage))
         {
             if (currentLevel == wantedLevel)
             {
                 return(page);
             }
             else
             {
                 return(FindCurrentPageAtLevel(currentLevel++, wantedLevel, page, currentPage));
             }
         }
     }
     return(null);
 }
Beispiel #15
0
 void CallModifiers(XDocument html, IReadOnlyPage page)
 {
     foreach (var modifier in modifiers)
     {
         modifier.Modify(html, page);
     }
 }
Beispiel #16
0
        void AddPageNameClassToBody(IReadOnlyPage page, XDocument html)
        {
            var path = page.Path.Replace('/','_');
            var cssClass = "page-" + path;

            var body = html.Root.Element("body");
            if (body.Attribute("class") == null)
            {
                body.Add(new XAttribute("class", cssClass));
            }
            else
            {
                body.Attribute("class").Value += " " + cssClass;
            }
        }
 public bool Contains(IReadOnlyPage page)
 {
     return false;
 }
Beispiel #18
0
 public bool Contains(IReadOnlyPage page)
 {
     return(false);
 }