Esempio n. 1
0
 public String RenderToString(TemplateScope Scope = null)
 {
     if (Scope == null) Scope = new TemplateScope();
     var StringWriter = new StringWriter();
     Render(new TemplateContext(StringWriter, Scope, TemplateFactory));
     return StringWriter.ToString();
 }
Esempio n. 2
0
        public String RenderToString(TemplateScope Scope = null)
        {
            if (Scope == null)
            {
                Scope = new TemplateScope();
            }
            var StringWriter = new StringWriter();

            Render(new TemplateContext(StringWriter, Scope, TemplateFactory));
            return(StringWriter.ToString());
        }
Esempio n. 3
0
		public void TestTrueFalseNoneAreImmutableConstants()
		{
			var Scope = new TemplateScope(new Dictionary<String, object>() {
				{ "true", false },
				{ "false", true },
				{ "none", 1 },
			});

			Assert.AreEqual("1", CompileTemplateCodeByString("{% if true %}1{% else %}0{% endif %}").RenderToString(Scope));
			Assert.AreEqual("0", CompileTemplateCodeByString("{% if false %}1{% else %}0{% endif %}").RenderToString(Scope));
			Assert.AreEqual("0", CompileTemplateCodeByString("{% if none %}1{% else %}0{% endif %}").RenderToString(Scope));
		}
Esempio n. 4
0
		public TemplateContext(TextWriter Output, TemplateScope Scope = null, TemplateFactory TemplateFactory = null)
		{
			if (Scope == null) Scope = new TemplateScope();

			this.Output = Output;
			this.Scope = Scope;
			this.TemplateFactory = TemplateFactory;

			Filters = new Dictionary<string, Tuple<Type, string>>();

			AddFilterLibrary(typeof(CoreFilters));
		}
Esempio n. 5
0
        public TemplateContext(TextWriter Output, TemplateScope Scope = null, TemplateFactory TemplateFactory = null)
        {
            if (Scope == null)
            {
                Scope = new TemplateScope();
            }

            this.Output          = Output;
            this.Scope           = Scope;
            this.TemplateFactory = TemplateFactory;

            Filters = new Dictionary <string, Tuple <Type, string> >();

            AddFilterLibrary(typeof(CoreFilters));
        }
        public String RenderToString(TemplateScope Scope = null)
        {
            if (Scope == null)
            {
                Scope = new TemplateScope();
            }
            var StringWriter = new StringWriter();

#if NET_4_5
            RenderAsync(new TemplateContext(StringWriter, Scope, TemplateFactory)).Wait();
#else
            Render(new TemplateContext(StringWriter, Scope, TemplateFactory));
#endif
            return(StringWriter.ToString());
        }
Esempio n. 7
0
 public TemplateScope(TemplateScope ParentScope = null)
 {
     this.ParentScope = ParentScope;
     this.Items       = new Dictionary <String, dynamic>();
 }
Esempio n. 8
0
 public TemplateScope(Dictionary <String, dynamic> Items, TemplateScope ParentScope = null)
 {
     this.ParentScope = ParentScope;
     this.Items       = Items;
 }
Esempio n. 9
0
		public void TestExecForElse()
		{
			var Params1 = new TemplateScope(new Dictionary<String, object>() { { "List", new int[] { 1, 2, 3, 4, 5 } } });
			var Params2 = new TemplateScope(new Dictionary<String, object>() { { "List", new int[] { } } });
			Assert.AreEqual("12345", CompileTemplateCodeByString("{% for Item in List %}{{ Item }}{% else %}Empty{% endfor %}").RenderToString(Params1));
			Assert.AreEqual("Empty", CompileTemplateCodeByString("{% for Item in List %}{{ Item }}{% else %}Empty{% endfor %}").RenderToString(Params2));
		}
Esempio n. 10
0
 public TemplateScope(TemplateScope ParentScope = null)
 {
     this.ParentScope = ParentScope;
     this.Items = new Dictionary<String, dynamic>();
 }
Esempio n. 11
0
 public TemplateScope(Dictionary<String, dynamic> Items, TemplateScope ParentScope = null)
 {
     this.ParentScope = ParentScope;
     this.Items = Items;
 }
Esempio n. 12
0
 public void NewScope(Action Action)
 {
     this.Scope = new TemplateScope(this.Scope);
     Action();
     this.Scope = this.Scope.ParentScope;
 }
Esempio n. 13
0
		public void NewScope(Action Action)
		{
			this.Scope = new TemplateScope(this.Scope);
			Action();
			this.Scope = this.Scope.ParentScope;
		}
Esempio n. 14
0
		public String RenderToString(TemplateScope Scope = null)
		{
			if (Scope == null) Scope = new TemplateScope();
			var StringWriter = new StringWriter();
#if NET_4_5
			RenderAsync(new TemplateContext(StringWriter, Scope, TemplateFactory)).Wait();
#else
			Render(new TemplateContext(StringWriter, Scope, TemplateFactory));
#endif
			return StringWriter.ToString();
		}