Beispiel #1
0
 private void GetStaticAssets(IElement element, AssetType assetType, IStringBuilder stringBuilder)
 {
     if (assetType == AssetType.Script)
     {
         using (var writer = _javascriptWriterFactory.Create())
         {
             using (var writeResult = element.WriteStaticJavascript(writer))
             {
                 writeResult.Wait();
                 writer.ToStringBuilder(stringBuilder);
             }
         }
     }
     else if (assetType == AssetType.Style)
     {
         using (var writer = _cssWriterFactory.Create())
         {
             using (var writeResult = element.WriteStaticCss(writer))
             {
                 writeResult.Wait();
                 writer.ToStringBuilder(stringBuilder);
             }
         }
     }
 }
Beispiel #2
0
        public void WritePageArea(
            IRenderContext context,
            PageArea pageArea)
        {
            if (_element.AssetDeployment != AssetDeployment.InPage)
            {
                return;
            }

            if (pageArea == PageArea.Styles)
            {
                if (CssRules != null && CssRules.Length > 0)
                {
                    var writer = _cssWriterFactory.Create(context);

                    for (var i = 0; i < CssRules.Length; i++)
                    {
                        CssRules[i](writer);
                    }

                    if (context.IncludeComments)
                    {
                        context.Html.WriteComment("css rules for " + _commentNameFunc());
                    }

                    context.Html.WriteOpenTag("style");
                    context.Html.WriteLine();
                    writer.ToHtml(context.Html);
                    context.Html.WriteCloseTag("style");
                    context.Html.WriteLine();
                }
            }
            else if (pageArea == PageArea.Scripts)
            {
                if (JavascriptFunctions != null && JavascriptFunctions.Length > 0)
                {
                    var writer = _javascriptWriterFactory.Create(context);

                    for (var i = 0; i < JavascriptFunctions.Length; i++)
                    {
                        JavascriptFunctions[i](writer);
                    }

                    if (context.IncludeComments)
                    {
                        context.Html.WriteComment("javascript functions for " + _commentNameFunc());
                    }

                    context.Html.WriteScriptOpen();
                    writer.ToHtml(context.Html);
                    context.Html.WriteScriptClose();
                }
            }
        }