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);
        }
示例#2
0
        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));
            }
        }
示例#3
0
        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());
            }
        }
示例#4
0
        public static void WithoutUserDefinedIndentation_ContainsDefaultIndentationInOutput()
        {
            var result = new SassOptions
            {
                Data = "a{b:c}"
            }
            .Compile();

            Assert.Equal("a {\n  b: c; }\n", result.Output);
        }
示例#5
0
        public static void WithRelativeInputFile_ProducesOutput()
        {
            var result = new SassOptions
            {
                InputPath = GetFixtureRelativePath("basic/basic1.scss")
            }
            .Compile();

            Assert.Contains("color: crimson", result.Output);
        }
示例#6
0
        public static void WithData_ProducesOutput()
        {
            var result = new SassOptions
            {
                Data = "tr { color: red; }"
            }
            .Compile();

            Assert.Contains("color: red", result.Output);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
文件: Scss.cs 项目: yhforever4/Kooboo
        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);
        }
示例#11
0
        public static void WithIncludeSourceComments_ContainsSourceCommentsInOutput()
        {
            var result = new SassOptions
            {
                InputPath             = GetFixtureRelativePath("basic/basic1.scss"),
                IncludeSourceComments = true
            }
            .Compile();

            Assert.Contains("/* line 1,", result.Output);
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        /* 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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        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);
        }
示例#23
0
        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);
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#26
0
        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);
        }
示例#27
0
        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);
        }
示例#28
0
        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);
        }
示例#29
0
        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);
        }
示例#30
0
        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);
        }