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


C# DotLiquid.Context类代码示例

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


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

示例1: Render

        public override void Render(Context context, TextWriter result)
        {
            var template = context[this._templateName].ToNullOrString();
            if (template == null)
            {
                template = this._templateName;
            }

            context.Registers["layout"] = template;
        }
开发者ID:rajendra1809,项目名称:VirtoCommerce,代码行数:10,代码来源:Layout.cs

示例2: PrepareTemplateContents

        public override string PrepareTemplateContents(string content, Context context, string templateName)
        {
            var templatePage = new TemplatePage(content);

            templatePage.Body = templatePage.Body.Replace("{{ content }}",
                string.Format("{{% block {0}_content -%}}{{% endblock -%}}", templateName));

            WrapWithTemplate(templatePage);

            return templatePage.Body;
        }
开发者ID:rdumont,项目名称:frankie,代码行数:11,代码来源:LiquidTemplateManager.cs

示例3: Render

        public override void Render(Context context, TextWriter result)
        {
            var mutablePagedList = context[_collectionName] as IMutablePagedList;
            var collection = context[_collectionName] as ICollection;
            var pagedList = context[_collectionName] as IPagedList;
            Uri requestUrl;
            Uri.TryCreate(context["request_url"] as string, UriKind.RelativeOrAbsolute, out requestUrl);
            var pageNumber = (int)context["current_page"];
 
            if (mutablePagedList != null)
            {
                mutablePagedList.Slice(pageNumber, _pageSize > 0 ? _pageSize : 20);
                pagedList = mutablePagedList;
            }
            else if (collection != null)
            {
                pagedList = new PagedList<Drop>(collection.OfType<Drop>().AsQueryable(), pageNumber, _pageSize);                
                //TODO: Need find way to replace ICollection instance in liquid context to paged instance
                //var hash = context.Environments.FirstOrDefault(s => s.ContainsKey(_collectionName));
                //hash[_collectionName] = pagedList;
            }

            if (pagedList != null)
            {
                var paginate = new Paginate(pagedList);
                context["paginate"] = paginate;

                for (int i = 1; i <= pagedList.PageCount; i++)
                {
                    paginate.Parts.Add(new Part { IsLink = i != pagedList.PageNumber, Title = i.ToString(), Url = requestUrl != null ? requestUrl.SetQueryParameter("page", i.ToString()).ToString() : i.ToString() });
                }
                RenderAll(NodeList, context, result);
            }
        }
开发者ID:sameerkattel,项目名称:vc-community,代码行数:34,代码来源:PaginateTag.cs

示例4: CompileTemplate

 public override void CompileTemplate(string templatePath)
 {
     var name = GetTemplateName(templatePath);
     var context = new Context();
     var contents = Template.FileSystem.ReadTemplateFile(context, name);
     templatesByName[name] = Template.Parse(contents);
 }
开发者ID:rdumont,项目名称:frankie,代码行数:7,代码来源:LiquidTemplateManager.cs

示例5: Render

        public void Render(Context context, TextWriter result)
        {
            object output = RenderInternal(context);

            if (output is ILiquidizable)
                output = null;

            if (output != null)
            {
                var transformer = Template.GetValueTypeTransformer(output.GetType());
                
                if(transformer != null)
                output = transformer(output);

                //treating Strings as IEnumerable, and was joining Chars in loop
                string outputString = output as string;

                if (outputString != null) {}
                else if (output is IEnumerable)
#if NET35
                    outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>().Select(o => o.ToString()).ToArray());
#else
                    outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>());
#endif
                else if (output is bool)
                    outputString = output.ToString().ToLower();
                else
                    outputString = output.ToString();
                result.Write(outputString);
            }
开发者ID:Elph,项目名称:dotliquid,代码行数:30,代码来源:Variable.cs

示例6: Create

 public static Strainer Create(Context context)
 {
     Strainer strainer = new Strainer(context);
     foreach (var keyValue in Filters)
         strainer.Extend(keyValue.Value);
     return strainer;
 }
开发者ID:strogo,项目名称:dotliquid,代码行数:7,代码来源:Strainer.cs

示例7: Render

        public void Render(Context context, TextWriter result)
        {
            object output = RenderInternal(context);

            if (output is ILiquidizable)
                output = null;

            if (output != null)
            {
                // see if this context has a ValueTypeTranformer for the type
                var transformer = context.GetValueTypeTransformer(output.GetType());
                if (transformer == null)
                {
                    // if the context doesn't have a ValueTypeTranformer for the type, get the global one (if there is one)
                    transformer = Template.GetValueTypeTransformer(output.GetType());
                }

                if(transformer != null)
                    output = transformer(output);

                string outputString;
                if (output is IEnumerable)
            #if NET35
                    outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>().Select(o => o.ToString()).ToArray());
            #else
                    outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>());
            #endif
                else if (output is bool)
                    outputString = output.ToString().ToLower();
                else
                    outputString = output.ToString();
                result.Write(outputString);
            }
开发者ID:NewSpring,项目名称:Rock,代码行数:33,代码来源:Variable.cs

示例8: Display

        public static string Display(Context context, dynamic input)
        {
            if (input == null || !(input is StaticShape)) return string.Empty;

            StaticShape shape = input;

            var wc = context.GetWorkContext();

            // Checking if the shape is displayed multiple times. If yes it can be legitimate (although rare) but
            // can also indicate unwanted recursion, so capping it.
            if (shape.Shape.DisplayedCount == null) shape.Shape.DisplayedCount = 0;

            if (shape.Shape.DisplayedCount >= Constants.MaxAllowedShapeDisplayCount)
            {
                wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many displays of the same shape prevented.");

                return string.Empty;
            }

            shape.Shape.DisplayedCount++;

            if (!context.ShapeIsWithinAllowedRecursionDepth(shape.Metadata.Type))
            {
                wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many recursive shape displays prevented.");

                return string.Empty;
            }

            context.AddCurrentShapeAsParentToShape((IShape)shape.Shape);

            return wc.Resolve<IShapeDisplay>().Display(shape.Shape);
        }
开发者ID:Lombiq,项目名称:Orchard-Liquid-Markup,代码行数:32,代码来源:DisplayFilter.cs

示例9: Render

        public override void Render(Context context, TextWriter result)
        {
            var formName = (context[_formName] ?? _formName).ToString();

            string actionUrl;
            if (_formsMap.TryGetValue(formName, out actionUrl))
            {
                var themeEngine = (ShopifyLiquidThemeEngine)Template.FileSystem;
                var qs = HttpUtility.ParseQueryString(themeEngine.WorkContext.RequestUrl.Query);
                var returnUrl = qs["ReturnUrl"];
                var actionAbsoluteUrl = themeEngine.UrlBuilder.ToAppAbsolute(actionUrl, themeEngine.WorkContext.CurrentStore, themeEngine.WorkContext.CurrentLanguage);

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    actionAbsoluteUrl += string.Concat("?ReturnUrl=", HttpUtility.UrlEncode(returnUrl));
                }

                result.WriteLine("<form accept-charset=\"UTF-8\" action=\"{0}\" method=\"post\" id=\"{1}\">",
                    HttpUtility.HtmlAttributeEncode(actionAbsoluteUrl),
                    HttpUtility.HtmlAttributeEncode(formName));

                RenderAll(NodeList, context, result);

                result.WriteLine("</form>");
            }
            else
            {
                throw new SyntaxException(string.Concat("Unknow form type ", _formName));
            }

        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:31,代码来源:FormTag.cs

示例10: IncludeResource

        protected RequireSettings IncludeResource(string resourceType, string resourcePath, Context context)
        {
            var workContext = context.GetWorkContext();
            var resourceManager = workContext.Resolve<IResourceManager>();
            var pathResolver = workContext.Resolve<ITemplateItemProvidedPathResolver>();

            var renderingContext = context.GetTemplateRenderingContext();
            // If a template file is being rendered then resources paths can be used as usual from themes; if a
            // template item is rendered then relative virtual paths should be handled the same way (those reference
            // flat files).
            if (renderingContext.TemplateType == Models.TemplateType.TemplateFile ||
                (resourcePath.StartsWith("~") && pathResolver.IsRealVirtualPath(resourcePath)))
            {
                var resourceRegister = new ResourceRegister(
                    new DummyWebPage { VirtualPath = renderingContext.TemplatePath },
                    resourceManager,
                    resourceType);
                return resourceRegister.Include(resourcePath);
            }
            else
            {
                if (!resourcePath.StartsWith("//") &&
                    !resourcePath.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
                    !resourcePath.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                {
                    resourcePath = pathResolver.GenerateUrlFromPath(resourcePath);
                }

                return resourceManager.Include(resourceType, resourcePath, resourcePath);
            }
        }
开发者ID:Lombiq,项目名称:Orchard-Liquid-Markup,代码行数:31,代码来源:ResourceManagingTagBase.cs

示例11: Render

        public override void Render(Context context, TextWriter result)
        {
            if (string.IsNullOrEmpty(_classNameParameter)) return;

            dynamic shape = context["Model"];
            shape.Classes.Add(_classNameParameter.EvaluateAsStringProducingParameter(context));
        }
开发者ID:Lombiq,项目名称:Orchard-Liquid-Markup,代码行数:7,代码来源:AddClassToCurrentShapeTag.cs

示例12: Render

		/// <summary>
		/// 描画内容
		/// </summary>
		/// <param name="context"></param>
		/// <param name="result"></param>
		public override void Render(Context context, TextWriter result) {
			// 获取所在区域,没有区域时抛例外
			if (context[Area.CurrentAreaIdKey] == null) {
				throw new FormatException("widget must use inside area");
			}
			// 获取模块名称和参数
			var markup = this.Markup.Trim();
			string widgetPath = null;
			string widgetArgs = null;
			var index = markup.IndexOf(' ');
			if (index > 0) {
				widgetPath = markup.Substring(0, index);
				widgetArgs = markup.Substring(index + 1);
			} else {
				widgetPath = markup;
			}
			// 添加div的开头
			result.Write($"<div class='diy_widget' path='{widgetPath}' args='{widgetArgs}' >");
			// 描画模块的内容
			var scope = widgetArgs == null ? new Hash() : Hash.FromDictionary(
				JsonConvert.DeserializeObject<IDictionary<string, object>>(widgetArgs));
			context.Stack(scope, () => {
				var includeTag = new Include();
				var htmlPath = widgetPath + DiyWidgetInfo.HtmlExtension;
				includeTag.Initialize("include", htmlPath, null);
				includeTag.Render(context, result);
			});
			// 添加div的末尾
			result.Write("</div>");
		}
开发者ID:daywrite,项目名称:ZKWeb,代码行数:35,代码来源:Widget.cs

示例13: EvaluateAsStringProducingParameter

        public static string EvaluateAsStringProducingParameter(this string parameterValue, Context context)
        {
            var evaluatedParameter = parameterValue.EvaluateAsParameter(context);

            if (evaluatedParameter == null) return null;
            if (evaluatedParameter is string) return (string)evaluatedParameter;
            return evaluatedParameter.ToString();
        }
开发者ID:Lombiq,项目名称:Orchard-Liquid-Markup,代码行数:8,代码来源:StringExtensions.cs

示例14: Render

 /// <summary>
 /// Primarily intended for testing.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 internal string Render(Context context)
 {
     using (TextWriter result = new StringWriter())
     {
         Render(context, result);
         return result.ToString();
     }
 }
开发者ID:ostapkoenig,项目名称:dotliquid,代码行数:13,代码来源:Tag.cs

示例15: Render

 public override void Render(Context context, TextWriter result)
 {
     // It's easier to fake every context and create a HtmlHelper to use the ClassForPage() extension. Note that
     // we also need to encode the output (and this is done in the ClassForPage() extension method)!
     context.WriteHtmlHelperOutputToResult(
         html => html.ClassForPage(GetEvaluatedParameters(context)),
         result);
 }
开发者ID:Lombiq,项目名称:Orchard-Liquid-Markup,代码行数:8,代码来源:ClassForPageTag.cs


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