Beispiel #1
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)));
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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;
        }
Beispiel #5
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,
                    IncludePaths = includePaths != null ? String.Join(";", includePaths) : String.Empty,
                    ImagePath = String.Empty
                }
            };

            _sassInterface.Compile(context);

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

            return context.OutputString;
        }
Beispiel #6
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);
        }
Beispiel #7
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;
		}
Beispiel #8
0
        private CompilationResult EndCompile(SassContext context)
        {
            FileManagerMarshallingProxy.UnsetFileManager();

            CompilationResult result;

            SassErrorInfo error = context.Error;
            if (error == null)
            {
                result = new CompilationResult
                {
                    CompiledContent = context.OutputString,
                    IncludedFilePaths = context.IncludedFiles.ToList(),
                    SourceMap = context.SourceMapString
                };
            }
            else
            {
                throw new SassСompilationException(error.Message)
                {
                    Status = error.Status,
                    Text = error.Text,
                    File = error.File,
                    LineNumber = error.Line,
                    ColumnNumber = error.Column,
                    Source = error.Source
                };
            }

            return result;
        }
Beispiel #9
0
        private void BeginCompile(SassContext context, string inputPath, string outputPath, CompilationOptions options)
        {
            options = options ?? new CompilationOptions();

            string inputFilePath = !string.IsNullOrWhiteSpace(inputPath) ? inputPath : string.Empty;
            string outputFilePath = !string.IsNullOrWhiteSpace(outputPath) ? outputPath : string.Empty;
            string sourceMapFilePath = !string.IsNullOrWhiteSpace(options.SourceMapFilePath) ?
                options.SourceMapFilePath : string.Empty;

            if (inputFilePath.Length > 0 || outputFilePath.Length > 0)
            {
                outputFilePath = outputFilePath.Length > 0 ?
                    outputPath : Path.ChangeExtension(inputFilePath, ".css");
                sourceMapFilePath = sourceMapFilePath.Length > 0 ?
                    sourceMapFilePath : Path.ChangeExtension(outputFilePath, ".css.map");
            }

            context.InputPath = inputFilePath;
            context.Options = new SassOptions
            {
                IncludePath = string.Join(";", options.IncludePaths),
                Indent = GetIndentString(options.IndentType, options.IndentWidth),
                IsIndentedSyntaxSource = options.IndentedSyntax,
                LineFeed = GetLineFeedString(options.LineFeedType),
                OutputStyle = (int)options.OutputStyle,
                Precision = options.Precision,
                OmitSourceMapUrl = options.OmitSourceMapUrl,
                SourceMapContents = options.SourceMapIncludeContents,
                SourceMapEmbed = options.InlineSourceMap,
                SourceMapFile = options.SourceMap ? sourceMapFilePath : string.Empty,
                SourceMapFileUrls = options.SourceMapFileUrls,
                SourceMapRoot = options.SourceMapRootPath,
                SourceComments = options.SourceComments
            };
            context.OutputPath = outputFilePath;

            FileManagerMarshallingProxy.SetFileManager(_fileManager);
        }