Exemple #1
0
        public void It_Should_Find_The_Parent_Loop()
        {
            TemplateContext ctx = new TemplateContext();

            //ctx.Define("outer", new LiquidCollection(new List<ILiquidValue> { new LiquidNumeric(1), new LiquidNumeric(1), new LiquidNumeric(1) }));
            ctx.DefineLocalVariable("outer", DictionaryFactory.CreateArrayFromJson("[[1, 1, 1], [1, 1, 1]]"));

            var template = LiquidTemplate.Create("Result :{% for inner in outer %}{% for k in inner %} {{ forloop.parentloop.index }}.{{ forloop.index }}{% endfor %}{% endfor %}");

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

            // Assert
            Assert.Equal("Result : 1.1 1.2 1.3 2.1 2.2 2.3", result);
        }
        public void It_Should_Render_A_Table_Row_From_A_String()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("numbers", DictionaryFactory.CreateArrayFromJson("[1, 2, 3, 4, 5, 6]"));
            var template = LiquidTemplate.Create(@"{% tablerow n in ""Test"" cols:2%}ITER{{n}}{% endtablerow %}");

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

            Logger.Log(result);
            String expected =
                "<tr class=\"row1\">\r\n<td class=\"col1\">ITERTest</td></tr>";

            // Act

            // Assert
            Assert.That(result, Is.StringContaining(expected));
        }
        public void It_Should_Render_A_Table_Row()
        {
            // Arrange
            TemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("numbers", DictionaryFactory.CreateArrayFromJson("[1, 2, 3, 4, 5, 6]"));
            var template = LiquidTemplate.Create(@"{% tablerow n in numbers cols:2%}ITER{{n}}{% endtablerow %}");

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

            Logger.Log(result);
            String expected =
                "<tr class=\"row1\">\r\n" +
                @"<td class=""col1"">ITER1</td><td class=""col2"">ITER2</td></tr>" + "\r\n" +
                @"<tr class=""row2""><td class=""col1"">ITER3</td><td class=""col2"">ITER4</td></tr>" + "\r\n" +
                @"<tr class=""row3""><td class=""col1"">ITER5</td><td class=""col2"">ITER6</td></tr>";

            // Act

            // Assert
            Assert.Contains(expected, result);
        }