private string Transform(string less, TestPath path) { var engine = new EngineFactory().GetEngine(); engine.CurrentDirectory = path.Directory; return engine.TransformToCss(less, path.FileName); }
public void Process(ToolContext context) { foreach (WorkfileContext workContext in context.Workfiles) { Directory.SetCurrentDirectory(workContext.OriginalSource.DirectoryName); if (Path.GetExtension(workContext.Workfile.Name).ToLower() == ".less") { string compressed = null; using (var reader = new StreamReader(workContext.Workfile.FullName, true)) { var engine = new EngineFactory(new DotlessConfiguration() { CacheEnabled = false, MinifyOutput = false, Web = false, }).GetEngine(); compressed = engine.TransformToCss(reader.ReadToEnd(), null); IEnumerable<string> l = engine.GetImports(); } string newFileName = Path.Combine(workContext.Workfile.DirectoryName, Path.GetFileNameWithoutExtension(workContext.Workfile.Name)) + ".css"; workContext.Workfile.MoveTo(newFileName); using (var writer = new StreamWriter(newFileName, false)) { writer.Write(compressed); } } } }
public void ProcessRequest(HttpContextBase context) { var physicalPath = context.Server.MapPath(context.Request.Path); var querystring = context.Request.QueryString.ToString(); var response = context.Response; try { var source = fileWrapper.GetFileString(physicalPath); var engine = new EngineFactory(new DotlessConfiguration { CacheEnabled = false, Logger = typeof (LessLogger), Web = HttpContext.Current != null } ).GetEngine(); var lessEngine = (LessEngine) ((ParameterDecorator) engine).Underlying; ((LessLogger)lessEngine.Logger).Response = response; var result = engine.TransformToCss(source, physicalPath + (string.IsNullOrWhiteSpace(querystring) ? string.Empty : "?" + querystring)); response.ContentType = "text/css"; if(!string.IsNullOrEmpty(result)) response.Write(result); } catch (System.IO.FileNotFoundException ex) { response.StatusCode = 404; response.Write("/* File Not Found while parsing: " + ex.Message + " */"); } catch (System.Exception ex) { response.StatusCode = 500; response.Write("/* Error in less parsing: " + ex.Message + " */"); } }
private string GenerateCss(string import, BundleContext context) { var configuration = new WebConfigConfigurationLoader().GetConfiguration(); configuration.DisableParameters = true; var logger = new InMemoryLogger(configuration.LogLevel); var engine = new EngineFactory(configuration).GetEngine(CreateContainer(context, logger)); var cssOutput = engine.TransformToCss(import, context.BundleVirtualPath); if (!engine.LastTransformationSuccessful) { return logger.GetOutput(); } return cssOutput; }
private static string LessToCss(string css, string fileName) { var current = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(new FileInfo(FilePath(fileName)).DirectoryName); var engine = new EngineFactory().GetEngine(new DotlessConfiguration { MinifyOutput = false }); string cssText = engine.TransformToCss(new LessSourceObject { Content = css, }); Directory.SetCurrentDirectory(current); return cssText; }
public string GetCss(string lessSource, Assembly contextAssembly) { var engine = new EngineFactory().GetEngine(); return engine.TransformToCss((contextAssembly != null ? GetLessVariableDefinitions(contextAssembly) + Environment.NewLine : "") + lessSource, "Module.less"); }