Beispiel #1
0
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("conditionBlocks", ConditionBlocksToLiquid(indent));
            return(template.Render(ctx).Result);
        }
        /// <summary>
        /// Generates the solidity code
        /// </summary>
        /// <returns>Solidity code in string</returns>
        public string GenerateSolidity()
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("contract", solidityContract.ToLiquidString(0));

            return(template.Render(ctx).Result);
        }
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("body", bodyToLiquid(indent));
            return(template.Render(ctx).Result);
        }
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("mappingStatement", GetMappingStatement(nestedProperties)).
            DefineLocalVariable("mappingName", LiquidString.Create(mappingName));
            return(outerTemplate.Render(ctx).Result);
        }
        public override string ToString(int indent = 0)
        {
            var ctx = new TemplateContext();

            ctx.DefineLocalVariable("components", FunctionsToLiquid(indent)).
            DefineLocalVariable("name", LiquidString.Create(name));

            return(template.Render(ctx).Result);
        }
Beispiel #6
0
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("enumName", enumName).
            DefineLocalVariable("values", ValuesToLiquid(indent));
            return(template.Render(ctx).Result);
        }
Beispiel #7
0
        public string GetSolidityCode()
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("maincontract", mainSolidityContract.ToLiquidString(0))
            .DefineLocalVariable("tokencontracts", DataModelConverter.TokenContractsToLiquid())
            .DefineLocalVariable("imports", GetDependencies());
            return(template.Render(ctx).Result);
        }
Beispiel #8
0
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("varName", LiquidString.Create(loopVariableName)).
            DefineLocalVariable("loopCount", LiquidString.Create(loopCountVariable)).
            DefineLocalVariable("body", body.ToLiquidString(indent + 1));
            return(template.Render(ctx).Result);
        }
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("name", modifierName).
            DefineLocalVariable("parameters", ParametersToLiquid()).
            DefineLocalVariable("body", BodyToLiquid(indent));
            return(template.Render(ctx).Result);
        }
Beispiel #10
0
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("condition", LiquidString.Create(condition)).
            DefineLocalVariable("isElse", new LiquidBoolean(isElse)).
            DefineLocalVariable("blockBody", blockBody.ToLiquidString(indent + 1));
            return(template.Render(ctx).Result);
        }
        public override string ToString(int indent = 0)
        {
            ITemplateContext ctx = new TemplateContext();

            ctx.DefineLocalVariable("indent", CreateIndent(indent)).
            DefineLocalVariable("name", functionName).
            DefineLocalVariable("parameters", ParametersToLiquid()).
            DefineLocalVariable("visibility", visibility).
            DefineLocalVariable("body", BodyToLiquid(indent)).
            DefineLocalVariable("modifiers", ModifiersToLiquid()).
            DefineLocalVariable("isView", new LiquidBoolean(isView)).
            DefineLocalVariable("returns", returns);
            return(template.Render(ctx).Result);
        }
        public void Render_NullContext_Throws()
        {
            string template = "Hello {{ p.Firstname }} {{ p.Lastname }}";

            try
            {
                LiquidTemplate target = new LiquidTemplate(template);
                target.RegisterType(typeof(Person));
                target.Render(null);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("context", ex.ParamName);
                throw;
            }
        }
        LiquidString GetMappingStatement(List <Property> properties)
        {
            ITemplateContext ctx = new TemplateContext();

            if (properties.Count == 0)
            {
                ctx.DefineLocalVariable("keyType", LiquidString.Create(lastKeyType)).
                DefineLocalVariable("valueType", LiquidString.Create(lastValueType));
            }
            else
            {
                var currProperty = properties.First();
                ctx.DefineLocalVariable("keyType", LiquidString.Create(Helpers.PrimitivePropertyTypeToString(currProperty.DataType))).
                DefineLocalVariable("valueType", GetMappingStatement(properties.Skip(1).ToList()));
            }
            return(LiquidString.Create(innerTemplate.Render(ctx).Result));
        }
        public void Render_EmptyTemplateValidContext_EmptyReturned()
        {
            string template = string.Empty;

            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            LiquidTemplate target = new LiquidTemplate(template);

            target.RegisterType(typeof(Person));
            string result = target.Render(context);

            Assert.AreEqual(string.Empty, result);
        }
        public void Render_ValidContext_Success()
        {
            // TODO: Setup the test to cover all features of liquid templates.
            string template = "Hello {{ p.Firstname }} {{ p.Lastname }}";

            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            LiquidTemplate target = new LiquidTemplate(template);

            target.RegisterType(typeof(Person));
            string result = target.Render(context);

            Assert.AreEqual("Hello Jim Bob", result);
        }
        public ActionResult ReminderPreview(ReminderJSON reminder)
        {
            var template = db.fees_templates.SingleOrDefault(x => x.id == reminder.templateid);

            if (template == null)
            {
                return(SendJsonErrorResponse("Template not found"));
            }

            var viewmodel = new Reminder();

            viewmodel.Initialise(reminder);

            var liquid = new LiquidTemplate(template.body);

            liquid.AddParameters("reminder", viewmodel);

            var view = liquid.Render();

            return(Json(view.ToJsonOKData()));
        }
        public void Render_TemplateNotSet_Throws()
        {
            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            try
            {
                LiquidTemplate target = new LiquidTemplate();
                target.RegisterType(typeof(Person));
                target.Render(context);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("The template has not been parsed.", ex.Message);
                throw;
            }
        }
Beispiel #18
0
        public override string ToString(int indent = 0)
        {
            string safeName;

            if (string.IsNullOrWhiteSpace(name))
            {
                safeName = "MainContract";
            }
            else
            {
                safeName = Regex.Replace(name, @"\s+", "");
            }

            var ctx = new TemplateContext();

            ctx.DefineLocalVariable("components", FunctionsToLiquid(indent)).
            DefineLocalVariable("name", LiquidString.Create(safeName)).
            DefineLocalVariable("inherits", InheritanceToLiquid());

            return(template.Render(ctx).Result);
        }
        public ActionResult ReminderSend(ReminderJSON reminder)
        {
            var template = db.fees_templates.SingleOrDefault(x => x.id == reminder.templateid);

            if (template == null)
            {
                return(SendJsonErrorResponse("Template not found"));
            }

            var viewmodel = new Reminder();

            viewmodel.Initialise(reminder);

            var parent = repository.GetUser(reminder.parentid);

            if (parent == null)
            {
                return(SendJsonErrorResponse("Could not locate parent"));
            }

            if (reminder.useEmail && string.IsNullOrEmpty(parent.email))
            {
                return(SendJsonErrorResponse("Selected parent has no email address. Select another parent."));
            }

            if (reminder.useSMS && string.IsNullOrEmpty(parent.phone_cell))
            {
                return(SendJsonErrorResponse("Selected parent has no cell phone number. Select another parent."));
            }

            if (reminder.useEmail)
            {
                var liquid = new LiquidTemplate(template.body);
                liquid.AddParameters("reminder", viewmodel);

                var emailbody = liquid.Render();

                new Thread(() => Email.SendMail(" School", "*****@*****.**", parent.ToName(false), parent.email, template.title, emailbody, false, null)).Start();
            }

            // save reminder params into db
            foreach (var feeid in reminder.children.SelectMany(x => x.feeids))
            {
                var dbentry = new fees_reminder();
                dbentry.templatename = template.title;
                dbentry.created      = DateTime.UtcNow;
                dbentry.paymentdue   = reminder.date_due;
                dbentry.receiver     = parent.id;
                dbentry.sender       = sessionid.Value;
                dbentry.feeid        = feeid;
                dbentry.uniqueid     = viewmodel.uniqueid;
                db.fees_reminders.InsertOnSubmit(dbentry);
            }


            repository.Save();

            // return view
            var view = this.RenderViewToString("Alerts",
                                               new[]
            {
                new LateFeeAlertSiblings(
                    reminder.children.Select(x => x.studentid))
            }).ToJsonOKData();

            view.message = "Reminder sent successfully";

            return(Json(view));
        }