internal static void Main(string[] args) { AtTemplate template = new AtTemplate("numbers.al", (Encoding) null); template.Debug = true; try { template.Parse(); template.Context = new object[] { 5 }; Console.WriteLine(template.Render()); } catch (TemplateParsingException ex) { Console.Write("A parsing error at line "); Console.WriteLine(ex.SourceLine); Console.WriteLine(ex.Message); } catch (TemplateCompilationException ex) { Console.WriteLine(ex.ToString()); } catch (TemplateRuntimeException ex) { Console.WriteLine(ex); } Console.ReadLine(); }
internal static void Main(string[] args) { AtTemplate template = new AtTemplate("numbers.al", (Encoding) null); template.Parse(); Console.WriteLine(template.Render()); Console.ReadLine(); }
internal static void Main(string[] args) { string templateContent = "@! string name = \"Cavingdeep\";\r\n" + "Hello @(name)."; AtTemplate template = new AtTemplate(templateContent); template.Parse(); Console.WriteLine(template.Render()); Console.ReadLine(); }
internal static void Main(string[] args) { AtTemplate template = new AtTemplate("class.al", (Encoding) null); template.Parse(); template.Context = new object[] { "SampleClass", 5, new string[] { "id", "name" } }; Console.WriteLine(template.Render()); Console.ReadLine(); }
internal static void Main(string[] args) { AtTemplate template = new AtTemplate("person.al", (Encoding) null); template.Parse(); template.Context = new object[] { new Person("Seth", "Yuan", 24, Gender.Male) }; Console.WriteLine(template.Render()); Console.ReadLine(); }
public void BetweenBlock() { AtTemplate template = new AtTemplate( @"{@{ if (true) { @text 1@ @end_text } @}}"); template.Parse(); Assert.AreEqual("{1}\r\n", template.Render()); }
internal static void Main(string[] args) { AtTemplate template = new AtTemplate("multi.al", (Encoding) null); template.Parse(); string output2 = "output2"; Dictionary<string, TextWriter> writers = new Dictionary<string, TextWriter>(); writers.Add(AtTemplate.MainOutputKey, new StringWriter()); writers.Add(output2, new StringWriter()); template.Render(writers); Console.WriteLine("Main Output:"); Console.WriteLine(writers[AtTemplate.MainOutputKey].ToString()); Console.WriteLine("Output 2:"); Console.WriteLine(writers[output2].ToString()); Console.ReadLine(); }
public void StaticEscaping() { AtTemplate template = new AtTemplate( "@@reference System.dll\r\n"); template.Parse(); Assert.AreEqual("@reference System.dll\r\n", template.Render()); }
public void TextLine() { AtTemplate template = new AtTemplate("line 1\r\nline 2"); template.Parse(); Assert.AreEqual("line 1\r\nline 2\r\n", template.Render()); }
public void InnerMultiOutput() { AtTemplate template = new AtTemplate( @"@output page2 <html> <br/> @! for (int i = 1; i <= 3; i++) { @output page3 Just kidding. @code for (int j = 1; j < 3; j++) { @text page3 @output page4 OK @end_output @end_text } @end_code @end_output @! } </html> @end_output"); template.Parse(); Dictionary<string, TextWriter> outputs = new Dictionary<string, TextWriter>(); outputs.Add(AtTemplate.MainOutputKey, new StringWriter()); outputs.Add("page2", new StringWriter()); outputs.Add("page3", new StringWriter()); outputs.Add("page4", new StringWriter()); template.Render(outputs); Assert.AreEqual(@"<html> <br/> </html> ", outputs["page2"].ToString()); Assert.AreEqual(@"Just kidding. page3 page3 Just kidding. page3 page3 Just kidding. page3 page3 ", outputs["page3"].ToString()); Assert.AreEqual(@"OK OK OK OK OK OK ", outputs["page4"].ToString()); }
public void SpacesAfterDirective() { AtTemplate template = new AtTemplate( @"1@ @code if (true) { @text 1 @end_text } @end_code "); template.Parse(); Assert.AreEqual("11\r\n", template.Render()); }
public void MultilineEvaluationWithParentIndentation() { AtTemplate template = new AtTemplate( @"line @code @text @= ""line1\r\nline2"" @end_text @end_code"); template.Parse(); Assert.AreEqual("line\r\n line1\r\n line2\r\n", template.Render()); }
public void SingleInstance() { IAtTemplate template = new AtTemplate( @"@global int number = 1; @end_global @(number++)"); try { template.Parse(); } catch (TemplateCompilationException ex) { Console.WriteLine(ex.ToString()); throw; } Assert.AreEqual("1\r\n", template.Render()); Assert.AreEqual("2\r\n", template.Render()); }
public void LineEnding(string lineEnding) { AtTemplate template = new AtTemplate( string.Format("line1{0}line2", lineEnding)); template.Parse(); Assert.That(template.Render(), Is.EqualTo(string.Format("line1{0}line2{0}", lineEnding))); }
public void CodeDirective() { AtTemplate template = new AtTemplate( @"line 1 @code Dcg.Write(""line 2\r\n""); @end_code line 3"); template.Parse(); Assert.AreEqual("line 1\r\nline 2\r\nline 3\r\n", template.Render()); }
public void SectionReferenceWithinAnOutput() { AtTemplate template = new AtTemplate( @"@output o\1 @+ Outer @end_output @section Outer () line1 @+ inner @end_section @section inner inner line @end_section"); template.Parse(); IDictionary<string, TextWriter> writers = new Dictionary<string, TextWriter>() { { AtTemplate.MainOutputKey, new StringWriter() }, { "o\\1", new StringWriter() } }; template.Render(writers); Assert.That( writers["o\\1"].ToString(), Is.EqualTo(" line1\r\n inner line\r\n")); }
public void SectionReferenceWithIndentation() { AtTemplate template = new AtTemplate( @" @+ SayHello @section SayHello line1 line2 @end_section"); template.Parse(); Assert.That(template.Render(), Is.EqualTo(" line1\r\n line2\r\n")); }
public void NothingToParse() { using (IAtTemplate template = new AtTemplate("")) { template.Parse(); Assert.IsEmpty(template.Render()); } }
public void NewInstance() { IAtTemplate template = new AtTemplate( @"@global int number = 1; @end_global @(number++)"); template.Parse(); Assert.AreEqual("1\r\n", template.Render()); IAtTemplateInstance instance1 = template.NewInstance(); Assert.AreEqual("1\r\n", instance1.Render()); }
public void MultiOutputWithEvaluationDirective() { AtTemplate template = new AtTemplate( @"main output @output key1 @(""key1"") output @end_output"); template.Parse(); IDictionary<string, TextWriter> writers = new Dictionary<string, TextWriter>(); writers.Add(AtTemplate.MainOutputKey, new StringWriter()); writers.Add("key1", new StringWriter()); template.Render(writers); Assert.AreEqual("main output\r\n", writers[AtTemplate.MainOutputKey].ToString()); Assert.AreEqual("key1 output\r\n", writers["key1"].ToString()); }
public void WhiteSpace() { AtTemplate template = new AtTemplate( @"line1@ ,line1 too "); template.Parse(); Assert.AreEqual("line1,line1 too\r\n", template.Render()); }
public void LineEndHandlingWithIndentation_WithinSection() { AtTemplate template = new AtTemplate( @" @+ MySection @section MySection @code @text line1@ continuation @end_text @end_code @end_section"); template.Parse(); Assert.That(template.Render(), Is.EqualTo(" line1continuation\r\n")); }
public void CodeAndTextDirective() { AtTemplate template = new AtTemplate( @"line 1 @code int two = 2; @text line @(two) @end_text @end_code "); template.Parse(); Assert.AreEqual("line 1\r\n line 2\r\n", template.Render()); }
public void EvaluationEscape() { AtTemplate template = new AtTemplate("@@@@(1+1)"); template.Parse(); Assert.AreEqual("@@(1+1)\r\n", template.Render(), "Par not working."); template = new AtTemplate("@@@(1+1)"); template.Parse(); Assert.AreEqual("@2\r\n", template.Render(), "Single not working."); }
public void SectionReferenceWithinSectionReference() { AtTemplate template = new AtTemplate( @" @+ Outer @section Outer () line1 @+ inner @end_section @section inner inner line @end_section"); template.Parse(); Assert.That(template.Render(), Is.EqualTo(" line1\r\n inner line\r\n")); }
public void MultilineEvaluation() { AtTemplate template = new AtTemplate( " @= \"line1\\r\\nline2\""); template.Parse(); Assert.AreEqual(" line1\r\n line2\r\n", template.Render()); }
public void ComplexWriterKey() { AtTemplate template = new AtTemplate( @"@output my\""output"" something @end_output"); template.Parse(); Dictionary<string, TextWriter> writers = new Dictionary<string,TextWriter>() { { AtTemplate.MainOutputKey, new StringWriter() }, { "my\\\"output\"", new StringWriter() } }; template.Render(writers); Assert.AreEqual("something\r\n", writers["my\\\"output\""].ToString()); }
public void SimpleSectionReference(string code) { AtTemplate template = new AtTemplate(code); template.Parse(); Assert.That(template.Render(), Is.EqualTo("Hello DCG\r\n")); }
public void SectionReferenceWithParameters() { AtTemplate template = new AtTemplate( @"@! string name = ""Seth""; @+ SayHello(name) @section SayHello(name : string) Hello @(name) @end_section"); template.Parse(); Assert.That(template.Render(), Is.EqualTo("Hello Seth\r\n")); }
public void EmptyLine() { AtTemplate template = new AtTemplate("\r\n"); template.Parse(); Assert.AreEqual("\r\n", template.Render()); }