Пример #1
0
        private static CompilationResult InnerCompile(string content, bool indentedSyntax, string inputPath,
                                                      string outputPath, string sourceMapPath, CompilationOptions options)
        {
            Initialize();

            CompilationResult result;
            var dataContext = new SassDataContext
            {
                SourceString = content
            };

            BeginCompile(dataContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options);

            try
            {
                _mutex.WaitOne();
                FileManagerMarshaler.SetFileManager(_fileManager);
                SassCompilerProxy.Compile(dataContext);
            }
            finally
            {
                FileManagerMarshaler.UnsetFileManager();
                _mutex.ReleaseMutex();
            }

            result = EndCompile(dataContext);

            return(result);
        }
Пример #2
0
        /// <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);
        }