/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { DotlessConfiguration config = DotlessConfiguration.GetDefault(); config.Logger = typeof(LessLogger); EngineFactory engineFactory = new EngineFactory(config); FileSystemReader fileSystemReader = new FileSystemReader(context.FileSystem); return(inputs.AsParallel().Select(context, input => { Trace.Verbose("Processing Less for {0}", input.SourceString()); ILessEngine engine = engineFactory.GetEngine(); // TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache); engine.AsDynamic().Underlying.Underlying.Parser.Importer.FileReader = fileSystemReader; FilePath path = input.FilePath(Keys.RelativeFilePath); string fileName = null; if (path != null) { engine.CurrentDirectory = path.Directory.FullPath; fileName = path.FileName.FullPath; } else { engine.CurrentDirectory = string.Empty; fileName = Path.GetRandomFileName(); } string content = engine.TransformToCss(input.Content, fileName); return context.GetDocument(input, content); })); }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { DotlessConfiguration config = DotlessConfiguration.GetDefault(); config.Logger = typeof(LessLogger); EngineFactory engineFactory = new EngineFactory(config); return(inputs.AsParallel().Select(x => { context.Trace.Verbose("Processing Less for {0}", x.Source); ILessEngine engine = engineFactory.GetEngine(); // TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache); string path = x.Get <string>(Keys.SourceFilePath, null); string fileName = null; if (path != null) { engine.CurrentDirectory = Path.GetDirectoryName(path); fileName = Path.GetFileName(path); } else { engine.CurrentDirectory = context.InputFolder; fileName = Path.GetRandomFileName(); } string content = engine.TransformToCss(x.Content, fileName); return x.Clone(content); })); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { DotlessConfiguration config = DotlessConfiguration.GetDefault(); config.Logger = typeof(LessLogger); EngineFactory engineFactory = new EngineFactory(config); FileSystemReader fileSystemReader = new FileSystemReader(context.FileSystem); return(inputs.AsParallel().Select(context, input => { Trace.Verbose("Processing Less for {0}", input.SourceString()); ILessEngine engine = engineFactory.GetEngine(); // TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache); engine.AsDynamic().Underlying.Underlying.Parser.Importer.FileReader = fileSystemReader; // Less conversion FilePath path = _inputPath.Invoke <FilePath>(input, context); if (path != null) { engine.CurrentDirectory = path.Directory.FullPath; } else { engine.CurrentDirectory = string.Empty; path = new FilePath(Path.GetRandomFileName()); Trace.Warning($"No input path found for document {input.SourceString()}, using {path.FileName.FullPath}"); } string content = engine.TransformToCss(input.Content, path.FileName.FullPath); // Process the result FilePath cssPath = path.ChangeExtension("css"); return context.GetDocument( input, context.GetContentStream(content), new MetadataItems { { Keys.RelativeFilePath, cssPath }, { Keys.WritePath, cssPath } }); })); }