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(""); }
public override Node Evaluate(Env env) { OriginalPath = OriginalPath.Evaluate(env); var quoted = OriginalPath as Quoted; if (quoted != null) { Path = quoted.Value; } ImportAction action = GetImportAction(env.Parser.Importer); if (action == Importers.ImportAction.ImportNothing) { return(new NodeList().ReducedFrom <NodeList>(this)); } Node features = null; if (Features) { features = Features.Evaluate(env); } if (action == ImportAction.LeaveImport) { return(new Import(OriginalPath, features)); } if (action == ImportAction.ImportCss) { var importCss = new Import(OriginalPath, null) { _importAction = ImportAction.ImportCss, InnerContent = InnerContent }; if (features) { return(new Media(features, new NodeList() { importCss })); } return(importCss); } using (env.Parser.Importer.BeginScope(this)) { if (IsReference || IsOptionSet(ImportOptions, ImportOptions.Reference)) { // Walk the parse tree and mark all nodes as references. IsReference = true; IVisitor referenceImporter = null; referenceImporter = DelegateVisitor.For <Node>(node => { var ruleset = node as Ruleset; if (ruleset != null) { if (ruleset.Selectors != null) { ruleset.Selectors.Accept(referenceImporter); ruleset.Selectors.IsReference = true; } if (ruleset.Rules != null) { ruleset.Rules.Accept(referenceImporter); ruleset.Rules.IsReference = true; } } var media = node as Media; if (media != null) { media.Ruleset.Accept(referenceImporter); } var nodeList = node as NodeList; if (nodeList != null) { nodeList.Accept(referenceImporter); } node.IsReference = true; return(node); }); Accept(referenceImporter); } NodeHelper.ExpandNodes <Import>(env, InnerRoot.Rules); } var rulesList = new NodeList(InnerRoot.Rules).ReducedFrom <NodeList>(this); if (features) { return(new Media(features, rulesList)); } return(rulesList); }