Example #1
0
        protected override void HandleRequest(HttpContext context)
        {
            context.Response.ContentEncoding = Encoding.UTF8;

            string skinName        = context.Request.Params["name"];
            string skinMedia       = context.Request.Params["media"];
            string skinTitle       = context.Request.Params["title"];
            string skinConditional = context.Request.Params["conditional"];

            var styles =
                (List <StyleDefinition>)
                StyleRenderer.GetStylesToBeMerged(skinName, skinMedia, skinTitle, skinConditional);

            //Append all styles into one file

            context.Response.Write(string.Format("/*{0}", Environment.NewLine));
            foreach (StyleDefinition style in styles)
            {
                context.Response.Write(style + Environment.NewLine);
            }
            context.Response.Write(string.Format("*/{0}", Environment.NewLine));

            foreach (StyleDefinition style in styles)
            {
                context.Response.Write(Environment.NewLine + "/* " + style + " */" + Environment.NewLine);
                string path = context.Server.MapPath(style.Href);
                if (File.Exists(path))
                {
                    string cssFile = File.ReadAllText(path);
                    // Normalize path.
                    cssFile = cssFile.Replace("url(../images", "url(../../images");
                    cssFile = cssFile.Replace("url(../Images", "url(../../Images");
                    if (!String.IsNullOrEmpty(style.Media) && styles.Count > 1)
                    {
                        context.Response.Write("@media " + style.Media + "{\r\n");
                        context.Response.Write(cssFile);
                        context.Response.Write("\r\n}");
                    }
                    else
                    {
                        context.Response.Write(cssFile);
                    }
                }
                else
                {
                    context.Response.Write(Environment.NewLine + "/* CSS file at " + path +
                                           " doesn't exist so cannot be included in the merged CSS file. */" +
                                           Environment.NewLine);
                }
            }

            SetHeaders(styles, context);
        }
Example #2
0
        public void MergedCssContainsStyleWithMedia()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer     = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List <StyleDefinition>)renderer.GetStylesToBeMerged("Piyo");

            Assert.IsTrue(mergedStyles.Contains(new StyleDefinition("/Skins/Piyo/print.css", "print")),
                          "Skin Piyo should have the print css in the merged css");
        }
Example #3
0
        public void MergedCssDoesntContainStyleWithMediaAndTitle()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer     = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List <StyleDefinition>)renderer.GetStylesToBeMerged("Piyo");

            Assert.IsFalse(mergedStyles.Contains(new StyleDefinition("/Skins/Piyo/piyo-fixed.css", "screen")),
                           "Skin Piyo should not have the fixed screen css in the merged CSS");
        }
Example #4
0
        public void MergedCssContainsDefaultStyle()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer     = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List <StyleDefinition>)renderer.GetStylesToBeMerged("Submarine");

            Assert.IsTrue(mergedStyles.Contains(new StyleDefinition("/Skins/Submarine/style.css")),
                          "Skin Submarine should have the default style.css");
        }