Пример #1
0
        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 "";
        }