public static void WithEmbedSourceMapUrl_ContainInputPathInSourceMap() { var inputPath = GetFixtureAbsolutePath("basic", "basic1.scss"); var outputPath = GetFixtureAbsolutePath("output", "example.css"); var mapPath = GetFixtureAbsolutePath("output", "example.css.map"); var result = new SassOptions { InputPath = inputPath, OutputPath = outputPath, SourceMapFile = mapPath, EmbedSourceMap = true } .Compile(); var startKey = "base64,"; var endKey = " */"; var indexStart = result.Output.IndexOf(startKey, StringComparison.Ordinal) + startKey.Length; var indexEnd = result.Output.IndexOf(endKey, StringComparison.Ordinal); var encodedString = result.Output.Substring(indexStart, indexEnd - indexStart); byte[] data = Convert.FromBase64String(encodedString); var json = Encoding.UTF8.GetString(data); var uri = new Uri(outputPath); var relativePath = uri.MakeRelativeUri(new Uri(inputPath)).ToString(); Assert.Contains(relativePath, json); }
static AssetProcessingResult DoCompile(string sass) { var sassOptions = new SassOptions { Data = sass, OutputStyle = SassOutputStyle.Compressed, }; var sassCompiler = new LibSass.Compiler.SassCompiler(sassOptions); try { var result = sassCompiler.Compile(); if (result.ErrorStatus != 0) { // TODO: enrich error dump return(new AssetProcessingResult(AssetProcessingResult.CompilationStatus.Failure, null, result.ErrorMessage)); } return(new AssetProcessingResult(AssetProcessingResult.CompilationStatus.Success, result.Output)); } catch (Exception e) { log.Error(e, "Error compiling sass `{sass}`", sass); if (Debugger.IsAttached) { Debugger.Break(); } return(new AssetProcessingResult(AssetProcessingResult.CompilationStatus.Failure, null, e.Message)); } }
public static void Sass_Specs_Run(string source, string expected, bool error, string[] paths) { var result = new SassOptions { InputPath = source, IncludePaths = paths } .Compile(); if (!string.IsNullOrEmpty(result.ErrorMessage)) { Assert.True(error); } else { Assert.False(error); } if (!string.IsNullOrEmpty(expected)) { Assert.Equal( expected.SpecNormalize(), result.Output.SpecNormalize()); } }
public static void WithoutUserDefinedIndentation_ContainsDefaultIndentationInOutput() { var result = new SassOptions { Data = "a{b:c}" } .Compile(); Assert.Equal("a {\n b: c; }\n", result.Output); }
public static void WithRelativeInputFile_ProducesOutput() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss") } .Compile(); Assert.Contains("color: crimson", result.Output); }
public static void WithData_ProducesOutput() { var result = new SassOptions { Data = "tr { color: red; }" } .Compile(); Assert.Contains("color: red", result.Output); }
public static void WithoutOutputStyle_ProcudecsOutputWithDefaultStyle() // default is 'Nested' { var result = new SassOptions { Data = "a{b:c}" } .Compile(); Assert.Equal("a {\n b: c; }\n", result.Output); }
public static void WithoutUserDefinedPrecision_AppliesDefaultPrecision() // default is 5 { var result = new SassOptions { Data = "$my-width: (20*100)/29; a{width:$my-width}" } .Compile(); Assert.Equal("a {\n width: 68.96552; }\n", result.Output); }
public static void WithUserDefinedIndentation_ContiansUserDefinedIndentationInOutput() { var result = new SassOptions { Data = "a{b:c}", Indent = "\t\t\t" } .Compile(); Assert.Equal("a {\n\t\t\tb: c; }\n", result.Output); }
public string Execute(RenderContext context, string input) { var sassOptions = new SassOptions { Data = input }; var sass = new SassCompiler(sassOptions); var result = sass.Compile(); return(result.Output); }
public static void WithIncludeSourceComments_ContainsSourceCommentsInOutput() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), IncludeSourceComments = true } .Compile(); Assert.Contains("/* line 1,", result.Output); }
public static void WithCompact_ProcudecsCompactOutput() { var result = new SassOptions { Data = "a{b:c}", OutputStyle = SassOutputStyle.Compact } .Compile(); Assert.Equal("a { b: c; }\n", result.Output); }
public static void WithDataAndInputPath_ProducesOutputForData() { var result = new SassOptions { Data = "div { color: lightgoldenrodyellow; }", InputPath = "Fixtures/basic/basic1.scss" } .Compile(); Assert.Contains("color: lightgoldenrodyellow", result.Output); }
/* sass to css covert */ public string sasscompiler(string sourcepath) { var options = new SassOptions { InputPath = sourcepath }; var sass = new SassCompiler(options); var result = sass.Compile(); return(result.Output); }
public static void WithSourceRoot_ContainsEmptySourceRootInSourceMap() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), SourceMapFile = GetFixtureRelativePath("output/example.css.map") } .Compile(); Assert.DoesNotContain("\"sourceRoot\"", result.SourceMap); }
public static void WithUserDefinedPrecision_AppliesUserDefinedPrecision() { var result = new SassOptions { Data = "$my-width: (20*100)/29; a{width:$my-width}", Precision = 14 } .Compile(); Assert.Equal("a {\n width: 68.9655172414; }\n", result.Output); }
public static void WithNested_ProcudecsNestedOutput() { var result = new SassOptions { Data = "a{b:c}", OutputStyle = SassOutputStyle.Nested } .Compile(); Assert.Equal("a {\n b: c; }\n", result.Output); }
public static void WithoutUserDefinedLinefeed_ContainsDefaultLinefeedInOutput() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic", "basic1.scss") } .Compile(); var expected = GetCssString("basic", "basic1.css"); Assert.Equal(expected, result.Output); }
public static void WithSourceRoot_PassesThroughSourceRootInSourceMap() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), SourceMapFile = GetFixtureRelativePath("output/example.css.map"), SourceMapRoot = "../webservice/api/" } .Compile(); Assert.Contains("\"sourceRoot\": \"../webservice/api/\",", result.SourceMap); }
public static void WithOutputPath_ContainsSourceMappingURLInOutput() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), OutputPath = GetFixtureRelativePath("output/example.css"), SourceMapFile = GetFixtureRelativePath("output/example.css.map") } .Compile(); Assert.Contains("sourceMappingURL=", result.Output); }
public static void WithAbsolutOutputPathAndSourceMap_ProducesSourceMapWithRelativeOutputPath() { var result = new SassOptions { Data = "div { color: lightgoldenrodyellow; }", InputPath = Path.Combine(Environment.CurrentDirectory, "Fixtures/basic/basic1.scss"), SourceMapFile = "color.css" } .Compile(); Assert.Contains("\"Fixtures/basic/basic1.scss\"", result.SourceMap); }
public static void WithOutputPath_ProducesSourceMap() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), OutputPath = GetFixtureRelativePath("output/example.css"), SourceMapFile = GetFixtureRelativePath("output/example.css.map") } .Compile(); Assert.Contains("example.css", result.SourceMap); }
public static void WithAbsoluteInputFile_OutputMatchesCssFile() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("basic", "basic1.scss") } .Compile(); var expectedOutput = GetCssString("basic", "basic1.css"); Assert.Equal(expectedOutput, result.Output); }
public static void WithRelativeOutputPathAndSourceMap_ProducesSourceMapWithRelativeOutputPath() { var result = new SassOptions { Data = "div { color: lightgoldenrodyellow; }", InputPath = "Fixtures/basic/basic1.scss", SourceMapFile = "color.css" } .Compile(); Assert.Contains("\"Fixtures/basic/basic1.scss\"", result.SourceMap); }
public static void WithImportsInInputFile_OutputMatchesCssFile() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("dependencies (structured)", "structured1.scss") } .Compile(); var expectedOutput = GetCssString("dependencies (structured)", "structured1.css"); Assert.Equal(expectedOutput, result.Output); }
public static void WithUserDefinedLinefeed_ContiansUserDefinedLinefeedInOutput() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic", "basic1.scss"), Linefeed = "\r" } .Compile(); var expected = GetCssString("basic", "basic1.css").Replace("\n", "\r"); Assert.Equal(expected, result.Output); }
public static void WithIncorrectPathSeparator_GivesError() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "disjoint2.scss"), IncludePath = string.Join(PathSeparator == ';' ? ":" : ";", GetFixtureRelativePath(), GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "dirB2") ) } .Compile(); Assert.NotEmpty(result.ErrorMessage); }
public static void WithDisjointImports_OutputMatchesCssFile() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("dependencies (disjoint)", "dirA", "dirA1", "dirA11", "disjoint1.scss"), IncludePath = string.Join(PathSeparator.ToString(), GetFixtureAbsolutePath("dependencies (disjoint)", "dirA"), GetFixtureAbsolutePath("dependencies (disjoint)", "dirA", "dirA2", "dirA21"), GetFixtureAbsolutePath("dependencies (disjoint)", "dirA", "dirA3") ) } .Compile(); var expectedOutput = GetCssString("dependencies (disjoint)", "dirA", "dirA1", "dirA11", "disjoint1.css"); Assert.Equal(expectedOutput, result.Output); }
public static void WithSemiDisjointImports_OutputMatchesCssFile() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "disjoint2.scss"), IncludePaths = new[] { GetFixtureRelativePath(), GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "dirB2") } } .Compile(); var expectedOutput = GetCssString("dependencies (disjoint)", "dirB", "disjoint2.css"); Assert.Equal(expectedOutput, result.Output); }
public static void WithEmbedSourceMapUrl_ContainOutputPathInSourceMap() { var result = new SassOptions { InputPath = GetFixtureRelativePath("basic/basic1.scss"), OutputPath = GetFixtureRelativePath("output/example.css"), SourceMapFile = GetFixtureRelativePath("output/example.css.map"), EmbedSourceMap = true } .Compile(); var startKey = "base64,"; var endKey = " */"; var indexStart = result.Output.IndexOf(startKey, StringComparison.Ordinal) + startKey.Length; var indexEnd = result.Output.IndexOf(endKey, StringComparison.Ordinal); var encodedString = result.Output.Substring(indexStart, indexEnd - indexStart); byte[] data = Convert.FromBase64String(encodedString); var json = Encoding.UTF8.GetString(data); Assert.Contains("\"example.css\"", json); }