当前位置: 首页>>代码示例>>C#>>正文


C# Parser.Parser类代码示例

本文整理汇总了C#中dotless.Core.Parser.Parser的典型用法代码示例。如果您正苦于以下问题:C# Parser类的具体用法?C# Parser怎么用?C# Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Parser类属于dotless.Core.Parser命名空间,在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public void Process(BundleContext context, BundleResponse bundle)
        {
            context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();

            var lessParser = new Parser();
            ILessEngine lessEngine = CreateLessEngine(lessParser);

            var content = new StringBuilder();

            var bundleFiles = new List<BundleFile>();

            foreach (var bundleFile in bundle.Files)
            {
                bundleFiles.Add(bundleFile);

                SetCurrentFilePath(lessParser, bundleFile.VirtualFile.VirtualPath);

                using (var reader = new StreamReader(VirtualPathProvider.OpenFile(bundleFile.VirtualFile.VirtualPath)))
                {
                    content.Append(lessEngine.TransformToCss(reader.ReadToEnd(), bundleFile.VirtualFile.VirtualPath));
                    content.AppendLine();

                    bundleFiles.AddRange(GetFileDependencies(lessParser));
                }
            }

            if (BundleTable.EnableOptimizations)
            {
                // include imports in bundle files to register cache dependencies
                bundle.Files = bundleFiles.Distinct().ToList();
            }

            bundle.ContentType = "text/css";
            bundle.Content = content.ToString();
        }
开发者ID:prashantkhandelwal,项目名称:Bloggy,代码行数:35,代码来源:BundleConfig.cs

示例2: CreateLessEngine

		ILessEngine CreateLessEngine(string path)
		{
			var importer = new Importer(new MulderFileReader(fileSystem, path));
			var parser = new Parser(new PlainStylizer(), importer);
			var engine = new LessEngine(parser) { Compress = true };
			return engine;
		}
开发者ID:wilsonmar,项目名称:mulder,代码行数:7,代码来源:LessFilter.cs

示例3: TransformToCss

        public string TransformToCss(string source, string fileName)
        {
            var sb = new StringBuilder();
            var parameters = parameterSource.GetParameters()
                .Where(ValueIsNotNullOrEmpty);

            var parser = new Parser.Parser();
            sb.Append(source);
            foreach (var parameter in parameters)
            {
                sb.AppendLine();
                var variableDeclaration = string.Format("@{0}: {1};", parameter.Key, parameter.Value);

                try
                {
                    // Attempt to evaluate the generated variable to see if it's OK
                    parser.Parse(variableDeclaration, "").ToCSS(new Env());
                    sb.Append(variableDeclaration);
                }
                catch (ParserException)
                {
                    // Result wasn't valid LESS, output a comment instead
                    sb.AppendFormat("/* Omitting variable '{0}'. The expression '{1}' is not valid. */", parameter.Key,
                        parameter.Value);
                }
            }
            return Underlying.TransformToCss(sb.ToString(), fileName);
        }
开发者ID:Ralphvanderneut,项目名称:dotless,代码行数:28,代码来源:ParameterDecorator.cs

示例4: Primary

        //
        // The `primary` rule is the *entry* and *exit* point of the parser.
        // The rules here can appear at any level of the parse tree.
        //
        // The recursive nature of the grammar is an interplay between the `block`
        // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
        // as represented by this simplified grammar:
        //
        //     primary  →  (ruleset | rule)+
        //     ruleset  →  selector+ block
        //     block    →  '{' primary '}'
        //
        // Only at one point is the primary rule not called from the
        // block rule: at the root level.
        //
        public NodeList Primary(Parser parser)
        {
            Node node;
            var root = new NodeList();
            NodeList comments = null;

            GatherComments(parser);

            while (node = MixinDefinition(parser) || Rule(parser) || PullComments() || Ruleset(parser) ||
                          MixinCall(parser) || Directive(parser))
            {
                if (comments = PullComments())
                {
                    root.AddRange(comments);
                }

                comments = node as NodeList;
                if (comments)
                {
                    foreach (Comment c in comments)
                    {
                        c.IsPreSelectorComment = true;
                    }
                    root.AddRange(comments);
                }
                else
                    root.Add(node);

                GatherComments(parser);
            }
            return root;
        }
开发者ID:WouterBos,项目名称:dotless,代码行数:47,代码来源:Parsers.cs

示例5: Process

        public void Process(BundleContext context, BundleResponse bundle)
        {
            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }

            context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();

            var lessParser = new Parser();
            ILessEngine lessEngine = CreateLessEngine(lessParser);

            var content = new StringBuilder(bundle.Content.Length);

            foreach (FileInfo file in bundle.Files)
            {
                SetCurrentFilePath(lessParser, file.FullName);
                string source = File.ReadAllText(file.FullName);
                content.Append(lessEngine.TransformToCss(source, file.FullName));
                content.AppendLine();

                AddFileDependencies(lessParser);
            }

            bundle.ContentType = "text/css";
            bundle.Content = content.ToString();
        }
开发者ID:peter-dangelo,项目名称:ServiceStackMVC,代码行数:27,代码来源:LessMinify.cs

示例6: Process

        /// <summary>
        /// Processes the specified bundle of LESS files.
        /// </summary>
        /// <param name="context"> </param>
        /// <param name="bundle">The LESS bundle.</param>
        public void Process(BundleContext context, BundleResponse bundle)
        {
            if (bundle == null)
                throw new ArgumentNullException("bundle");

            context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();

            var parser = new Parser();
            var engine = new LessEngine(parser);
            var content = new StringBuilder();
            
            foreach (var file in bundle.Files)
            {
                // set current file path
                SetCurrentFilePath(parser, file.FullName);
                
                var text = File.ReadAllText(file.FullName);
                var css = engine.TransformToCss(text, file.FullName);
                content.AppendLine(css);
                
                // content.Append(engine.TransformToCss(text, file.FullName));
                // content.AppendLine();

                AddFileDependencies(parser);
            }
            
            bundle.Content = content.ToString();
            bundle.ContentType = "text/css";
        }
开发者ID:onebeatconsumer,项目名称:onebeatconsumer.blog,代码行数:34,代码来源:LessTransformer.cs

示例7: GetEngine

 private ILessEngine GetEngine()
 {
     var importer = new Importer(new FileReader(new CustomPathResolver(filePath)));
     var parser = new Parser(new PlainStylizer(), importer);
     var engine = new LessEngine(parser);
     return engine;
 }
开发者ID:nayanak,项目名称:pretzel,代码行数:7,代码来源:FileTransforms.cs

示例8: GetEngine

 private ILessEngine GetEngine()
 {
     var importer = new Importer(new CustomFileReader(fileSystem, filePath));
     var parser = new Parser(new PlainStylizer(), importer);
     var engine = new LessEngine(parser) { Compress = true };
     return engine;
 }
开发者ID:timfish,项目名称:pretzel,代码行数:7,代码来源:LessTransform.cs

示例9: GetLessEngine

 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;
 }
开发者ID:Godoy,项目名称:CMS,代码行数:9,代码来源:LessCssProvider.cs

示例10: GetEngine

        public ILessEngine GetEngine(IFileSystem fileSystem, string directory)
        {
            IStylizer stylizer = new HtmlStylizer();

            IPathResolver pathResolver = new TestPathResolver(directory);
            IFileReader reader = new TestFileReader(fileSystem, pathResolver);
            var importer = new Importer(reader);
            var parser = new Parser(stylizer, importer);
            ILogger logger = new ConsoleLogger(LogLevel.Error);
            return new LessEngine(parser, logger, true, true);
        }
开发者ID:Beatles1692,项目名称:pretzel,代码行数:11,代码来源:TestContainerFactory.cs

示例11: AddFileDependencies

        /// <summary>
        /// Adds imported files to the collection of files on which the current response is dependent.
        /// </summary>
        /// <param name="lessParser">The LESS parser.</param>
        private void AddFileDependencies(Parser lessParser)
        {
            IPathResolver pathResolver = GetPathResolver(lessParser);

            foreach (string importedFilePath in lessParser.Importer.Imports)
            {
                string fullPath = pathResolver.GetFullPath(importedFilePath);
                HttpContext.Current.Response.AddFileDependency(fullPath);
            }

            lessParser.Importer.Imports.Clear();
        }
开发者ID:peter-dangelo,项目名称:ServiceStackMVC,代码行数:16,代码来源:LessMinify.cs

示例12: Generate

            public static string Generate(string fileName, string less, string color1, string color2)
            {
                var reader = new CustomFileReader(color1, color2);
                var importer = new Importer(reader);
                var parser = new Parser(new PlainStylizer(), importer, false);
                var lessEngine = new LessEngine(parser, NullLogger.Instance, true, false);
                less = Regex.Replace(less, "\\.theme-color\\(([a-z-]+),? ?", Evaluate);

                lessEngine.CurrentDirectory = Path.GetDirectoryName(fileName);

                return lessEngine.TransformToCss(less, Path.GetFileName(fileName));
            }
开发者ID:wimr,项目名称:Vidyano,代码行数:12,代码来源:Web2Controller.Less.cs

示例13: Comment

        // We create a Comment node for CSS comments `/* */`,
        // but keep the LeSS comments `//` silent, by just skipping
        // over them.
        public Comment Comment(Parser parser)
        {
            var index = parser.Tokenizer.Location.Index;
            string comment = parser.Tokenizer.GetComment();

            if  (comment != null)
            {
                return NodeProvider.Comment(comment, comment.StartsWith("//"), index);
            }

            return null;
        }
开发者ID:trevorsg,项目名称:dotless,代码行数:15,代码来源:Parsers.cs

示例14: Process

        /// <summary>
        /// The process.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="bundle">
        /// The bundle.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Argument NULL Exception
        /// </exception>
        public void Process(BundleContext context, BundleResponse bundle)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }

            context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();

            var lessParser = new Parser();
            var lessEngine = this.CreateLessEngine(lessParser);

            var content = new StringBuilder(bundle.Content.Length);

            var bundleFiles = new List<BundleFile>();

            foreach (var bundleFile in bundle.Files)
            {
                bundleFiles.Add(bundleFile);
                var filePath = bundleFile.IncludedVirtualPath;
                filePath = filePath.Replace('\\', '/');
                if (filePath.StartsWith("~"))
                {
                    filePath = VirtualPathUtility.ToAbsolute(filePath);
                }

                if (filePath.StartsWith("/"))
                {
                    filePath = HostingEnvironment.MapPath(filePath);
                }

                this.SetCurrentFilePath(lessParser, filePath);
                var source = File.ReadAllText(filePath);
                content.Append(lessEngine.TransformToCss(source, filePath));
                content.AppendLine();

                bundleFiles.AddRange(this.GetFileDependencies(lessParser, bundleFile.VirtualFile));
            }

            if (BundleTable.EnableOptimizations)
            {
                // include imports in bundle files to register cache dependencies
                bundle.Files = bundleFiles.Distinct();
            }

            bundle.ContentType = "text/css";
            bundle.Content = content.ToString();
        }
开发者ID:peter-dangelo,项目名称:AngularJS,代码行数:65,代码来源:LessTransform.cs

示例15: GetParser

 /// <summary>
 /// Construct LESS Parser
 /// </summary>
 /// <param name="file"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 private static Parser GetParser(string file, DotlessConfiguration config)
 {
     var fullPath = HttpContext.Current.Server.MapPath(file);
     var parser = new Parser();
     var fileReader = new WebFileReader(new WebPathResolver(fullPath));
     var importer = new WebImporter(fileReader,
                                       config.DisableUrlRewriting,
                                       config.InlineCssFiles,
                                       config.ImportAllFilesAsLess);
     parser.Importer = importer;
     return parser;
 }
开发者ID:khoanguyen,项目名称:LessMVCFour,代码行数:18,代码来源:WebLessParser.cs


注:本文中的dotless.Core.Parser.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。