Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            MultiplatformAssemblyLoader.Enable = true;

            Console.WriteLine("Is64BitProcess {0}", Environment.Is64BitProcess);

            var          compiler = new SassCompilerProxy();
            const string input    = "$primary-color: #333; body {color: $primary-color;}";
            var          output   = compiler.Compile(input);

            Console.WriteLine(output);
        }
Ejemplo n.º 3
0
        private static CompilationResult InnerCompile(string content, bool indentedSyntax, string inputPath,
                                                      string outputPath, string sourceMapPath, CompilationOptions options)
        {
            var dataContext = new SassDataContext
            {
                SourceString = content
            };

            BeginCompile(dataContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options);
            SassCompilerProxy.Compile(dataContext);
            CompilationResult result = EndCompile(dataContext);

            return(result);
        }
Ejemplo n.º 4
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="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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a Sass compiler
        /// </summary>
        private static void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                try
                {
                    _version         = SassCompilerProxy.GetVersion();
                    _languageVersion = SassCompilerProxy.GetLanguageVersion();
                }
                catch (DllNotFoundException e)
                {
                    throw WrapDllNotFoundException(e);
                }
#if NETSTANDARD1_3
                catch (TypeLoadException e)
#else
                catch (EntryPointNotFoundException e)
#endif
                {
                    string message = e.Message;
                    if (message.ContainsQuotedValue(DllName.Universal) &&
                        (message.ContainsQuotedValue("libsass_version") || message.ContainsQuotedValue("libsass_language_version")))
                    {
                        _version         = "0.0.0";
                        _languageVersion = "0.0";
                    }
                    else
                    {
                        throw SassErrorHelpers.WrapCompilerLoadException(e, true);
                    }
                }
                catch (Exception e)
                {
                    throw SassErrorHelpers.WrapCompilerLoadException(e, true);
                }

                _initialized = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Static constructor
        /// </summary>
        /// <exception cref="SassCompilerLoadException">Failed to load a Sass-compiler.</exception>
        static SassCompiler()
        {
#if !NETSTANDARD
            if (Utils.IsWindows())
            {
                AssemblyResolver.Initialize();
            }
#endif
            try
            {
                _version         = SassCompilerProxy.GetVersion();
                _languageVersion = SassCompilerProxy.GetLanguageVersion();
            }
            catch (DllNotFoundException e)
            {
                throw new SassCompilerLoadException(Strings.Runtime_SassCompilerNotLoaded, e);
            }
        }
Ejemplo n.º 7
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);
        }