public Module Transform(Module module) { string fullModulePath = module.FullPath; string moduleId = module.ModuleId; string content = module.TransformedContent ?? _fileSystem.File.ReadAllText(fullModulePath); dotless.Core.EngineFactory factory = new dotless.Core.EngineFactory(new dotless.Core.configuration.DotlessConfiguration { Debug = true, ImportAllFilesAsLess = true, InlineCssFiles = true, MinifyOutput = true }); // Temporary solution until Pandora is exposed by Dotless. FileReader.FileSystem = _fileSystem; factory.Configuration.LessSource = typeof(FileReader); var engine = factory.GetEngine(); engine.CurrentDirectory = _fileSystem.Path.GetFullPath(_fileSystem.Path.GetDirectoryName(fullModulePath)); var css = engine.TransformToCss(content, moduleId); CssToJsModule cssTransformer = new CssToJsModule(); module.OriginalContent = module.OriginalContent ?? content; module.TransformedContent = cssTransformer.Build(css, moduleId); return(module); }
public string CompileString(string less, string basePath, params string[] libPaths) { var lessFactory = new dotless.Core.EngineFactory(new DotlessConfiguration() { MinifyOutput = true }); less = ResolveImports(less, basePath, libPaths); return lessFactory.GetEngine().TransformToCss(less, SanitizePath(basePath)); }
public void ProcessRequest(HttpContext context) { var host = Host.Get(Host.DefaultId); var lastModifiedDateUtc = Configuration.LastModifiedDateUtc; if (lastModifiedDateUtc > DateTime.UtcNow) { lastModifiedDateUtc = DateTime.UtcNow; } context.Response.ContentType = "text/css"; var cacheKey = CacheKey + host.AbsoluteUrl("~/"); var cachedStyleSheet = host.Cache.Get(cacheKey) as CachedStyleSheet; if (cachedStyleSheet == null || cachedStyleSheet.LastModifiedDateUtc < lastModifiedDateUtc) { cachedStyleSheet = new CachedStyleSheet(); cachedStyleSheet.LastModifiedDateUtc = lastModifiedDateUtc; cachedStyleSheet.StyleSheet = string.Empty; var styleSheets = Configuration.StyleSheets; if (styleSheets != null) { var less = string.Join("\n", styleSheets); var config = new dotless.Core.configuration.DotlessConfiguration(); config.CacheEnabled = false; config.Debug = false; config.DisableParameters = false; config.DisableUrlRewriting = true; config.DisableVariableRedefines = false; config.HandleWebCompression = false; config.ImportAllFilesAsLess = false; config.InlineCssFiles = false; config.KeepFirstSpecialComment = false; config.MapPathsToWeb = false; config.MinifyOutput = false; config.Web = false; config.LessSource = typeof(LessFileReader); config.LogLevel = dotless.Core.Loggers.LogLevel.Warn; config.Logger = typeof(DotLessLogger); config.SessionMode = dotless.Core.configuration.DotlessSessionStateMode.Disabled; try { var engine = new dotless.Core.EngineFactory(config).GetEngine(); cachedStyleSheet.StyleSheet = engine.TransformToCss(UpdateEmbeddedFileReferences(context, less), null) + ((DotLessLogger)((dotless.Core.LessEngine)((dotless.Core.ParameterDecorator)engine).Underlying).Logger).GetMessages(); } catch (Exception ex) { host.LogError("An error occurred while processing LESS directives in stylesheets.", ex); context.Response.StatusCode = 500; return; } } host.Cache.Put(cacheKey, cachedStyleSheet, 30 * 60); } context.Response.Cache.SetAllowResponseInBrowserHistory(true); context.Response.Cache.SetLastModified(lastModifiedDateUtc); context.Response.Cache.SetETag(lastModifiedDateUtc.Ticks.ToString()); context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetExpires(DateTime.UtcNow.AddHours(2)); context.Response.Cache.SetValidUntilExpires(false); context.Response.Write(cachedStyleSheet.StyleSheet); }