当前位置: 首页>>代码示例>>C#>>正文


C# Config.GetAbsoluteOutputFile方法代码示例

本文整理汇总了C#中Config.GetAbsoluteOutputFile方法的典型用法代码示例。如果您正苦于以下问题:C# Config.GetAbsoluteOutputFile方法的具体用法?C# Config.GetAbsoluteOutputFile怎么用?C# Config.GetAbsoluteOutputFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Config的用法示例。


在下文中一共展示了Config.GetAbsoluteOutputFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            string sourceMap = config.SourceMap ? config.GetAbsoluteOutputFile() + ".map" : null;

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            SassOptions options = new SassOptions(config);

            try
            {
                LibSassNet.SassCompiler compiler = new LibSassNet.SassCompiler();
                var compilerResult = compiler.CompileFile(inputFile, (LibSassNet.OutputStyle)options.OutputStyle, sourceMap, options.IncludeSourceComments, options.Precision);
                result.CompiledContent = compilerResult.CSS;
                result.SourceMap = compilerResult.SourceMap;
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = ex.Message.Replace("/", "\\").Replace(info.FullName, string.Empty).Trim()
                };

                if (error.Message.StartsWith(":"))
                {
                    int end = error.Message.IndexOf(':', 1);
                    int line = 0;
                    if (int.TryParse(error.Message.Substring(1, end - 1), out line))
                    {
                        error.LineNumber = line;
                        error.Message = error.Message.Substring(end + 1).Trim();
                    }
                }

                result.Errors.Add(error);
            }

            return result;
        }
开发者ID:robbygregory,项目名称:WebCompiler,代码行数:49,代码来源:SassCompiler.cs

示例2: Adjust

        public static string Adjust(string content, Config config)
        {
            string cssFileContents = content;
            string absoluteOutputPath = config.GetAbsoluteOutputFile();

            // apply the RegEx to the file (to change relative paths)
            var matches = _rxUrl.Matches(cssFileContents);

            // Ignore the file if no match
            if (matches.Count > 0)
            {
                string cssDirectoryPath = Path.GetDirectoryName(config.GetAbsoluteInputFile());

                if (!Directory.Exists(cssDirectoryPath))
                    return cssFileContents;

                foreach (Match match in matches)
                {
                    string quoteDelimiter = match.Groups[1].Value; //url('') vs url("")
                    string relativePathToCss = match.Groups[2].Value;

                    // Ignore root relative references
                    if (relativePathToCss.StartsWith("/", StringComparison.Ordinal))
                        continue;

                    //prevent query string from causing error
                    var pathAndQuery = relativePathToCss.Split(new[] { '?' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    var pathOnly = pathAndQuery[0];
                    var queryOnly = pathAndQuery.Length == 2 ? pathAndQuery[1] : string.Empty;

                    string absolutePath = GetAbsolutePath(cssDirectoryPath, pathOnly);

                    if (string.IsNullOrEmpty(absoluteOutputPath))
                        continue;

                    string serverRelativeUrl = FileHelpers.MakeRelative(absoluteOutputPath, absolutePath);

                    if (!string.IsNullOrEmpty(queryOnly))
                        serverRelativeUrl += "?" + queryOnly;

                    string replace = string.Format("url({0}{1}{0})", quoteDelimiter, serverRelativeUrl);

                    cssFileContents = cssFileContents.Replace(match.Groups[0].Value, replace);
                }
            }

            return cssFileContents;
        }
开发者ID:DayLightDancer,项目名称:WebCompiler,代码行数:48,代码来源:CssRelativePathAdjuster.cs

示例3: MinifyFile

        internal static MinificationResult MinifyFile(Config config)
        {
            FileInfo file = config.GetAbsoluteOutputFile();
            string extension = file.Extension.ToUpperInvariant();

            switch (extension)
            {
                case ".JS":
                    return MinifyJavaScript(config, file.FullName);

                case ".CSS":
                    return MinifyCss(config, file.FullName);
            }

            return null;
        }
开发者ID:JackWangCUMT,项目名称:WebCompiler,代码行数:16,代码来源:FileMinifier.cs

示例4: ProcessConfig

        private CompilerResult ProcessConfig(string baseFolder, Config config)
        {
            ICompiler compiler = CompilerService.GetCompiler(config);

            var result = compiler.Compile(config);

            if (result.Errors.Any(e => !e.IsWarning))
                return result;

            if (Path.GetExtension(config.OutputFile).Equals(".css", StringComparison.OrdinalIgnoreCase) && AdjustRelativePaths(config))
            {
                result.CompiledContent = CssRelativePath.Adjust(result.CompiledContent, config);
            }

            config.Output = result.CompiledContent;

            FileInfo outputFile = config.GetAbsoluteOutputFile();
            bool containsChanges = FileHelpers.HasFileContentChanged(outputFile.FullName, config.Output);

            OnBeforeProcess(config, baseFolder, containsChanges);

            if (containsChanges)
            {
                string dir = outputFile.DirectoryName;

                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);

                File.WriteAllText(outputFile.FullName, config.Output, new UTF8Encoding(true));
            }

            OnAfterProcess(config, baseFolder, containsChanges);

            //if (!config.Minify.ContainsKey("enabled") || config.Minify["enabled"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase))
            //{
            FileMinifier.MinifyFile(config);
            //}

            if (config.SourceMap)
            {
                if (!string.IsNullOrEmpty(result.SourceMap))
                {
                    string absolute = config.GetAbsoluteOutputFile().FullName;
                    string mapFile = absolute + ".map";
                    bool smChanges = FileHelpers.HasFileContentChanged(mapFile, result.SourceMap);

                    OnBeforeWritingSourceMap(absolute, mapFile, smChanges);

                    if (smChanges)
                    {
                        File.WriteAllText(mapFile, result.SourceMap, new UTF8Encoding(true));
                    }

                    OnAfterWritingSourceMap(absolute, mapFile, smChanges);
                }
            }

            Telemetry.TrackCompile(config);

            return result;
        }
开发者ID:duncansmart,项目名称:WebCompiler,代码行数:61,代码来源:ConfigFileProcessor.cs

示例5: ProcessConfig

        private CompilerResult ProcessConfig(string baseFolder, Config config)
        {
            ICompiler compiler = CompilerService.GetCompiler(config);

            var result = compiler.Compile(config);

            if (result.HasErrors)
                return result;

            config.Output = result.CompiledContent;
            string outputFile = Path.Combine(baseFolder, config.OutputFile);

            OnBeforeProcess(config, baseFolder);
            File.WriteAllText(outputFile, config.Output, new UTF8Encoding(true));
            OnAfterProcess(config, baseFolder);

            if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                FileMinifier.MinifyFile(config);
            }

            if (config.SourceMap)
            {
                if (!string.IsNullOrEmpty(result.SourceMap))
                {
                    string aboslute = config.GetAbsoluteOutputFile();
                    string mapFile = aboslute + ".map";

                    OnBeforeWritingSourceMap(aboslute, mapFile);
                    File.WriteAllText(mapFile, result.SourceMap, new UTF8Encoding(true));
                    OnAfterWritingSourceMap(aboslute, mapFile);
                }
            }

            return result;
        }
开发者ID:justindyer,项目名称:WebCompiler,代码行数:36,代码来源:ConfigFileProcessor.cs

示例6: ProcessConfig

        private CompilerResult ProcessConfig(string baseFolder, Config config)
        {
            ICompiler compiler = CompilerService.GetCompiler(config);

            var result = compiler.Compile(config);

            if (result.HasErrors)
                return result;

            if (Path.GetExtension(config.OutputFile).Equals(".css", StringComparison.OrdinalIgnoreCase) && AdjustRelativePaths(config))
            {
                result.CompiledContent = CssRelativePath.Adjust(result.CompiledContent, config);
            }

            config.Output = result.CompiledContent;

            string outputFile = config.GetAbsoluteOutputFile();
            bool containsChanges = FileHelpers.HasFileContentChanged(outputFile, config.Output);

            OnBeforeProcess(config, baseFolder, containsChanges);

            if (containsChanges)
            {
                File.WriteAllText(outputFile, config.Output, new UTF8Encoding(true));
            }

            OnAfterProcess(config, baseFolder, containsChanges);

            if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                FileMinifier.MinifyFile(config);
            }

            if (config.SourceMap)
            {
                if (!string.IsNullOrEmpty(result.SourceMap))
                {
                    string aboslute = config.GetAbsoluteOutputFile();
                    string mapFile = aboslute + ".map";
                    bool smChanges = FileHelpers.HasFileContentChanged(mapFile, result.SourceMap);

                    OnBeforeWritingSourceMap(aboslute, mapFile, smChanges);

                    if (smChanges)
                    {
                        File.WriteAllText(mapFile, result.SourceMap, new UTF8Encoding(true));
                    }

                    OnAfterWritingSourceMap(aboslute, mapFile, smChanges);
                }
            }

            return result;
        }
开发者ID:scott-xu,项目名称:WebCompiler,代码行数:54,代码来源:ConfigFileProcessor.cs


注:本文中的Config.GetAbsoluteOutputFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。