Esempio n. 1
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);
        }
Esempio n. 2
0
        public string Compile(string source, OutputStyle outputStyle = OutputStyle.Nested, bool includeSourceComments = true, int precision = 5, IEnumerable <string> includePaths = null)
        {
            SassContext context = new SassContext
            {
                SourceString = source,
                Options      = new SassOptions
                {
                    OutputStyle                                                        = (int)outputStyle,
                    IncludeSourceComments                                              = includeSourceComments,
                    IncludePaths                                                       = includePaths != null?String.Join(";", includePaths) : String.Empty,
                                                                  Precision            = precision,
                                                                  LineFeed             = OutputLineFeed ?? (OutputLineFeed = "\r\n"),
                                                                  OmitSourceMappingUrl = OmitSourceMappingUrl
                }
            };

            _sassInterface.Compile(context);

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

            return(context.OutputString);
        }
Esempio n. 3
0
        public CompileResult Compile(string source, CompileContext context)
        {
            var sourceFile = context.RootDirectory.GetFile(context.SourceFilePath);

            lock (_lock)
            {
                var sassContext = new SassContext
                {
                    SourceString = source,
                    Options      = new SassOptions
                    {
                        OutputStyle    = (int)OutputStyle.Nested,
                        SourceComments = false,
                        IncludePaths   = sourceFile.Directory.GetAbsolutePath()
                    }
                };

                sassInterface.Compile(sassContext);

                if (sassContext.ErrorStatus)
                {
                    throw new Exception(string.Format("Error in {0}: {1}", sourceFile, sassContext.ErrorMessage));
                }

                return(new CompileResult(sassContext.OutputString, GetReferencesViaRegexHack(source, sourceFile)));
            }
        }
Esempio n. 4
0
        public string Compile(string source, OutputStyle outputStyle = OutputStyle.Nested, bool sourceComments = true, 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,
                    SourceComments                                   = sourceComments,
                    SourceMapFile                                    = String.Empty,
                    OmitSourceMapUrl                                 = true,
                    SourceMapEmbed                                   = false,
                    SourceMapContents                                = false,
                    SourceMapRoot                                    = String.Empty,
                    IsIndentedSyntaxSrc                              = false,
                    IncludePaths                                     = includePaths != null?String.Join(";", includePaths) : String.Empty,
                                                         PluginPaths = String.Empty,
                                                         Indent      = String.Empty,
                                                         Linefeed    = String.Empty,
                                                         Precision   = 0
                }
            };

            _sassInterface.Compile(context);

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

            return(context.OutputString);
        }