/// <summary> /// "Compiles" a Sass-file to CSS-code /// </summary> /// <param name="inputPath">Path to input file</param> /// <param name="outputPath">Path to output file</param> /// <param name="sourceMapPath">Path to source map file</param> /// <param name="options">Compilation options</param> /// <returns>Compilation result</returns> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException" /> /// <exception cref="SassСompilationException">Sass compilation error.</exception> public static CompilationResult CompileFile(string inputPath, string outputPath = null, string sourceMapPath = null, CompilationOptions options = null) { if (inputPath == null) { throw new ArgumentNullException( nameof(inputPath), string.Format(Strings.Common_ArgumentIsNull, nameof(inputPath)) ); } if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentException( string.Format(Strings.Common_ArgumentIsEmpty, nameof(inputPath)), nameof(inputPath) ); } var fileContext = new SassFileContext(); bool indentedSyntax = GetIndentedSyntax(inputPath); BeginCompile(fileContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options); try { SassCompilerProxy.CompileFile(fileContext); } catch (FileNotFoundException e) { string filePath = e.FileName; string text = string.Format("File to read not found or unreadable: {0}", filePath); string message = string.Format("Internal Error: {0}", text); throw new SassСompilationException(message, e) { Status = 3, Text = text, File = null, LineNumber = -1, ColumnNumber = -1, Source = null }; } CompilationResult result = EndCompile(fileContext); return(result); }
/// <summary> /// "Compiles" a Sass file to CSS code /// </summary> /// <param name="inputPath">Path to input file</param> /// <param name="outputPath">Path to output file</param> /// <param name="sourceMapPath">Path to source map file</param> /// <param name="options">Compilation options</param> /// <returns>Compilation result</returns> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException" /> /// <exception cref="SassCompilationException">Sass compilation error.</exception> public static CompilationResult CompileFile(string inputPath, string outputPath = null, string sourceMapPath = null, CompilationOptions options = null) { if (inputPath == null) { throw new ArgumentNullException( nameof(inputPath), string.Format(Strings.Common_ArgumentIsNull, nameof(inputPath)) ); } if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentException( string.Format(Strings.Common_ArgumentIsEmpty, nameof(inputPath)), nameof(inputPath) ); } Initialize(); IFileManager fileManager = _fileManager; if (fileManager != null && !fileManager.FileExists(inputPath)) { string description = string.Format("File to read not found or unreadable: {0}", inputPath); string message = string.Format("Internal Error: {0}", description); throw new SassCompilationException(message) { ErrorCode = 3, Description = description, File = null, LineNumber = -1, ColumnNumber = -1, SourceFragment = null }; } CompilationResult result; var fileContext = new SassFileContext(); bool indentedSyntax = GetIndentedSyntax(inputPath); BeginCompile(fileContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options); try { _mutex.WaitOne(); FileManagerMarshaler.SetFileManager(fileManager); SassCompilerProxy.CompileFile(fileContext); } finally { FileManagerMarshaler.UnsetFileManager(); _mutex.ReleaseMutex(); } GC.KeepAlive(fileManager); result = EndCompile(fileContext); return(result); }