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


C# TemplateContext.DefineLocalVariable方法代码示例

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


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

示例1: It_Should_Allow_Variables_In_Args

        public void It_Should_Allow_Variables_In_Args()
        {
            // Arrange
            const string templateString = "Result : {% tablerow i in array cols: x limit: y offset: z %}{{ i }}{% endtablerow %}";
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("array",
                new ArrayValue(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Select(x => (IExpressionConstant)NumericValue.Create(x)).ToList())
                );
            ctx.DefineLocalVariable("x", NumericValue.Create(2));
            ctx.DefineLocalVariable("y", NumericValue.Create(3));
            ctx.DefineLocalVariable("z", NumericValue.Create(1));
            var template = LiquidTemplate.Create(templateString);

            // Act
            String result = template.Render(ctx);
            Logger.Log(result);

            // Assert
            Assert.That(result, Is.StringContaining("<tr class=\"row1\">"));
            Assert.That(result, Is.StringContaining("<tr class=\"row2\">"));
            Assert.That(result, Is.Not.StringContaining("<tr class=\"row3\">"));
            Assert.That(result, Is.Not.StringContaining(">1</td>"));
            Assert.That(result, Is.StringContaining(">2</td>"));
            Assert.That(result, Is.StringContaining(">4</td>"));
            Assert.That(result, Is.Not.StringContaining(">5</td>"));
            
        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:27,代码来源:TableRowBlockTagTests.cs

示例2: It_Should_Ignore_Missing_Plural

        public void It_Should_Ignore_Missing_Plural()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("input", new StringValue("1"));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize: 'thing' }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : 1 thing"));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:11,代码来源:PluralizeFilterTests.cs

示例3: It_Should_Return_The_String_When_Insufficient_Args

        public void It_Should_Return_The_String_When_Insufficient_Args()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("input", new StringValue("1"));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : 1" ));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:11,代码来源:PluralizeFilterTests.cs

示例4: It_Should_Pluralize_A_String

        [TestCase("z", "0 things")] // I  think this is what should happen...?
        public void It_Should_Pluralize_A_String(String input, String expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("input", new StringValue(input));
            var result = RenderingHelper.RenderTemplate("Result : {{ input | pluralize: 'thing', 'things' }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : " + expected));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:12,代码来源:PluralizeFilterTests.cs

示例5: It_Should_Format_A_Date

        public void It_Should_Format_A_Date(String format, string expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            DateTime dateTime = new DateTime(2015, 3, 30, 23, 1, 12);
            ctx.DefineLocalVariable("mydate", new DateValue(dateTime));
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ mydate | date: \""+format+"\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : "+expected));
        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:12,代码来源:DateFilterTests.cs

示例6: It_Should_Not_Work_For_A_Numeric_Value

        public void It_Should_Not_Work_For_A_Numeric_Value()
        {
            // Arrange
            var ctx = new TemplateContext();
            ctx.DefineLocalVariable("array", CreateArray());

            // Act
            var result = RenderingHelper.RenderTemplate("{%if 3 contains 3 %}TRUE{% else %}FALSE{% endif %}");

            // Assert
            Assert.That(result, Is.StringContaining("FALSE")); // TODO: SHould this be an error?
        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:12,代码来源:ContainsExpressionTests.cs

示例7: It_Should_Ignore_An_Empty_Date

        public void It_Should_Ignore_An_Empty_Date()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("mydate", new DateValue(null));
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ mydate | date: \"%y\" }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : "));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:12,代码来源:DateFilterTests.cs

示例8: It_Should_MD5_Hash_A_String

        public void It_Should_MD5_Hash_A_String()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("email", new StringValue("[email protected]"));
            const string tmpl = "<img src=\"https://www.gravatar.com/avatar/{{ email | md5 }}\" />";
            var result = RenderingHelper.RenderTemplate(tmpl, ctx);
            Logger.Log(result);
            // Assert
            Assert.That(result,
                Is.EqualTo("<img src=\"https://www.gravatar.com/avatar/517ea04cf362ddc08f107f6ef98a12d9\" />"));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:13,代码来源:Md5FilterTests.cs

示例9: It_Should_Determine_If_An_Dictionary_Contains_A_KEy

        public void It_Should_Determine_If_An_Dictionary_Contains_A_KEy(String contains, String expected)
        {
            // Arrange
            var ctx = new TemplateContext();
            ctx.DefineLocalVariable("dict", CreateDictionary());

            // Act
            var result = RenderingHelper.RenderTemplate("{%if dict contains " + contains + " %}TRUE{% else %}FALSE{% endif %}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo(expected));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:13,代码来源:ContainsExpressionTests.cs

示例10: It_Should_Slice_An_Array

        public void It_Should_Slice_An_Array(String slice, string expected)
        {
            // Arrange
            var ctx = new TemplateContext();
            ctx.DefineLocalVariable("array", CreateArray());
            // Act
            var result = RenderingHelper.RenderTemplate("Result : {{ array | slice : " + slice + " }}", ctx);

            // Assert
            Assert.That(result, Is.EqualTo("Result : "+expected));


        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:13,代码来源:SliceFilterTests.cs

示例11: It_Should_Dereference_Properties_Of_Array

        public void It_Should_Dereference_Properties_Of_Array(String property, String expected)
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            var arrayValue = DataFixtures.CreateArrayValue();
            ctx.DefineLocalVariable("myarray", arrayValue);
            String tmpl = "{{ myarray." + property + " }}";

            // Act
            var result = RenderingHelper.RenderTemplate(tmpl, ctx);

            // Assert          
            Assert.That(result, Is.EqualTo(expected));
        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:14,代码来源:IndexDereferencerTests.cs

示例12: It_Should_Evaluate_An_Expresson

        public void It_Should_Evaluate_An_Expresson()
        {
            // Arrange
            ITemplateContext ctx = new TemplateContext().WithAllFilters();
            ctx.DefineLocalVariable("array", CreateArrayValues());
            var template = LiquidTemplate.Create("{% assign foo = \"test\" | upcase %}{{ foo }}");

            // Act
            String result = template.Render(ctx);

            // Assert
            Assert.That(result, Is.EqualTo("TEST"));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:14,代码来源:AssignTagTests.cs

示例13: It_Refer_To_Another_Variable

        public void It_Refer_To_Another_Variable()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();
            ctx.DefineLocalVariable("array", CreateArrayValues());
            var template = LiquidTemplate.Create("{% assign foo = array %}{{ foo[1] }}");

            // Act
            String result = template.Render(ctx);

            // Assert
            Assert.That(result, Is.EqualTo("123"));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:14,代码来源:AssignTagTests.cs

示例14: It_Should_Allow_An_Int_Variable

        public void It_Should_Allow_An_Int_Variable()
        {
            // Arrange
            ITemplateContext ctx = new TemplateContext().WithAllFilters();
            ctx.DefineLocalVariable("bar", NumericValue.Create(3) );
            var template = LiquidTemplate.Create("{{ 1 | plus: bar }}");

            // Act
            String result = template.Render(ctx);
            Logger.Log(result);

            // Assert
            Assert.That(result, Is.EqualTo("4"));
        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:14,代码来源:FilterChainTests.cs

示例15: It_Should_Reference_A_Defined_Name

        public void It_Should_Reference_A_Defined_Name()
        {
            // Arrange
            const string varname = "hello";
            var templateContext = new TemplateContext();            
            templateContext.DefineLocalVariable(varname, new StringValue("HELLO"));

            // Act
            var result = templateContext.SymbolTableStack.Reference(varname);

            // Assert
            Assert.That(result.SuccessValue<StringValue>().StringVal, Is.EqualTo("HELLO"));

        }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:14,代码来源:TemplateContextTests.cs


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