public static String Css(String files, Boolean debug) { String name = HelperService.CalculateMD5Hash(files); String path = @"/cache/script/css/"; String FilePath = path + name + ".css"; if (!HelperService.DirExists(path)) { System.IO.Directory.CreateDirectory(path); } CSSBundle css = new CSSBundle(); foreach (string fl in files.Split(',')) { if (File.Exists(HttpContext.Current.Server.MapPath(fl))) { css.Add(fl); } else { } } if (debug) { return(css.ForceRelease().ForceDebug().Render(FilePath)); } else { return(css.ForceRelease().Render(FilePath)); } }
public void WithPreprocessor_Uses_Instance_Preprocessors() { var stylePreprocessor = new StubStylePreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = cssBundle .Add("~/css/test.style.global") .WithPreprocessor(stylePreprocessor) .WithPreprocessor(globalPreprocessor) .Render("~/css/output.css"); string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")]; Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=hash\" />", tag); Assert.AreEqual("styley", contents); Assert.AreEqual("globey", stylePreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); Assert.IsEmpty(Configuration.Instance.Preprocessors.Where(x => !(x is NullPreprocessor))); }
public void Css_Stops_At_First_Extension_With_No_Defined_Preprocessor() { var stylePreprocessor = new StubStylePreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using (new StylePreprocessorScope <StubStylePreprocessor>(stylePreprocessor)) using (new GlobalPreprocessorScope <StubGlobalPreprocessor>(globalPreprocessor)) { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = cssBundle .Add("~/css/test.style.fake.global.bogus") .Render("~/css/output.css"); string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")]; Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=hash\" />", tag); Assert.AreEqual("start", contents); Assert.Null(stylePreprocessor.CalledWith); Assert.Null(globalPreprocessor.CalledWith); } }
public void CanBundleCssWithLessAndPathRewrites() { using (new StylePreprocessorScope <LessPreprocessor> ()) { string css = @"@brand_color: #4D926F; #header { color: @brand_color; background-image: url(../image/mygif.gif); } "; CSSBundle cssBundle = cssBundleFactory .WithDebuggingEnabled(false) .WithContents(css) .Create(); cssBundle .Add("~/css/something/test.less") .Render("~/css/output_less_with_rewrites.css"); string contents = cssBundleFactory.FileWriterFactory.Files[ TestUtilities.PrepareRelativePath(@"css\output_less_with_rewrites.css")]; Assert.AreEqual("#header{color:#4d926f;background-image:url(image/mygif.gif)}", contents); } }
public void CanBundleCssWithNestedLess() { string importCss = @" @import 'other.less'; #header { color: #4D926F; }"; CSSBundle cssBundle = cssBundleFactory .WithDebuggingEnabled(false) .WithContents(importCss) .Create() .WithPreprocessor(new LessPreprocessor()); TestUtilities.CreateFile("other.less", "#footer{color:#ffffff}"); cssBundle .Add("~/css/test.less") .Render("~/css/output_test.css"); TestUtilities.DeleteFile("other.less"); Assert.AreEqual("#footer{color:#fff}#header{color:#4d926f}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output_test.css")]); Assert.Contains(translator.ResolveAppRelativePathToFileSystem("css/other.less"), cssBundle.bundleState.DependentFiles); }
public void CanBundleCssWithLessToRawContentMultiThreaded() { using (new StylePreprocessorScope <LessPreprocessor>()) { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents(cssLess) .Create(); Task <string> taskA = new Task <string>(() => cssBundle.Add("~/css/test.less").RenderRawContent("A")); Task <string> taskB = new Task <string>(() => cssBundle.Add("~/css/test.less").RenderRawContent("B")); Task <string> taskC = new Task <string>(() => cssBundle.Add("~/css/test.less").RenderRawContent("C")); taskA.Start(); taskB.Start(); taskC.Start(); Task.WaitAll(taskA, taskB, taskC); string contentA = taskA.Result; string contentB = taskB.Result; string contentC = taskC.Result; Assert.AreEqual("#header{color:#4d926f}h2{color:#4d926f}", contentA); Assert.AreEqual(contentA, contentB); Assert.AreEqual(contentB, contentC); } }
public void CanBundleCssWithAsNamedMultiThreaded() { using (new StylePreprocessorScope <LessPreprocessor>()) { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents(cssLess) .Create(); Task taskA = Task.Factory.StartNew(() => cssBundle.Add("~/css/test.less").AsNamed("a", "~/css/a.css")); Task taskB = Task.Factory.StartNew(() => cssBundle.Add("~/css/test.less").AsNamed("b", "~/css/b.css")); Task taskC = Task.Factory.StartNew(() => cssBundle.Add("~/css/test.less").AsNamed("c", "~/css/c.css")); Task.WaitAll(taskA, taskB, taskC); Assert.AreEqual( "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/a.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", cssBundle.RenderNamed("a")); Assert.AreEqual( "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/b.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", cssBundle.RenderNamed("b")); Assert.AreEqual( "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/c.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", cssBundle.RenderNamed("c")); string contentA = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\a.css")]; string contentB = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\b.css")]; string contentC = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\c.css")]; Assert.AreEqual("#header{color:#4d926f}h2{color:#4d926f}", contentA); Assert.AreEqual(contentA, contentB); Assert.AreEqual(contentB, contentC); } }
public void CanRenderOnlyIfFileMissing() { CSSBundle cssBundle = cssBundleFactory .WithDebuggingEnabled(false) .WithContents(css) .Create(); cssBundleFactory.FileReaderFactory.SetFileExists(false); cssBundle .Add("/css/first.css") .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")]); }
public void CanRerenderFiles() { CSSBundle 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[TestUtilities.PrepareRelativePath(@"css\can_rerender_files.css")]); CSSBundle 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[TestUtilities.PrepareRelativePath(@"css\can_rerender_files.css")]); }
public void CanRenderCssFileWithRelativeImportStatement() { string importCss = @" @import url(""other.css""); #header { color: #4D926F; }"; CSSBundle cssBundle = cssBundleFactory .WithDebuggingEnabled(false) .WithContents(importCss) .Create(); cssBundleFactory.FileReaderFactory.SetContents(importCss); cssBundleFactory.FileReaderFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(@"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[TestUtilities.PrepareRelativePath(@"css\processed_import.css")]); }
public void Css_Global_Then_Style() { var stylePreprocessor = new StubStylePreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using (new StylePreprocessorScope <StubStylePreprocessor>(stylePreprocessor)) using (new GlobalPreprocessorScope <StubGlobalPreprocessor>(globalPreprocessor)) { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = cssBundle .Add("~/css/test.style.global") .Render("~/css/output.css"); string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")]; Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=0B5C0EC6F2D8CEA452236626242443B7\" />", tag); Assert.AreEqual("styley", contents); Assert.AreEqual("globey", stylePreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); } }
public void CanRenderDebugTagsTwice() { CSSBundle cssBundle1 = cssBundleFactory .WithDebuggingEnabled(true) .WithContents(css) .Create(); CSSBundle 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\" />"); }
public void CanRenderDebugTagsTwice() { CSSBundle cssBundle1 = cssBundleFactory .WithDebuggingEnabled(true) .WithContents(css) .Create(); CSSBundle 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("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />\n", TestUtilities.NormalizeLineEndings(tag1)); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />\n", TestUtilities.NormalizeLineEndings(tag2)); }
/// <summary> </summary> public static String Css(String files, String mode, Boolean debug) { String name = helperService.CalculateMD5Hash(files); String path = file_info.virtual_site_cache_path().Trim('/') + "/scripts/css/"; path = file_info.normalize_path(path); String dir = Path.GetDirectoryName(path); try { if (!Directory.Exists(dir)) { DirectoryInfo di = Directory.CreateDirectory(dir); } } catch { }//let it pass String FilePath = file_info.normalize_path(path + name + ".css"); if (!file_info.dir_exists(path)) { System.IO.Directory.CreateDirectory(path); } site site = siteService.getCurrentSite(); String theme = themeService.current_theme_alias(); CSSBundle css = new CSSBundle(); foreach (string fl in files.Split(',')) { String filepath = themeService.virtual_theme_skin_path(site, theme, mode, "css").Trim('/') + "/" + fl.Trim('/'); // this is terrible.. if (!file_info.file_exists(filepath)) { filepath = themeService.virtual_theme_skin_path(site, "base", mode, "css").Trim('/') + "/" + fl.Trim('/'); } if (file_info.file_exists(filepath)) { css.Add(filepath); } } String output = ""; debug = true; if (debug) { output = css.ForceRelease().ForceDebug().Render(FilePath); } else { try{ output = css.ForceRelease().Render(FilePath); }catch { return(css.ForceRelease().ForceDebug().Render(FilePath) + "<!-- there is something wrong with your css and can't be parsed -->"); } } return(output); }
public void CanCreateCachedBundleInDebugMode() { CSSBundle 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\" />\n", TestUtilities.NormalizeLineEndings(tag)); }
public void CanDebugBundleCssWithEmbedded() { CSSBundle 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\" />\n", TestUtilities.NormalizeLineEndings(tag)); Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count); }
public void CanRenderDebugTagsWithMediaAttribute() { CSSBundle cssBundle = cssBundleFactory .WithDebuggingEnabled(true) .WithContents(css) .Create(); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithAttribute("media", "screen") .Render("/css/output.css"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/first.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/second.css\" />\n", TestUtilities.NormalizeLineEndings(tag)); }
public void CanBundleCssWithQueryStringParameter() { CSSBundle 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); }
public void CanBundleDebugCssWithArbitraryAttributes() { CSSBundle 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\" />\n<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" test=\"other\" href=\"/css/second.css\" />\n", tag); }
public void CanCreateNamedBundleWithDebug() { CSSBundle 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\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp2.css\" />\n", TestUtilities.NormalizeLineEndings(tag)); }
public void CanBundleCssWithEmbedded() { CSSBundle 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[TestUtilities.PrepareRelativePath(@"css\output_embedded.css")]); }
public void CanCreateCachedBundle() { CSSBundle 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); }
public void CanBundleCssWithArbitraryAttributes() { CSSBundle 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); }
public void CanBundleCssWithRemote() { CSSBundle 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")]); }
public void CanRenderCssFileWithHashInFileName() { CSSBundle 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[TestUtilities.PrepareRelativePath(@"css\output_C33D1225DED9D889876CEE87754EE305.css")]); }
public void CanCreateNamedBundle() { CSSBundle 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.PrepareRelativePath(@"css\output.css")]); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=67F81278D746D60E6F711B5A29747388\" />", tag); }
public void CanBundleCssWithLessWithLessDotCssFileExtension() { CSSBundle 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[TestUtilities.PrepareRelativePath(@"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); }
public void CanBundleCssWithNullCompressorAttribute() { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents(css) .Create(); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithMinifier <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.PrepareRelativePath(@"css\css_with_null_compressor_output.css")]); }
public static String Css(string files) { String name = CalculateMD5Hash(files); String path = @"/cache/script/css/"; String FilePath = path + name + ".css"; if (!HelperService.DirExists(path)) { System.IO.Directory.CreateDirectory(path); } CSSBundle css = new CSSBundle(); foreach (string fl in files.Split(',')) { css.Add(fl); } return(css.ForceRelease().Render(FilePath)); }
public void CanBundleCssWithCompressorAttribute() { CSSBundle cssBundle = cssBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents(css) .Create(); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithMinifier <YuiCompressor>() .Render("/css/css_with_compressor_output.css"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_compressor_output.css?r=1D0C7C68EDD1B4BD490CCE557E427268\" />", tag); Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count); Assert.AreEqual(" li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:400;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:400;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}" , cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\css_with_compressor_output.css")]); }