public ICompilerFile GetSourceFileNameFromRequestedFileName(ICompilerFile physicalFileName) { var compiler = GetMatchingCompiler(physicalFileName); if (compiler == null) { return null; } return compiler.FindInputFileGivenOutput(physicalFileName); }
public string GetOutputMimeType(ICompilerFile requestedFileName) { var compiler = GetMatchingCompiler(requestedFileName); if (compiler == null) { return "application/octet-stream"; } return compiler.OutputMimeType; }
public string ProcessFileContent(ICompilerFile inputFileContent) { IEnumerable<ICompilerFile> combineFileNames = GetCombineFileNames(inputFileContent); string[] allText = combineFileNames .Select(x => _compiler.CanCompile(x) ? _compiler.GetCompiledContent(x).Contents : String.Empty) .ToArray(); return allText.Aggregate(new StringBuilder(), (acc, x) => { acc.Append(x); acc.Append("\n"); return acc; }).ToString(); }
public string ProcessFileContent(ICompilerFile inputFileContent) { string text = inputFileContent.ReadAllText(); if (inputFileContent.Name.EndsWith(".coffee", StringComparison.OrdinalIgnoreCase)) { using (ValueContainer<CoffeeScriptCompiler> coffeeEngine = _coffeeEngine.Get()) { text = coffeeEngine.Value.Compile(text); } } string ret; using (ValueContainer<MinifyingCompiler> engine = _engine.Get()) { ret = engine.Value.Compile(text); } return ret; }
public static ICompilerFile FindInputFileGivenOutput(this ISimpleFileCompiler This, ICompilerFile outputFilePath) { var outputName = outputFilePath.Name; if (outputName.EndsWith(This.OutputFileExtension, StringComparison.InvariantCultureIgnoreCase)) { outputName = outputName.Substring(0, outputName.Length-This.OutputFileExtension.Length); foreach (var ext in This.InputFileExtensions) { ICompilerFile result = outputFilePath.GetRelativeFile(outputName+ext); if (result.Exists) { return result; } } } return null; }
public CompilationResult GetCompiledContent(ICompilerFile sourceFileName) { var compiler = GetMatchingCompiler(sourceFileName); if (compiler == null) { return CompilationResult.Error; } var physicalFileName = compiler.FindInputFileGivenOutput(sourceFileName); if (!physicalFileName.Exists) { return CompilationResult.Error; } var cacheKey = GetCacheKey(physicalFileName, compiler); return _cache.GetOrAdd(cacheKey, f => CompileContent(physicalFileName, compiler), compiler.OutputMimeType); }
public string GetFileChangeToken(ICompilerFile inputFileContent) { MD5 md5sum = MD5.Create(); MemoryStream ms = GetCombineFileNames(inputFileContent) .Select(x => _compiler.GetSourceFileNameFromRequestedFileName(x)) .Where(x => (x != null) && x.Exists) .Select(x => x.LastWriteTimeUtc.Ticks) .Aggregate(new MemoryStream(), (acc, x) => { byte[] buf = BitConverter.GetBytes(x); acc.Write(buf, 0, buf.Length); return acc; }); return md5sum.ComputeHash(ms.GetBuffer()).Aggregate(new StringBuilder(), (acc, x) => { acc.Append(x.ToString("x")); return acc; }).ToString(); }
public string ProcessFileContent(ICompilerFile inputFileContent) { return inputFileContent.ReadAllText(); }
public string GetFileChangeToken(ICompilerFile inputFileContent) { return ""; }
private IEnumerable<ICompilerFile> GetCombineFileNames(ICompilerFile inputFileContent) { return inputFileContent.ReadLines() .Select(l => _lineRegex.Match(l)) .Where(m => m.Success) .Select(m => inputFileContent.GetRelativeFile(m.Value)); }
internal IDisposable SetCompilerFile(ICompilerFile file) { if (file == null) { throw new ArgumentNullException("file"); } Debug.Assert(_compilerFile == null); _compilerFile = file; _currentDirectory = Path.GetDirectoryName(@"V:"+file.Name); Directory.CreateDirectory(_cachePath); return Disposable.Create(delegate { _compilerFile = null; _currentDirectory = null; Directory.Delete(_cachePath, true); }); }
public string ProcessFileContent(ICompilerFile inputFileContent) { using (var sassModule = _sassModule.Get()) { dynamic opt = (inputFileContent.Name.EndsWith(".scss", StringComparison.OrdinalIgnoreCase) ? sassModule.Value.ScssOption : sassModule.Value.SassOption); using (sassModule.Value.PlatformAdaptationLayer.SetCompilerFile(inputFileContent)) { return (string)sassModule.Value.Engine.compile(inputFileContent.ReadAllText(), opt); } } }
private string GetCacheKey(ICompilerFile physicalFileName, ISimpleFileCompiler compiler) { var token = compiler.GetFileChangeToken(physicalFileName) ?? String.Empty; return String.Format("{0:yyyyMMddHHmmss}-{1}-{2}{3}", physicalFileName.LastWriteTimeUtc, token, Path.GetFileNameWithoutExtension(physicalFileName.Name), compiler.OutputFileExtension); }
private CompilationResult CompileContent(ICompilerFile physicalFileName, ISimpleFileCompiler compiler) { return new CompilationResult(true, compiler.ProcessFileContent(physicalFileName), compiler.OutputMimeType, physicalFileName.LastWriteTimeUtc); }
public bool CanCompile(ICompilerFile physicalFileName) { return GetMatchingCompiler(physicalFileName) != null; }
private ISimpleFileCompiler GetMatchingCompiler(ICompilerFile physicalPath) { return _compilers.FirstOrDefault(x => physicalPath.Name.EndsWith(x.OutputFileExtension, StringComparison.OrdinalIgnoreCase) && x.FindInputFileGivenOutput(physicalPath) != null); }