Esempio n. 1
0
 private static void RenderMeta(HtmlHelper helper, CmsPageContext context, StringBuilder output)
 {
     foreach (var scripts in context.Meta())
     {
         var tag = new TagBuilder("meta");
         tag.MergeAttributes(scripts.Attributes);
         output.AppendLine(tag.ToString(TagRenderMode.SelfClosing));
     }
 }
Esempio n. 2
0
        public static CmsPageContext Build(this CmsPageContext context, Page page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            context.Alias = page.Alias;
            context.Title = page.Title;

            // Build widgets
            foreach (Widget widget in page.Widgets)
            {
                context.Widgets.Add(new CmsWidgetContext
                {
                    ID          = widget.ID.ToString(),
                    Ordinal     = widget.Ordinal,
                    PageContext = context,
                    Section     = widget.Section,
                    Title       = widget.Title,
                    RouteData   = GetValues(widget.WidgetData)
                });
            }

            // Build resources
            foreach (var resource in page.Resources)
            {
                context.Resources.Add(new PageResourceContext(resource.Tag).Build(resource));
            }

            if (page.Parent != null)
            {
                context.Parent = context.Build(page.Parent);
            }

            if (page.Template != null)
            {
                context.Template = new CmsPageTemplateContext {
                    Title = page.Template.Title
                };
                foreach (Widget widget in page.Template.Widgets)
                {
                    context.Widgets.Add(new CmsWidgetContext
                    {
                        ID               = widget.ID.ToString(),
                        Ordinal          = widget.Ordinal,
                        Section          = widget.Section,
                        Title            = widget.Title,
                        PageContext      = context,
                        IsTemplateWidget = true,
                        RouteData        = GetValues(widget.WidgetData)
                    });
                }
            }

            return(context);
        }
Esempio n. 3
0
        public static IList <CmsWidgetContext> AllWidgets(this CmsPageContext context)
        {
            var all = new List <CmsWidgetContext>();

            if (context.Template != null)
            {
                all.AddRange(context.Template.Widgets);
            }
            all.AddRange(context.Widgets);
            return(all);
        }
Esempio n. 4
0
        private static string GetUrl(CmsPageContext context)
        {
            var          sb        = new StringBuilder();
            const string separator = "/";

            sb.AppendFormat("{0}{1}", separator, context.Alias);
            CmsPageContext parent = context.Parent;

            while (parent != null)
            {
                sb.Insert(0, String.Format("{0}{1}", separator, parent.Alias));
                parent = parent.Parent;
            }
            string url = sb.ToString();

            return(url.EndsWith("/") ? url : string.Concat(url, "/"));
        }
Esempio n. 5
0
        private static void RenderStyles(HtmlHelper helper, CmsPageContext context, StringBuilder output)
        {
            foreach (var scripts in context.Styles())
            {
                var tag = new TagBuilder("link");
                tag.MergeAttributes(scripts.Attributes);
                output.AppendLine(tag.ToString(TagRenderMode.SelfClosing));
            }

            // render style reference css page layout editing
            if (context.Mode != CmsPageContextMode.View)
            {
                var editStyle = new TagBuilder("link");
                editStyle.MergeAttribute("rel", "stylesheet");
                editStyle.MergeAttribute("href", String.Format("/areas{0}/style/page.css", _config.XilionPath));
                output.AppendLine(editStyle.ToString(TagRenderMode.SelfClosing));
            }
        }
Esempio n. 6
0
        private static void RenderScripts(HtmlHelper helper, CmsPageContext context, StringBuilder output,
                                          PageResourceScope scope)
        {
            foreach (var scripts in context.Scripts().Where(x => x.Scope == scope))
            {
                var tag = new TagBuilder("script");
                tag.MergeAttributes(scripts.Attributes);
                output.AppendLine(tag.ToString());
            }

            // render require script reference with data for page layout editing
            if (scope == PageResourceScope.Body && context.Mode != CmsPageContextMode.View)
            {
                var editScript = new TagBuilder("script");
                editScript.MergeAttribute("type", "text/javascript");
                editScript.MergeAttribute("src", string.Format("{0}/bundles/page", _config.XilionPath));
                output.AppendLine(editScript.ToString());
            }
        }
Esempio n. 7
0
 public static IList <CmsWidgetContext> SectionWidgets(this CmsPageContext context, string section)
 {
     return(context.AllWidgets()
            .Where(x => x.Section.Equals(section, StringComparison.InvariantCultureIgnoreCase))
            .OrderBy(x => x.Ordinal).ToList());
 }
Esempio n. 8
0
 public static string Url(this CmsPageContext context)
 {
     return(GetUrl(context));
 }
Esempio n. 9
0
 public static IList <PageResourceContext> Meta(this CmsPageContext context)
 {
     return(context.Resources.Where(x => x.ResourceType == PageResourceType.Meta).ToList());
 }
Esempio n. 10
0
 private static void RenderFooter(HtmlHelper helper, CmsPageContext context, StringBuilder output)
 {
     RenderScripts(helper, context, output, PageResourceScope.Body);
 }
Esempio n. 11
0
 private static void RenderHead(HtmlHelper helper, CmsPageContext context, StringBuilder output)
 {
     RenderMeta(helper, context, output);
     RenderStyles(helper, context, output);
     RenderScripts(helper, context, output, PageResourceScope.Head);
 }