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


C# Writer.RenderTokens方法代码示例

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


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

示例1: Render

        /// <summary>
        /// Renders a tokens representation if the value (or interpolated value result)
        /// is truthy
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered result of the token if the resolved value is not truthy</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var value = context.Lookup(Value);
            value = InterpolateLambdaValueIfPossible(value, writer, context, partials);

            return !context.IsTruthyValue(value) ? writer.RenderTokens(ChildTokens, context, partials, originalTemplate) : null;
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:16,代码来源:InvertedToken.cs

示例2: Render

        /// <summary>
        /// Renders a named partial template if one exists with the given context
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered partial template</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var value = partials != null && partials.ContainsKey(Value) ? partials[Value] : null;
            if (value == null && context.Registry.PartialTemplateLoader != null)
            {
                value = context.Registry.PartialTemplateLoader.Load(Value);
            }

            return value != null ? writer.RenderTokens(writer.Parse(value), context, partials, value) : null;
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:18,代码来源:PartialToken.cs

示例3: Render

        /// <summary>
        /// Returns the rendered result of all the child tokens of the section
        /// if the token value is truthy
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered result of all the sections children</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var buffer = new StringBuilder();
            var value = context.Lookup(Value);

            if (!context.IsTruthyValue(value))
            {
                return null;
            }

            if (value is IEnumerable && !EnumerableBlacklist.Any(x => x.IsInstanceOfType(value)))
            {
                var arrayValue = value as IEnumerable;

                foreach (var v in arrayValue)
                {
                    buffer.Append(writer.RenderTokens(ChildTokens, context.Push(v), partials, originalTemplate));
                }
            }
            else if (value is IEnumerator)
            {
                var enumeratorValue = value as IEnumerator;
                while (enumeratorValue.MoveNext())
                {
                    buffer.Append(writer.RenderTokens(ChildTokens, context.Push(enumeratorValue.Current), partials, originalTemplate));
                }
            }
            else if (value is Func<dynamic, string, object> || value is Func<string, object>)
            {
                var functionDynamicValue = value as Func<dynamic, string, object>;
                var functionStringValue = value as Func<string, object>;
                var sectionContent = originalTemplate.Slice(End, ParentSectionEnd);
                value = functionDynamicValue != null ? functionDynamicValue.Invoke(context.View, sectionContent) : functionStringValue.Invoke(sectionContent);
                value = writer.Render(value.ToString(), context, partials, Tags);

                if (value != null)
                {
                    buffer.Append(value);
                }
            }
            else if (value is IDictionary || value != null)
            {
                buffer.Append(writer.RenderTokens(ChildTokens, context.Push(value), partials, originalTemplate));
            }

            return buffer.ToString();
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:56,代码来源:SectionToken.cs


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