예제 #1
0
        public void CanRenderOnlyIfFileMissing()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetFileExists(false);

            cssBundle
            .Add("/css/first.css")
            .RenderOnlyIfOutputFileMissing()
            .Render("~/css/can_render_only_if_file_missing.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\can_render_only_if_file_missing.css")]);

            cssBundleFactory.FileReaderFactory.SetContents(css2);
            cssBundleFactory.FileReaderFactory.SetFileExists(true);
            cssBundle.ClearCache();

            cssBundle
            .Add("/css/first.css")
            .RenderOnlyIfOutputFileMissing()
            .Render("~/css/can_render_only_if_file_missing.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\can_render_only_if_file_missing.css")]);
        }
예제 #2
0
        public void CanRerenderFiles()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetFileExists(false);

            cssBundle.ClearCache();
            cssBundle
            .Add("/css/first.css")
            .Render("~/css/can_rerender_files.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\can_rerender_files.css"]);

            ICssBundle cssBundle2 = cssBundleFactory
                                    .WithDebuggingEnabled(false)
                                    .WithContents(css2)
                                    .Create();

            cssBundleFactory.FileReaderFactory.SetFileExists(true);
            cssBundleFactory.FileWriterFactory.Files.Clear();
            cssBundle.ClearCache();

            cssBundle2
            .Add("/css/first.css")
            .Render("~/css/can_rerender_files.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\can_rerender_files.css"]);
        }
예제 #3
0
        public void CanRenderDebugTagsTwice()
        {
            ICssBundle cssBundle1 = cssBundleFactory
                                    .WithDebuggingEnabled(true)
                                    .WithContents(css)
                                    .Create();

            ICssBundle cssBundle2 = cssBundleFactory
                                    .WithDebuggingEnabled(true)
                                    .WithContents(css)
                                    .Create();

            string tag1 = cssBundle1
                          .Add("/css/first.css")
                          .Add("/css/second.css")
                          .Render("/css/output.css");

            string tag2 = cssBundle2
                          .Add("/css/first.css")
                          .Add("/css/second.css")
                          .Render("/css/output.css");

            Assert.AreEqual(tag1, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />");
            Assert.AreEqual(tag2, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />");
        }
예제 #4
0
        public void CanRenderCssFileWithImportStatement()
        {
            string importCss =
                @"
                                    @import url(""/css/other.css"");
                                    #header {
                                        color: #4D926F;
                                    }";


            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(importCss)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetContents(importCss);
            cssBundleFactory.FileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff}");

            string tag = cssBundle
                         .Add("/css/first.css")
                         .ProcessImports()
                         .Render("/css/processed_import.css");

            Assert.AreEqual("#footer{color:#fff}#header{color:#4d926f}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\processed_import.css"]);
        }
        public void SetUp()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);

            jsFileWriterFactory  = new StubFileWriterFactory();
            jsFileReaderFactory  = new StubFileReaderFactory();
            cssFileWriterFactory = new StubFileWriterFactory();
            cssFileReaderFactory = new StubFileReaderFactory();

            jsFileReaderFactory.SetContents(javaScript);
            jsFileReaderFactory.SetPackagedFileNameExists(true);
            jsFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.js");

            cssFileReaderFactory.SetContents(css);
            cssFileReaderFactory.SetPackagedFileNameExists(true);
            cssFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.css");

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                    jsFileWriterFactory,
                                                    jsFileReaderFactory);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                     jsFileWriterFactory,
                                                     jsFileReaderFactory);

            cssBundle = new CssBundle(nonDebugStatusReader, cssFileWriterFactory, cssFileReaderFactory);

            Bundle.PackageJavaScript = true;
            Bundle.PackageCss        = true;
        }
        public void SetUp()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);

            jsFileWriterFactory = new StubFileWriterFactory();
            jsFileReaderFactory = new StubFileReaderFactory();
            cssFileWriterFactory = new StubFileWriterFactory();
            cssFileReaderFactory = new StubFileReaderFactory();

            jsFileReaderFactory.SetContents(javaScript);
            jsFileReaderFactory.SetPackagedFileNameExists(true);
            jsFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.js");

            cssFileReaderFactory.SetContents(css);
            cssFileReaderFactory.SetPackagedFileNameExists(true);
            cssFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.css");

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                    jsFileWriterFactory,
                                                    jsFileReaderFactory);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                     jsFileWriterFactory,
                                                     jsFileReaderFactory);

            cssBundle = new CssBundle(nonDebugStatusReader, cssFileWriterFactory, cssFileReaderFactory);

            Bundle.PackageJavaScript = true;
            Bundle.PackageCss = true;
        }
예제 #7
0
        public void CanCreateCachedBundleInDebugMode()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("~/css/temp.css")
                         .AsCached("TestCached", "~/static/css/TestCached.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp.css\" />", tag);
        }
예제 #8
0
        public void CanDebugBundleCssWithEmbedded()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .AddEmbeddedResource("/css/first.css", "SquishIt.Tests://EmbeddedResource.Embedded.css")
                         .Render("/css/output_embedded.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" />", tag);
            Assert.AreEqual(0, cssBundleFactory.FileWriterFactory.Files.Count);
        }
예제 #9
0
        public void CanBundleCssWithQueryStringParameter()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithContents(css)
                                   .WithDebuggingEnabled(false)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output_querystring.css?v=1");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_querystring.css?v=1&r=C33D1225DED9D889876CEE87754EE305\" />", tag);
        }
예제 #10
0
        public void CanRenderDebugTagsWithMediaAttribute()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithMedia("screen")
                         .Render("/css/output.css");

            Assert.AreEqual(tag, "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/second.css\" />");
        }
예제 #11
0
        public void CanCreateNamedBundleWithDebug()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            cssBundle
            .Add("~/css/temp1.css")
            .Add("~/css/temp2.css")
            .AsNamed("TestWithDebug", "~/css/output.css");

            string tag = cssBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp1.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp2.css\" />", tag);
        }
예제 #12
0
        public void CanBundleDebugCssWithArbitraryAttributes()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithAttribute("media", "screen")
                         .WithAttribute("test", "other")
                         .Render("/css/css_with_debugattribute_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" test=\"other\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" test=\"other\" href=\"/css/second.css\" />", tag);
        }
예제 #13
0
        public void CanBundleCssWithEmbedded()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .AddEmbeddedResource("/css/first.css", "SquishIt.Tests://EmbeddedResource.Embedded.css")
                         .Render("/css/output_embedded.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_embedded.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\output_embedded.css"]);
        }
예제 #14
0
        public void CanCreateNamedBundle()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            cssBundle
            .Add("~/css/temp.css")
            .AsNamed("Test", "~/css/output.css");

            string tag = cssBundle.RenderNamed("Test");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\output.css")]);
            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
        }
예제 #15
0
        public void CanBundleCssWithLess()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(cssLess)
                                   .Create();

            string tag = cssBundle
                         .Add("~/css/test.less")
                         .Render("~/css/output.css");

            string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\output.css")];

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", tag);
            Assert.AreEqual("#header{color:#4d926f}h2{color:#4d926f}", contents);
        }
예제 #16
0
        public void CanBundleCssWithArbitraryAttributes()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithAttribute("media", "screen")
                         .WithAttribute("test", "other")
                         .Render("/css/css_with_attribute_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" test=\"other\" href=\"/css/css_with_attribute_output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
        }
예제 #17
0
        public void CanCreateCachedBundle()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("~/css/temp.css")
                         .AsCached("TestCached", "~/static/css/TestCached.css");

            string contents = cssBundle.RenderCached("TestCached");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", contents);
            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"static/css/TestCached.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
        }
예제 #18
0
        public void CanBundleCssWithRemote()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .AddRemote("/css/first.css", "http://www.someurl.com/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output_remote.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.someurl.com/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_remote.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\output_remote.css")]);
        }
예제 #19
0
        public void CanRenderCssFileWithHashInFileName()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output_#.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_C33D1225DED9D889876CEE87754EE305.css\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\output_C33D1225DED9D889876CEE87754EE305.css"]);
        }
예제 #20
0
        public void CanBundleCssWithLessWithLessDotCssFileExtension()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(cssLess)
                                   .Create();

            string tag = cssBundle
                         .Add("~/css/test.less.css")
                         .Render("~/css/output_less_dot_css.css");

            string contents = cssBundleFactory.FileWriterFactory.Files[@"C:\css\output_less_dot_css.css"];

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output_less_dot_css.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", tag);
            Assert.AreEqual("#header{color:#4d926f}h2{color:#4d926f}", contents);
        }
예제 #21
0
        public void CanBundleCss()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetContents(css);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\output.css")]);
        }
예제 #22
0
        public void CanBundleCssWithCompressorAttribute()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithCompressor(CssCompressors.YuiCompressor)
                         .Render("/css/css_with_compressor_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_compressor_output.css?r=23D6019A4B502913579DE4BB98131201\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}\nth{font-weight:normal;vertical-align:bottom}\n.FloatRight{float:right}\n.FloatLeft{float:left}\nli{margin-bottom:.1em;margin-left:0;margin-top:.1em}\nth{font-weight:normal;vertical-align:bottom}\n.FloatRight{float:right}\n.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\css_with_compressor_output.css"]);
        }
예제 #23
0
        public void CanBundleCssWithNullCompressorAttribute()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithCompressor(CssCompressors.NullCompressor)
                         .Render("/css/css_with_null_compressor_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_null_compressor_output.css?r=54F52AC95333FEFD5243AC373F573A07\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual(css + "\n" + css + "\n", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\css_with_null_compressor_output.css")]);
        }
예제 #24
0
        public void CanBundleCssWithNullCompressorAttribute()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithCompressor(CssCompressors.NullCompressor)
                         .Render("/css/css_with_null_compressor_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_null_compressor_output.css?r=B79161F2F4979E630DBB09E482976D5F\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual(css + "\n" + css + "\n", cssBundleFactory.FileWriterFactory.Files[@"C:\css\css_with_null_compressor_output.css"]);
        }
예제 #25
0
        public void CanCreateNamedBundleWithForceRelease()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(true)
                                   .WithContents(css)
                                   .Create();

            cssBundle
            .Add("~/css/temp.css")
            .ForceRelease()
            .AsNamed("TestForce", "~/css/named_withforce.css");

            string tag = cssBundle.RenderNamed("TestForce");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\named_withforce.css"]);
            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/named_withforce.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
        }
        /// <summary>
        /// Minify the css into one file
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="filenames">The filenames.</param>
        /// <param name="outputPathandFilename">The output pathand filename.</param>
        /// <returns></returns>
        public static string Css(this HtmlHelper helper, IEnumerable <string> filenames, string outputPathandFilename)
        {
            ICssBundle        bundle  = Bundle.Css();
            ICssBundleBuilder builder = null;

            foreach (string filename in filenames)
            {
                if (builder == null)
                {
                    builder = bundle.Add(filename);
                }
                else
                {
                    builder.Add(filename);
                }
            }

            return(builder != null ? builder.Render(outputPathandFilename) : string.Empty);
        }
예제 #27
0
        public void CanBundleCssWithCompressorInstance()
        {
            ICssBundle cssBundle = cssBundleFactory
                                   .WithHasher(hasher)
                                   .WithDebuggingEnabled(false)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetContents(css);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithCompressor(new MsCompressor())
                         .Render("/css/compressor_instance.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/compressor_instance.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag);
            Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[@"C:\css\compressor_instance.css"]);
        }
예제 #28
0
        public void CanRenderCssFileWithImportStatementUppercase()
        {
            string importCss =
                @"
                                    @IMPORT URL(/css/other.css);
                                    #header {
                                        color: #4D926F;
                                    }";

            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(importCss)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetContentsForFile(TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\other.css"), "#footer{color:#ffffff}");

            string tag = cssBundle
                         .Add("/css/first.css")
                         .ProcessImports()
                         .Render("/css/processed_import_uppercase.css");

            Assert.AreEqual("#footer{color:#fff}#header{color:#4d926f}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\processed_import_uppercase.css")]);
        }
예제 #29
0
        public void CanRenderCssFileWithUnprocessedImportStatement()
        {
            string importCss =
                @"
                                    @import url(""/css/other.css"");
                                    #header {
                                        color: #4D926F;
                                    }";

            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(importCss)
                                   .Create();

            cssBundleFactory.FileReaderFactory.SetContents(importCss);
            cssBundleFactory.FileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff}");

            cssBundle
            .Add("/css/first.css")
            .Render("/css/unprocessed_import.css");

            Assert.AreEqual(@"@import url(""/css/other.css"");#header{color:#4d926f}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\css\unprocessed_import.css")]);
        }
예제 #30
0
        public void CanBundleCssWithLessAndPathRewrites()
        {
            string css =
                @"@brand_color: #4D926F;
                        #header {
                            color: @brand_color;
                            background-image: url(../image/mygif.gif);
                        }
                    ";

            ICssBundle cssBundle = cssBundleFactory
                                   .WithDebuggingEnabled(false)
                                   .WithContents(css)
                                   .Create();

            string tag = cssBundle
                         .Add("~/css/something/test.less")
                         .Render("~/css/output_less_with_rewrites.css");

            string contents = cssBundleFactory.FileWriterFactory.Files[@"C:\css\output_less_with_rewrites.css"];

            Assert.AreEqual("#header{color:#4d926f;background-image:url(image/mygif.gif)}", contents);
        }
예제 #31
0
 public static MvcHtmlString RenderNamedMvc(this ICssBundle cssBundle, string name)
 {
     return(MvcHtmlString.Create(cssBundle.RenderNamed(name)));
 }