Example #1
0
        public void Url_namedAndPosArgUrl()
        {
            string tt = "{% url 'named_and_pos_arg_url' product_name=product 7 %}";
            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["product"] = "badr";

            Assert.Equal ("/badr/page/7/", te.Render (tc));
        }
Example #2
0
        public static BadrResponse ModelView(BadrRequest request, UrlArgs args)
        {
            dynamic model = Model.Manager(args[1]).Get(int.Parse(args["model_id"]));

            dynamic tc = new TemplateContext();
            tc.modelName = args[1];
            tc.model = model;

            return BadrResponse.Create(request, tc);
        }
Example #3
0
        public void ForTag_in()
        {
            string tt = "{% for a in list %}{{ a }}, {% endfor %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["list"] = new int[]{1, 2, 3, 4, 5, 6, 7 ,8, 9 };

            Assert.Equal ("1, 2, 3, 4, 5, 6, 7, 8, 9, ", te.Render (tc));
        }
Example #4
0
        public static BadrResponse ModelListView(BadrRequest request, UrlArgs args)
        {
            string modelName = args[1];
                string pageNum = args["page_num"];
                dynamic modelsPage = Model.Manager(modelName).Page(pageNum != null ? int.Parse(pageNum) : 1, 20);

                dynamic tc = new TemplateContext ();
                tc.modelName = modelName;
                tc.modelsPage = modelsPage;

                return BadrResponse.Create (request, tc);
        }
Example #5
0
        public void IfTag_andNot()
        {
            string tt = "{% if a < 10 and not a = 5 %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -7;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 5;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 19;
            Assert.Equal ("false", te.Render (tc));
        }
Example #6
0
        public void IfTag_and()
        {
            string tt = "{% if a < 10 and a > -2 and a in list %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["list"] = new double[]{-11.7, -7, -1, 3, 5, 81};

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -1;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 9;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 81;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -11.7;
            Assert.Equal ("false", te.Render (tc));
        }
 protected internal override void Process(TemplateContext context)
 {
     context["STATIC_URL"] = "/" + SiteManager.Settings.StaticUrl;
 }
 public void Process(TemplateContext context)
 {
     if (context != null)
         foreach (ContextProcessorBase contextProcessor in _contextProcessors)
             contextProcessor.Process(context);
 }
        public string Render(BadrRequest request, TemplateContext context)
        {
            if (ContainsErrors)
                throw new TemplateException(string.Join(Environment.NewLine, Errors.Select(te => te.Message)), this);

            if (_isStaticTemplate)
                return TemplateContent;
            else
                return new RenderContext(request).Render(_scope0, context);
        }
Example #10
0
 public string Render(TemplateContext context)
 {
     return Render (null, context);
 }
Example #11
0
        public void IfTag_or()
        {
            string tt = "{% if a = 1 or a < -50 or a in list %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();
            tc ["list"] = new double[]{-11.7, -7, -1, 3, 5, 81};

            tc ["a"] = 1;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 81;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 7;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -2;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = -71.7;
            Assert.Equal ("true", te.Render (tc));
        }
Example #12
0
        public void IfTag_notIn()
        {
            string tt = "{% if a not in b %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["a"] = 2;
            tc ["b"] = new int[]{1, 3, 7};
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 1;
            Assert.Equal ("false", te.Render (tc));
        }
Example #13
0
        public void IfTag_noRhs()
        {
            string tt = "{% if a %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = true;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 0;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = null;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = false;
            Assert.Equal ("false", te.Render (tc));
        }
Example #14
0
        public void IfTag_lessThan()
        {
            string tt = "{% if a < b %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext ();
            tc ["a"] = 1;
            tc ["b"] = 1;
            Assert.Equal ("false", te.Render (tc));

            tc ["b"] = 2;
            Assert.Equal ("true", te.Render (tc));
        }
Example #15
0
        public void IfTag_and_or_mix()
        {
            string tt = "{% if a < 10 and not a = 5 or a > 10 and a < 20 and not a = 15 or a = 27 %}true{% else %}false{% endif %}";

            TemplateEngine te = new TemplateEngine (tt);
            TemplateContext tc = new TemplateContext();

            tc ["a"] = 3;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 17;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 27;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = -77;
            Assert.Equal ("true", te.Render (tc));

            tc ["a"] = 5;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 15;
            Assert.Equal ("false", te.Render (tc));

            tc ["a"] = 77;
            Assert.Equal ("false", te.Render (tc));
        }