public void Should_Compile_Less_To_Css_To_Output_Path() { var lessContent = @"@brand_color: #4D926F; #header { color: @brand_color; } h2 { color: @brand_color; }"; var lessOutput = @"#header{color:#4d926f}h2{color:#4d926f}"; var filepath = @"c:\css\style.less"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath, new MockFileData(lessContent) } }); var files = new List<FileInfo>() { new FileInfo(filepath) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); minifier.Minify(); var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8); Assert.Equal(lessOutput, minifiedFile); }
public void Should_Combine_Files_To_Output_Path() { var filepath1 = @"c:\css\style.css"; var filepath2 = @"c:\css\style2.css"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath1, new MockFileData("a { color: Red; }") }, { filepath2, new MockFileData("a { color: Blue; }") } }); var files = new List<FileInfo> { new FileInfo(filepath1), new FileInfo(filepath2) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); minifier.Minify(); var expectedOutput = @"a{color:Red}a{color:Blue}"; var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8); Assert.Equal(expectedOutput, minifiedFile); }
private string minifyCss(string templateContent) { var outputPath = Path.Combine(_siteDirectory, @"_site\css\minified.css"); //todo extract all internal css/less links from template var cssFiles = new List<FileInfo>(); var cssMinifier = new CssMinifier(_fileSystem, cssFiles, outputPath); cssMinifier.Minify(); //todo replace extracted links with single link to minified css (possibly with a hash appended) throw new NotImplementedException(); }
public void OnImportsSatisfied() { minifier = new CssMinifier(fileSystem, GetEngine); }
public void Should_Compile_Single_Less_File() { var lessContent = @"@brand_color: #4D926F; #header { color: @brand_color; } h2 { color: @brand_color; }"; var lessOutput = @"#header{color:#4d926f}h2{color:#4d926f}"; var filepath = @"c:\css\style.less"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath, new MockFileData(lessContent) } }); var files = new List<FileInfo> { new FileInfo(filepath) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); var minified = minifier.ProcessCss(new FileInfo(filepath)); Assert.Equal(lessOutput, minified); }
public void Should_Write_Single_File_To_Output_Path() { var filepath = @"c:\css\style.css"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath, new MockFileData("a { color: Red; }") } }); var files = new List<FileInfo>() { new FileInfo(filepath) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); minifier.Minify(); var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8); Assert.False(string.IsNullOrWhiteSpace(minifiedFile)); }
public void Should_Process_Less_Imports() { var filepath1 = @"c:\css\style.less"; var filepath2 = @"c:\css\style2.less"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath1, new MockFileData("@brand_color: #4D926F;") }, { filepath2, new MockFileData("@import \"style.less\"; a { color: @brand_color; }") } }); var files = new List<FileInfo> { new FileInfo(filepath1), new FileInfo(filepath2) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); var expectedOutput = @"a{color:#4d926f}"; var minifiedFile = minifier.ProcessCss(new FileInfo(filepath2)); Assert.Equal(expectedOutput, minifiedFile); }
public void Should_Minify_Single_File() { var filepath = @"c:\css\style.css"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { filepath, new MockFileData("a { color: Red; }") } }); var files = new List<FileInfo> { new FileInfo(filepath) }; var factory = new TestContainerFactory(); var engine = factory.GetEngine(fileSystem, @"c:\css"); var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine); var result = minifier.ProcessCss(new FileInfo(filepath)); Assert.Equal("a{color:Red}", result); }