public string TransformToCss(string source, string fileName) { try { Parser.StrictMath = StrictMath; var tree = Parser.Parse(source, fileName); var env = Env ?? new Env(Parser) { Compress = Compress, Debug = Debug, KeepFirstSpecialComment = KeepFirstSpecialComment, DisableVariableRedefines = DisableVariableRedefines, DisableColorCompression = DisableColorCompression }; if (Plugins != null) { foreach (IPluginConfigurator configurator in Plugins) { env.AddPlugin(configurator.CreatePlugin()); } } var css = tree.ToCSS(env); var stylizer = new PlainStylizer(); foreach (var unmatchedExtension in env.FindUnmatchedExtensions()) { Logger.Warn("Warning: extend '{0}' has no matches {1}\n", unmatchedExtension.BaseSelector.ToCSS(env).Trim(), stylizer.Stylize(new Zone(unmatchedExtension.Extend.Location)).Trim()); } tree.Accept(DelegateVisitor.For <Media>(m => { foreach (var unmatchedExtension in m.FindUnmatchedExtensions()) { Logger.Warn("Warning: extend '{0}' has no matches {1}\n", unmatchedExtension.BaseSelector.ToCSS(env).Trim(), stylizer.Stylize(new Zone(unmatchedExtension.Extend.Location)).Trim()); } })); LastTransformationSuccessful = true; return(css); } catch (ParserException e) { LastTransformationSuccessful = false; LastTransformationError = e; Logger.Error(e.Message); } return(""); }
private ILessEngine GetLessEngine(string physicalPath) { var basePath = Path.GetDirectoryName(physicalPath); var stylizer = new PlainStylizer(); var importer = new Importer(new FileReader(new BasePathResolver(basePath))); var parser = new Parser(stylizer, importer) { NodeProvider = new RawUrlNodeProvider() }; var lessEngine = new LessEngine(parser); return(lessEngine); }
public Dotless(DotlessOptions options = null) { if (options == null) { options = new DotlessOptions(); // defaults } _config = DotlessConfiguration.GetDefault(); _config.KeepFirstSpecialComment = options.KeepFirstSpecialComment; _config.RootPath = options.RootPath; if (!String.IsNullOrWhiteSpace(_config.RootPath) && !_config.RootPath.EndsWith("/")) { _config.RootPath += "/"; } _config.InlineCssFiles = options.InlineCssFiles; _config.ImportAllFilesAsLess = options.ImportAllFilesAsLess; _config.MinifyOutput = options.MinifyOutput; _config.Debug = options.Debug; _config.Optimization = options.Optimization; _config.StrictMath = options.StrictMath; _cssToLess = new FilenameTransform(options.CssMatchPattern, options.LessSourceFilePattern); _stylizer = new PlainStylizer(); }