private IWriteResult WritePageBody(IRenderContext context)
        {
            var result = WriteResult.Continue();
            var html   = context.Html;

            var bodyClassNames = BodyClassNames;

            if (!string.IsNullOrEmpty(BodyStyle))
            {
                _dependencies.NameManager.EnsureAssetName(this, ref _bodyStyleName);

                if (string.IsNullOrEmpty(bodyClassNames))
                {
                    bodyClassNames = _bodyStyleName;
                }
                else
                {
                    bodyClassNames += " " + _bodyStyleName;
                }
            }

            if (string.IsNullOrEmpty(bodyClassNames))
            {
                html.WriteOpenTag("body");
            }
            else
            {
                html.WriteOpenTag("body", "class", bodyClassNames);
            }
            html.WriteLine();

            result.Add(WritePageArea(context, PageArea.Body));
            result.Add(WritePageArea(context, PageArea.Initialization));

            html.WriteCloseTag("body");
            html.WriteLine();

            return(result);
        }
        private IWriteResult WritePageHead(IRenderContext context)
        {
            var result = WriteResult.Continue();
            var html   = context.Html;

            html.WriteOpenTag("head");
            html.WriteLine();

            html.WriteOpenTag("title");
            result.Add(WritePageArea(context, PageArea.Title));
            html.WriteCloseTag("title");
            html.WriteLine();

            result.Add(WritePageArea(context, PageArea.Head));
            result.Add(WritePageArea(context, PageArea.Styles));
            result.Add(WritePageArea(context, PageArea.Scripts));

            html.WriteCloseTag("head");
            html.WriteLine();

            return(result);
        }
        public override IWriteResult WriteStaticJavascript(IJavascriptWriter writer)
        {
            var writeResult = WriteResult.Continue();

            if (!ReferenceEquals(_pageComponents, null))
            {
                for (var i = 0; i < _pageComponents.Length; i++)
                {
                    var pageComponent = _pageComponents[i];
                    if (writeResult.Add(pageComponent.WriteStaticJavascript(writer)).IsComplete)
                    {
                        return(writeResult);
                    }
                }
            }

            if (!ReferenceEquals(_layout, null))
            {
                writeResult.Add(_layout.WriteStaticJavascript(writer));
            }

            return(writeResult);
        }
        /// <summary>
        /// Override this method to take over how the head part of
        /// the page is written
        /// </summary>
        public virtual IWriteResult WriteHeadArea(IRenderContext context)
        {
            var html = context.Html;

            if (CanonicalUrlFunc != null)
            {
                html.WriteUnclosedElement(
                    "link",
                    "rel", "canonical",
                    "href", CanonicalUrlFunc(context));
                html.WriteLine();
            }

            var websiteStylesUrl = _dependencies.AssetManager.GetWebsiteAssetUrl(AssetType.Style);

            if (websiteStylesUrl != null)
            {
#if TRACE
                context.Trace(() => "Writing link to website css " + websiteStylesUrl);
#endif
                html.WriteUnclosedElement(
                    "link",
                    "rel", "stylesheet",
                    "type", "text/css",
                    "href", websiteStylesUrl.ToString());
                html.WriteLine();
            }

            if (_referencedModules != null && _referencedModules.Count > 0)
            {
#if TRACE
                context.Trace(() => "Writing links to css for referenced modules");
                context.TraceIndent();
#endif
                foreach (var module in _referencedModules)
                {
                    var moduleStylesUrl = _dependencies.AssetManager.GetModuleAssetUrl(module, AssetType.Style);
                    if (moduleStylesUrl != null)
                    {
#if TRACE
                        context.Trace(() => "Writing link to css for module " + moduleStylesUrl);
#endif
                        html.WriteUnclosedElement(
                            "link",
                            "rel", "stylesheet",
                            "type", "text/css",
                            "href", moduleStylesUrl.ToString());
                        html.WriteLine();
                    }
                }
#if TRACE
                context.TraceOutdent();
#endif
            }

            var pageStylesUrl = _dependencies.AssetManager.GetPageAssetUrl(this, AssetType.Style);
            if (pageStylesUrl != null)
            {
#if TRACE
                context.Trace(() => "Writing links to page specific css " + pageStylesUrl);
#endif
                html.WriteUnclosedElement(
                    "link",
                    "rel", "stylesheet",
                    "type", "text/css",
                    "href", pageStylesUrl.ToString());
                html.WriteLine();
            }

            var websiteScriptUrl = _dependencies.AssetManager.GetWebsiteAssetUrl(AssetType.Script);
            if (websiteScriptUrl != null)
            {
#if TRACE
                context.Trace(() => "Writing link to website JavaScript " + websiteScriptUrl);
#endif
                html.WriteElement(
                    "script", null,
                    "type", "text/javascript",
                    "src", websiteScriptUrl.ToString());
                html.WriteLine();
            }

            if (_referencedModules != null && _referencedModules.Count > 0)
            {
#if TRACE
                context.Trace(() => "Writing links to JavaScript for referenced modules");
                context.TraceIndent();
#endif

                foreach (var module in _referencedModules)
                {
                    var moduleScriptUrl = _dependencies.AssetManager.GetModuleAssetUrl(module, AssetType.Script);
                    if (moduleScriptUrl != null)
                    {
#if TRACE
                        context.Trace(() => "Writing link to JavaScript for module " + moduleScriptUrl);
#endif
                        html.WriteElement(
                            "script", null,
                            "type", "text/javascript",
                            "src", moduleScriptUrl.ToString());
                        html.WriteLine();
                    }
                }

#if TRACE
                context.TraceOutdent();
#endif
            }

            var pageScriptUrl = _dependencies.AssetManager.GetPageAssetUrl(this, AssetType.Script);
            if (pageScriptUrl != null)
            {
#if TRACE
                context.Trace(() => "Writing link to page specific JavaScript " + pageScriptUrl);
#endif
                html.WriteElement(
                    "script", null,
                    "type", "text/javascript",
                    "src", pageScriptUrl.ToString());
                html.WriteLine();
            }

            if (!ReferenceEquals(_layout, null))
            {
                return(_layout.WritePageArea(context, PageArea.Head));
            }

            return(WriteResult.Continue());
        }
        /// <summary>
        /// Override this method to take over how the styles part of
        /// the page head is written
        /// </summary>
        public virtual IWriteResult WriteScriptsArea(IRenderContext renderContext)
        {
#if TRACE
            renderContext.Trace(() => "Writing JavaScript functions");
            renderContext.TraceIndent();
#endif
            var html = renderContext.Html;

            if (_inPageScriptLines == null || _inPageScriptLines.Count == 0)
            {
#if TRACE
                renderContext.Trace(() => "page has no static JavaScript");
#endif
            }
            else
            {
#if TRACE
                renderContext.Trace(() => "page has " + _inPageScriptLines.Count + " lines of static JavaScript");
#endif
                if (renderContext.IncludeComments)
                {
                    html.WriteComment("static in-page javascript");
                }

                html.WriteScriptOpen();

                foreach (var line in _inPageScriptLines)
                {
                    html.WriteLine(line);
                }

                html.WriteScriptClose();
            }

            using (var javascriptWriter = _dependencies.JavascriptWriterFactory.Create())
            {
                var writeResult = WriteResult.Continue();

                if (!ReferenceEquals(_pageComponents, null) && _pageComponents.Length > 0)
                {
#if TRACE
                    renderContext.Trace(() => _pageComponents.Length + " non-visual components");
#endif
                    for (var i = 0; i < _pageComponents.Length; i++)
                    {
                        var pageComponent = _pageComponents[i];
                        writeResult.Add(pageComponent.WriteScripts(javascriptWriter));
                    }
                }

                if (!ReferenceEquals(_layout, null))
                {
#if TRACE
                    renderContext.Trace(() => "layout JavaScript");
#endif
                    writeResult.Add(_layout.WriteScripts(javascriptWriter));
                }

                writeResult.Wait();

                if (javascriptWriter.HasContent)
                {
#if TRACE
                    renderContext.Trace(() => "page has dynamic JavaScript");
#endif
                    if (renderContext.IncludeComments)
                    {
                        html.WriteComment("dynamic javascript");
                    }

                    html.WriteScriptOpen();
                    javascriptWriter.ToHtml(html);
                    html.WriteScriptClose();
                }
                else
                {
#if TRACE
                    renderContext.Trace(() => "page does not have any dynamic JavaScript");
#endif
                }
            }

#if TRACE
            renderContext.TraceOutdent();
#endif

            if (!ReferenceEquals(_layout, null))
            {
                return(_layout.WritePageArea(renderContext, PageArea.Scripts));
            }

            return(WriteResult.Continue());
        }
        public virtual IWriteResult WriteStylesArea(IRenderContext renderContext)
        {
#if TRACE
            renderContext.Trace(() => "Writing styles");
            renderContext.TraceIndent();
#endif
            var html = renderContext.Html;

            if (_inPageCssLines == null || _inPageCssLines.Count == 0)
            {
#if TRACE
                renderContext.Trace(() => "page has no static CSS");
#endif
            }
            else
            {
#if TRACE
                renderContext.Trace(() => _inPageCssLines.Count + " lines of static in-page styles");
#endif
                if (renderContext.IncludeComments)
                {
                    html.WriteComment("static in-page styles");
                }

                html.WriteOpenTag("style");
                html.WriteLine();

                foreach (var line in _inPageCssLines)
                {
                    html.WriteLine(line);
                }

                html.WriteCloseTag("style");
                html.WriteLine();
            }

            using (var cssWriter = _dependencies.CssWriterFactory.Create())
            {
                var writeResult = WriteResult.Continue();

                if (!ReferenceEquals(_pageComponents, null))
                {
#if TRACE
                    renderContext.Trace(() => _pageComponents.Length + " non-visual components");
#endif
                    for (var i = 0; i < _pageComponents.Length; i++)
                    {
                        var pageComponent = _pageComponents[i];
                        writeResult.Add(pageComponent.WriteStyles(cssWriter));
                    }
                }

                if (!ReferenceEquals(_layout, null))
                {
#if TRACE
                    renderContext.Trace(() => "layout styles");
#endif
                    writeResult.Add(_layout.WriteStyles(cssWriter));
                }

                writeResult.Wait();

                if (cssWriter.HasContent)
                {
#if TRACE
                    renderContext.Trace(() => "page has dynamic styles");
#endif
                    if (renderContext.IncludeComments)
                    {
                        html.WriteComment("dynamic styles");
                    }

                    html.WriteOpenTag("style");
                    html.WriteLine();

                    cssWriter.ToHtml(html);

                    html.WriteCloseTag("style");
                    html.WriteLine();
                }
                else
                {
#if TRACE
                    renderContext.Trace(() => "page does not have any dynamic styles");
#endif
                }
            }

#if TRACE
            renderContext.TraceOutdent();
#endif

            if (!ReferenceEquals(_layout, null))
            {
                return(_layout.WritePageArea(renderContext, PageArea.Styles));
            }

            return(WriteResult.Continue());
        }
        public virtual IWriteResult WritePageArea(
            IRenderContext renderContext,
            PageArea pageArea)
        {
            var writeResult = WriteResult.Continue();

#if TRACE
            renderContext.Trace(() => "Writing the page " + Enum.GetName(typeof(PageArea), pageArea));
            renderContext.TraceIndent();

            try
            {
#endif
            if (pageArea == PageArea.Title)
            {
                if (ReferenceEquals(TitleFunc, null))
                {
                    if (_layout != null)
                    {
                        writeResult.Add(_layout.WritePageArea(renderContext, PageArea.Title));
                    }
                }
                else
                {
                    renderContext.Html.Write(TitleFunc(renderContext));
                    return(writeResult);
                }
            }

            switch (pageArea)
            {
            case PageArea.Head:
                writeResult.Add(WriteHeadArea(renderContext));
                break;

            case PageArea.Styles:
                writeResult.Add(WriteStylesArea(renderContext));
                break;

            case PageArea.Scripts:
                writeResult.Add(WriteScriptsArea(renderContext));
                break;

            case PageArea.Body:
                writeResult.Add(WriteBodyArea(renderContext));
                break;

            case PageArea.Initialization:
                writeResult.Add(WriteInitializationArea(renderContext));
                break;
            }

            if (!ReferenceEquals(_pageComponents, null))
            {
                for (var i = 0; i < _pageComponents.Length; i++)
                {
                    var pageComponent = _pageComponents[i];
                    if (writeResult.Add(pageComponent.WritePageArea(renderContext, pageArea)).IsComplete)
                    {
                        return(writeResult);
                    }
                }
            }
#if TRACE
        }

        finally
        {
            renderContext.TraceOutdent();
        }
#endif
            return(writeResult);
        }
Exemple #8
0
 public virtual IWriteResult WriteInitializationArea(IRenderContext renderContext)
 {
     return(WriteResult.Continue());
 }
Exemple #9
0
 public virtual IWriteResult WriteBodyArea(IRenderContext renderContext)
 {
     return(WriteResult.Continue());
 }
Exemple #10
0
 public IWriteResult WriteStaticJavascript(IJavascriptWriter writer)
 {
     return(WriteResult.Continue());
 }
Exemple #11
0
 public IWriteResult WriteStaticCss(ICssWriter writer)
 {
     return(WriteResult.Continue());
 }