private string BuildSassFile(string inputFilePath, string outputFilePath, string sourceMapFilePath, bool buildSourceMap = false)
        {
            try
            {
                var options = new CompilationOptions
                {
                    SourceMap = buildSourceMap
                };

                var result = SassCompiler.CompileFile(inputFilePath, outputFilePath, sourceMapFilePath, options);
                _fileService.SaveFile(outputFilePath, result.CompiledContent);
                if (buildSourceMap && sourceMapFilePath.HasValue())
                {
                    _fileService.SaveFile(sourceMapFilePath, result.SourceMap);
                }
            }
            catch (SassCompilationException ex)
            {
                var errorDetails = SassErrorHelpers.GenerateErrorDetails(ex);
                _logger.Error <SassService>(ex, errorDetails);
                return(ex.Message);
            }

            return(string.Empty);
        }
        private static void WriteError(string title, SassException exception)
        {
            Console.WriteLine("{0} See details:", title);
            Console.WriteLine();
            Console.Write(exception.Message);

            string errorDetails = SassErrorHelpers.GenerateErrorDetails(exception, true);

            if (errorDetails.Length > 0)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.Write(errorDetails);
            }

            Console.WriteLine();
            Console.WriteLine();
        }
        private void InnerTranslate(IAsset asset, CompilationOptions sassOptions, bool enableNativeMinification)
        {
            string         assetTypeName = asset.AssetTypeCode == Constants.AssetTypeCode.Sass ? "Sass" : "SCSS";
            string         newContent;
            string         assetUrl = asset.Url;
            IList <string> dependencies;

            try
            {
                CompilationResult result = SassCompiler.Compile(asset.Content, assetUrl, options: sassOptions);
                newContent   = result.CompiledContent;
                dependencies = result.IncludedFilePaths;
            }
            catch (SassCompilationException e)
            {
                string errorDetails = SassErrorHelpers.GenerateErrorDetails(e, true);

                var           stringBuilderPool   = StringBuilderPool.Shared;
                StringBuilder errorMessageBuilder = stringBuilderPool.Rent();
                errorMessageBuilder.AppendLine(e.Message);
                errorMessageBuilder.AppendLine();
                errorMessageBuilder.Append(errorDetails);

                string errorMessage = errorMessageBuilder.ToString();
                stringBuilderPool.Return(errorMessageBuilder);

                throw new AssetTranslationException(
                          string.Format(CoreStrings.Translators_TranslationSyntaxError,
                                        assetTypeName, OUTPUT_CODE_TYPE, assetUrl, errorMessage));
            }
            catch (Exception e)
            {
                throw new AssetTranslationException(
                          string.Format(CoreStrings.Translators_TranslationFailed,
                                        assetTypeName, OUTPUT_CODE_TYPE, assetUrl, e.Message), e);
            }

            asset.Content  = newContent;
            asset.Minified = enableNativeMinification;
            asset.RelativePathsResolved   = false;
            asset.VirtualPathDependencies = dependencies;
        }
Esempio n. 4
0
        /// <summary>
        /// Returns a string that represents the current exception
        /// </summary>
        /// <returns>A string that represents the current exception</returns>
        public override string ToString()
        {
            string errorDetails = SassErrorHelpers.GenerateErrorDetails(this, true);

            var           stringBuilderPool = StringBuilderPool.Shared;
            StringBuilder resultBuilder     = stringBuilderPool.Rent();

            resultBuilder.Append(this.GetType().FullName);
            resultBuilder.Append(": ");
            resultBuilder.Append(this.Message);

            if (errorDetails.Length > 0)
            {
                resultBuilder.AppendLine();
                resultBuilder.AppendLine();
                resultBuilder.Append(errorDetails);
            }

            if (this.InnerException != null)
            {
                resultBuilder.Append(" ---> ");
                resultBuilder.Append(this.InnerException.ToString());
            }

            if (this.StackTrace != null)
            {
                resultBuilder.AppendLine();
                resultBuilder.AppendLine(this.StackTrace);
            }

            string result = resultBuilder.ToString();

            stringBuilderPool.Return(resultBuilder);

            return(result);
        }