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


C# VelocityEngine.MergeTemplate方法代码示例

本文整理汇总了C#中NVelocity.App.VelocityEngine.MergeTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# VelocityEngine.MergeTemplate方法的具体用法?C# VelocityEngine.MergeTemplate怎么用?C# VelocityEngine.MergeTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NVelocity.App.VelocityEngine的用法示例。


在下文中一共展示了VelocityEngine.MergeTemplate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeTemplate

        /// <summary>
        /// Merge the specified Velocity template with the given model and write
        /// the result to the given Writer.
        /// </summary>
        /// <param name="velocityEngine">VelocityEngine to work with</param>
        /// <param name="templateLocation">the location of template, relative to Velocity's resource loader path</param>
        /// <param name="encoding">encoding the encoding of the template file</param>
        /// <param name="model">the Hashtable that contains model names as keys and model objects</param>
        /// <param name="writer">writer the TextWriter to write the result to</param>
        /// <exception cref="VelocityException">thrown if any exception is thrown by the velocity engine</exception>		
        public static void MergeTemplate(
            VelocityEngine velocityEngine, string templateLocation, string encoding, Hashtable model, TextWriter writer) {

            try {
                VelocityContext velocityContext = new VelocityContext(model);
                velocityEngine.MergeTemplate(templateLocation, encoding, velocityContext, writer);
            } catch (VelocityException) {
                throw;
            } catch (Exception ex) {
                throw new VelocityException(ex.ToString(), ex);
            }
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:22,代码来源:VelocityEngineUtils.cs

示例2: CreateSqlOutput

        /// <summary>
        /// Creates a velocity engine that is initiated.  It loads up
        /// templates from the 'Templates' folder.
        /// </summary>
        /// <returns></returns>
        protected virtual string CreateSqlOutput(IEnumerable<Migration> migrations)
        {
            VelocityEngine velocityEngine = new VelocityEngine();

            ExtendedProperties extendedProperties = new ExtendedProperties();
            extendedProperties.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory + "\\Templates");

            velocityEngine.Init(extendedProperties);

            var context = new VelocityContext();
            context.Put("migrations", migrations.OrderBy(migration => migration.MigrationDate));

            var stringWriter = new StringWriter();
            velocityEngine.MergeTemplate("deployment_tsql.vm", "ISO-8859-1", context, stringWriter);

            return stringWriter.GetStringBuilder().ToString();
        }
开发者ID:tommyk,项目名称:SqlMigration,代码行数:22,代码来源:DeploymentTask.cs

示例3: GetString

        /// <summary>
        /// 生成内容
        /// </summary>
        /// <returns></returns>
        public string GetString()
        {
            VelocityEngine ve = new VelocityEngine();//模板引擎实例化
            ExtendedProperties ep = new ExtendedProperties();//模板引擎参数实例化

            ep.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)300); //缓存时间(秒)
            ve.Init(ep);

            VelocityContext vc = new VelocityContext(); //当前的数据信息载体集合

            foreach (var item in Items)
            {
                vc.Put(item.Key, item.Value);
            }
            TextWriter writer = new StringWriter();
            ve.MergeTemplate(TemplateName, "utf-8", vc, writer);

            return writer.ToString();
        }
开发者ID:kuibono,项目名称:KCMS2,代码行数:23,代码来源:Helper.cs

示例4: RenderTemplate

        public string RenderTemplate(string masterPage, string templateName, IDictionary<string, object> data)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentException("The \"templateName\" parameter must be specified", "templateName");
            }

            var name = !string.IsNullOrEmpty(masterPage)
                 ? masterPage : templateName;

            var engine = new VelocityEngine();
            var props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, _templatesPath);
            engine.Init(props);
            var template = engine.GetTemplate(name);
            template.Encoding = Encoding.UTF8.BodyName;
            var context = new VelocityContext();

            var templateData = data ?? new Dictionary<string, object>();
            foreach (var key in templateData.Keys)
            {
                context.Put(key, templateData[key]);
            }

            if (!string.IsNullOrEmpty(masterPage))
            {
                context.Put("childContent", templateName);
            }

            using (var writer = new StringWriter())
            {
                engine.MergeTemplate(name, context, writer);
                return writer.GetStringBuilder().ToString();
            }
        }
开发者ID:leon737,项目名称:MvcBlanket,代码行数:35,代码来源:NVelocityTemplateRepository.cs


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