示例#1
0
 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;
 }
示例#2
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 "";
        }