• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Parser.Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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 List<Node> Primary(Parser parser)
        {
            Node node;
            var root = new List<Node>();

            while (node = MixinDefinition(parser) || Rule(parser) || Ruleset(parser) ||
                          MixinCall(parser) || Comment(parser) || Directive(parser))
            {
                root.Add(node);
            }
            return root;
        }
开发者ID:NickCraver,项目名称:dotless,代码行数:27,代码来源:Parsers.cs


示例17: LessEngine

 public LessEngine(Parser.Parser parser, ILogger logger, bool compress, bool debug, bool disableVariableRedefines, bool disableColorCompression, bool keepFirstSpecialComment, bool strictMath, IEnumerable<IPluginConfigurator> plugins)
 {
     Parser = parser;
     Logger = logger;
     Compress = compress;
     Debug = debug;
     DisableVariableRedefines = disableVariableRedefines;
     Plugins = plugins;
     KeepFirstSpecialComment = keepFirstSpecialComment;
     DisableColorCompression = disableColorCompression;
     StrictMath = strictMath;
 }
开发者ID:Ralphvanderneut,项目名称:dotless,代码行数:12,代码来源:LessEngine.cs


示例18: ReadFileContent

        protected override string ReadFileContent(string fileSystemPath, bool minify)
        {
            var directory = Path.GetDirectoryName(fileSystemPath);
            var pathResolver = new AbsolutePathResolver(directory);
            var fileReader = new FileReader { PathResolver = pathResolver };
            var importer = new Importer { FileReader = fileReader };
            var parser = new Parser { Importer = importer };
            var lessEngine = new LessEngine { Parser = parser };

            var rawFileContent = base.ReadFileContent(fileSystemPath, false);

            return lessEngine.TransformToCss(rawFileContent, fileSystemPath);
        }
开发者ID:rmacfie,项目名称:Ominify,代码行数:13,代码来源:DotLessPackage.cs


示例19: GetPathResolver

        /// <summary>
        /// Returns an <see cref="IPathResolver"/> instance used by the specified LESS lessParser.
        /// </summary>
        /// <param name="lessParser">The LESS prser.</param>
        private IPathResolver GetPathResolver(Parser lessParser)
        {
            var importer = lessParser.Importer as Importer;
            if (importer != null)
            {
                var fileReader = importer.FileReader as FileReader;
                if (fileReader != null)
                {
                    return fileReader.PathResolver;
                }
            }

            return null;
        }
开发者ID:peter-dangelo,项目名称:ServiceStackMVC,代码行数:18,代码来源:LessMinify.cs


示例20: Compile

        public CompileResult Compile(string source, CompileContext context)
        {
            var sourceFile = context.RootDirectory.GetFile(context.SourceFilePath);
            importedFilePaths = new HashedSet<string>();
            var parser = new Parser
            {
                Importer = new Importer(new CassetteLessFileReader(sourceFile.Directory, importedFilePaths))
            };
            var errorLogger = new ErrorLogger();
            var engine = new LessEngine(
                                    parser,
                                    errorLogger,
                                    configuration.MinifyOutput,
                                    configuration.Debug,
                                    configuration.DisableVariableRedefines,
                                    configuration.DisableColorCompression,
                                    configuration.KeepFirstSpecialComment,
                                    configuration.Plugins);

            string css;
            try
            {
                css = engine.TransformToCss(source, sourceFile.FullPath);
            }
            catch (Exception ex)
            {
                throw new LessCompileException(
                    string.Format("Error compiling {0}{1}{2}", context.SourceFilePath, Environment.NewLine, ex.Message),
                    ex
                );
            }

            if (errorLogger.HasErrors)
            {
                var exceptionMessage = string.Format(
                    "Error compiling {0}{1}{2}",
                    context.SourceFilePath,
                    Environment.NewLine,
                    errorLogger.ErrorMessage
                );
                throw new LessCompileException(exceptionMessage);
            }
            else
            {
                return new CompileResult(css, importedFilePaths);
            }
        }
开发者ID:joplaal,项目名称:cassette,代码行数:47,代码来源:LessCompiler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Sdk.ApiContext类代码示例发布时间:2022-05-26
下一篇:
C# docsoft.jgrid类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap