本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}