示例#1
0
        public void It_Should_Iterate_Through_A_Nested_Collection()
        {
            // Arrange
            const string templateString = "Result : {% for subarray in array1 %}"
                                          + "<tr>{% for item in subarray %}"
                                          + "<td>{{item}}</td>"
                                          + "{% endfor %}"
                                          + "</tr>{% endfor %}";
            TemplateContext ctx = new TemplateContext();
            var             liquidCollection = new LiquidCollection();

            var numericValues = Enumerable.Range(0, 3).Select(x => (ILiquidValue)LiquidNumeric.Create(x)).ToList();

            foreach (var item in numericValues)
            {
                liquidCollection.Add(Option <ILiquidValue> .Create(item));
            }
            //var array1 = Enumerable.Range(0, 3).Select(x => new LiquidCollection(array2);
            var array1 = new LiquidCollection {
                liquidCollection, liquidCollection, liquidCollection
            };

            ctx.DefineLocalVariable("array1", array1);

            var template = LiquidTemplate.Create(templateString);

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

            // Assert
            String row = "<tr><td>0</td><td>1</td><td>2</td></tr>";

            Assert.Equal("Result : " + row + row + row, result);
        }
示例#2
0
        public void It_Should_Remove_The_Upper_For_Limit()
        {
            // Arrange
            const string     templateString = "Result : {% for item in array%}<li>{{ item }}</li>{% endfor %}";
            ITemplateContext ctx            = new TemplateContext()
                                              .WithNoForLimit();
            var list = new LiquidCollection();

            var items =
                Enumerable.Range(1, 100)
                .Select(LiquidNumeric.Create)
                .Cast <ILiquidValue>().ToList();

            foreach (var item in items)
            {
                //list.Add((Option<ILiquidValue>)item);
                list.Add(Option <ILiquidValue> .Create(item));
            }

            ctx.DefineLocalVariable("array", list);
            var template = LiquidTemplate.Create(templateString);

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

            // Assert
            Assert.Contains("<li>100</li>", result);
        }
        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();
            var             arr            = new LiquidCollection();

            for (int i = 1; i < 10; i++)
            {
                arr.Add(LiquidNumeric.Create(i));
            }

            ctx.DefineLocalVariable("array", arr);
            ctx.DefineLocalVariable("x", LiquidNumeric.Create(2));
            ctx.DefineLocalVariable("y", LiquidNumeric.Create(3));
            ctx.DefineLocalVariable("z", LiquidNumeric.Create(1));
            var template = LiquidTemplate.Create(templateString);

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

            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>"));
        }
        LiquidCollection bodyToLiquid(int indent)
        {
            var col = new LiquidCollection();

            foreach (var b in body)
            {
                col.Add(b.ToLiquidString(indent + 1));
            }
            return(col);
        }
        LiquidCollection ParentCallsToLiquid()
        {
            var liquidCollection = new LiquidCollection();

            foreach (var parentCall in parentCalls)
            {
                liquidCollection.Add(LiquidString.Create(parentCall));
            }
            return(liquidCollection);
        }
示例#6
0
        LiquidCollection ConditionBlocksToLiquid(int indent)
        {
            var col = new LiquidCollection();

            foreach (var c in conditionBlocks)
            {
                col.Add(c.ToLiquidString(indent));
            }
            return(col);
        }
示例#7
0
        private Option <ILiquidValue> CreateCollection(IEnumerable list)
        {
            var coll = new LiquidCollection();

            foreach (var item in list)
            {
                coll.Add(Convert(item)); // may throw exception
            }
            return(coll);
        }
示例#8
0
        LiquidCollection FunctionsToLiquid(int indent)
        {
            var col = new LiquidCollection();

            foreach (var f in components)
            {
                col.Add(LiquidString.Create(f.ToString(indent + 1) + "\n"));
            }
            return(col);
        }
示例#9
0
        LiquidCollection ModifiersToLiquid()
        {
            var col = new LiquidCollection();

            foreach (var mod in modifiers)
            {
                col.Add(LiquidString.Create(mod + " "));
            }
            return(col);
        }
示例#10
0
        public LiquidCollection TokenContractsToLiquid()
        {
            var collection = new LiquidCollection();

            foreach (var tokenConverter in tokenConverters)
            {
                collection.Add(tokenConverter.GetTokenContract().ToLiquidString(0));
            }
            return(collection);
        }
示例#11
0
        public static Option <ILiquidValue> Transform(JArray arr)
        {
            var result = new LiquidCollection();
            var list   = arr.Select(el => (Option <ILiquidValue>)Transform((dynamic)el));

//                .Cast<Option<ILiquidValue>>();
            foreach (var item in list)
            {
                //result.Add(Option<ILiquidValue>.Create(item));
                result.Add(item);
            }
            return(result);
        }
        public LiquidCollection TokenContractsToLiquid()
        {
            var tokenContracts = new LiquidCollection();

            foreach (var tokenConverter in tokenConverters)
            {
                if (tokenConverter.IsOriginalToken())
                {
                    tokenContracts.Add(tokenConverter.GetTokenContract().ToLiquidString(0));
                }
            }
            return(tokenContracts);
        }
示例#13
0
        LiquidCollection ParametersToLiquid()
        {
            var col = new LiquidCollection();

            foreach (var par in parameters)
            {
                if (par != parameters[parameters.Count - 1])
                {
                    par.Name = par.Name + ", ";
                }
                col.Add(par.ToLiquidString());
            }
            return(col);
        }
示例#14
0
        LiquidCollection GetDependencies()
        {
            LiquidCollection liquidCol    = new LiquidCollection();
            HashSet <string> dependencies = new HashSet <string>();

            dependencies.UnionWith(DataModelConverter.GetDependencies());

            foreach (var dependency in dependencies)
            {
                var statement = new SolidityStatement($"import {dependency}");
                liquidCol.Add(statement.ToLiquidString(0));
            }

            return(liquidCol);
        }
示例#15
0
        public void It_Should_Allow_Variables_In_Args()
        {
            // Arrange
            const string    templateString = "Result : {%for i in array limit: x offset: y %}{{ i }}{%endfor%}";
            TemplateContext ctx            = new TemplateContext();
            var             arr            = new LiquidCollection();

            for (var index = 1; index < 10; index++)
            {
                arr.Add(LiquidNumeric.Create(index));
            }
            ctx.DefineLocalVariable("array", arr);

            ctx.DefineLocalVariable("x", LiquidNumeric.Create(2));
            ctx.DefineLocalVariable("y", LiquidNumeric.Create(2));
            var template = LiquidTemplate.Create(templateString);

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

            // Assert
            Assert.Equal("Result : 34", result);
        }