/// <summary>
        /// Creates a compilation options
        /// </summary>
        /// <param name="assetTypeCode">Asset type code</param>
        /// <param name="enableNativeMinification">Flag that indicating to use of native minification</param>
        /// <returns>Compilation options</returns>
        private CompilationOptions CreateCompilationOptions(string assetTypeCode, bool enableNativeMinification)
        {
            var options = new CompilationOptions
            {
                IndentedSyntax = (assetTypeCode == Constants.AssetTypeCode.Sass),
                IndentType = Utils.GetEnumFromOtherEnum<BtIndentType, LshIndentType>(IndentType),
                IndentWidth = IndentWidth,
                LineFeedType = Utils.GetEnumFromOtherEnum<BtLineFeedType, LshLineFeedType>(LineFeedType),
                OutputStyle = enableNativeMinification ? OutputStyle.Compressed : OutputStyle.Expanded,
                Precision = Precision,
                SourceComments = SourceComments
            };

            return options;
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// "Compiles" a Sass-code to CSS-code
        /// </summary>
        /// <param name="content">Text content written on Sass</param>
        /// <param name="inputPath">Path to input file</param>
        /// <param name="outputPath">Path to output file</param>
        /// <param name="options">Compilation options</param>
        /// <returns>Compilation result</returns>
        public CompilationResult Compile(string content, string inputPath = null, string outputPath = null, CompilationOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new ArgumentException(string.Format(Strings.Common_ArgumentIsEmpty, "content"), "content");
            }

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

            lock (_compilationSynchronizer)
            {
                BeginCompile(dataContext, inputPath, outputPath, options);

                _sassNativeCompiler.Compile(dataContext);

                result = EndCompile(dataContext);
            }

            return result;
        }
示例#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="options">Compilation options</param>
        /// <returns>Compilation result</returns>
        public CompilationResult CompileFile(string inputPath, string outputPath = null, CompilationOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(inputPath))
            {
                throw new ArgumentException(string.Format(Strings.Common_ArgumentIsEmpty, "inputPath"), "inputPath");
            }

            CompilationResult result;
            var fileContext = new SassFileContext();

            lock (_compilationSynchronizer)
            {
                if (!_fileManager.FileExists(inputPath))
                {
                    throw new FileNotFoundException(string.Format(Strings.Common_FileNotExist, inputPath), inputPath);
                }

                BeginCompile(fileContext, inputPath, outputPath, options);

                _sassNativeCompiler.CompileFile(fileContext);

                result = EndCompile(fileContext);
            }

            return result;
        }