Beispiel #1
0
        public string Compile(string source, OutputStyle outputStyle = OutputStyle.Nested, SourceCommentsMode sourceComments = SourceCommentsMode.Default, string imagePath = "", IEnumerable<string> includePaths = null)
        {
            if (outputStyle != OutputStyle.Nested && outputStyle != OutputStyle.Compressed)
            {
                throw new ArgumentException("Only nested and compressed output styles are currently supported by libsass.");
            }

            SassContext context = new SassContext
            {
                SourceString = source,
                Options = new SassOptions
                {
                    OutputStyle = (int)outputStyle,
                    SourceCommentsMode = (int)sourceComments,
                    IncludePaths = includePaths != null ? String.Join(";", includePaths) : String.Empty,
                    ImagePath = imagePath
                }
            };

            _sassInterface.Compile(context);

            if (context.ErrorStatus)
            {
                throw new SassCompileException(context.ErrorMessage);
            }

            return context.OutputString;
        }
Beispiel #2
0
        public CompileFileResult CompileFile(string inputPath, OutputStyle outputStyle = OutputStyle.Nested,  string sourceMapPath = null, SourceCommentsMode sourceComments = SourceCommentsMode.Default, string imagePath = "", IEnumerable<string> additionalIncludePaths = null)
        {
            if (outputStyle != OutputStyle.Nested && outputStyle != OutputStyle.Compressed)
            {
                throw new ArgumentException("Only nested and compressed output styles are currently supported by libsass.");
            }

            string directoryName = Path.GetDirectoryName(inputPath);
            List<string> includePaths = new List<string> { directoryName };
            if (additionalIncludePaths != null)
            {
                includePaths.AddRange(additionalIncludePaths);
            }

            SassFileContext context = new SassFileContext
            {
                InputPath = inputPath,
                Options = new SassOptions
                {
                    OutputStyle = (int)outputStyle,
                    SourceCommentsMode = (int)sourceComments,
                    IncludePaths = String.Join(";", includePaths),
                    ImagePath = imagePath
                },
                OutputSourceMapFile = sourceMapPath
            };

            _sassInterface.Compile(context);

            if (context.ErrorStatus)
            {
                throw new SassCompileException(context.ErrorMessage);
            }

            return new CompileFileResult(context.OutputString, context.OutputSourceMap);
        }
Beispiel #3
0
        public CompileFileResult CompileFile(string inputPath, OutputStyle outputStyle = OutputStyle.Nested, string sourceMapPath = null, SourceCommentsMode sourceComments = SourceCommentsMode.Default, int precision = 5, IEnumerable <string> additionalIncludePaths = null)
        {
            if (outputStyle != OutputStyle.Nested && outputStyle != OutputStyle.Compressed)
            {
                throw new ArgumentException("Only nested and compressed output styles are currently supported by libsass.");
            }

            string        directoryName = Path.GetDirectoryName(inputPath);
            List <string> includePaths  = new List <string> {
                directoryName
            };

            if (additionalIncludePaths != null)
            {
                includePaths.AddRange(additionalIncludePaths);
            }

            SassFileContext context = new SassFileContext
            {
                // libsass 3.0 expects utf8 path string, but strings in .NET are utf16, so we need to convert it
                InputPath = Utf16ToUtf8(inputPath),
                Options   = new SassOptions
                {
                    OutputStyle        = (int)outputStyle,
                    SourceCommentsMode = (int)sourceComments,
                    IncludePaths       = String.Join(";", includePaths),
                    ImagePath          = string.Empty,
                    Precision          = precision
                },
                OutputSourceMapFile = sourceMapPath
            };

            _sassInterface.Compile(context);

            if (context.ErrorStatus)
            {
                throw new SassCompileException(context.ErrorMessage);
            }

            return(new CompileFileResult(context.OutputString, context.OutputSourceMap));
        }
Beispiel #4
0
        public string Compile(string source, OutputStyle outputStyle = OutputStyle.Nested, SourceCommentsMode sourceComments = SourceCommentsMode.Default, int precision = 5, IEnumerable <string> includePaths = null)
        {
            if (outputStyle != OutputStyle.Nested && outputStyle != OutputStyle.Compressed)
            {
                throw new ArgumentException("Only nested and compressed output styles are currently supported by libsass.");
            }

            SassContext context = new SassContext
            {
                SourceString = source,
                Options      = new SassOptions
                {
                    OutputStyle                                  = (int)outputStyle,
                    SourceCommentsMode                           = (int)sourceComments,
                    IncludePaths                                 = includePaths != null?String.Join(";", includePaths) : String.Empty,
                                                       ImagePath = string.Empty,
                                                       Precision = precision
                }
            };

            _sassInterface.Compile(context);

            if (context.ErrorStatus)
            {
                throw new SassCompileException(context.ErrorMessage);
            }

            return(context.OutputString);
        }