Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        internal static void Main(string[] args)
        {
            AtTemplate template = new AtTemplate("numbers.al", (Encoding) null);
            template.Parse();

            Console.WriteLine(template.Render());
            Console.ReadLine();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        public void BetweenBlock()
        {
            AtTemplate template = new AtTemplate(
                @"{@{
            if (true)
            {
            @text
            1@
            @end_text
            }
            @}}");
            template.Parse();

            Assert.AreEqual("{1}\r\n", template.Render());
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        public void StaticEscaping()
        {
            AtTemplate template = new AtTemplate(
                "@@reference System.dll\r\n");

            template.Parse();

            Assert.AreEqual("@reference System.dll\r\n", template.Render());
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        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());
        }
Exemplo n.º 14
0
        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)));
        }
Exemplo n.º 15
0
        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());
        }
Exemplo n.º 16
0
        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"));
        }
Exemplo n.º 17
0
        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"));
        }
Exemplo n.º 18
0
 public void NothingToParse()
 {
     using (IAtTemplate template = new AtTemplate(""))
     {
         template.Parse();
         Assert.IsEmpty(template.Render());
     }
 }
Exemplo n.º 19
0
        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());
        }
Exemplo n.º 20
0
        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());
        }
Exemplo n.º 21
0
        public void WhiteSpace()
        {
            AtTemplate template = new AtTemplate(
                @"line1@
            ,line1 too
            ");
            template.Parse();

            Assert.AreEqual("line1,line1 too\r\n", template.Render());
        }
Exemplo n.º 22
0
        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"));
        }
Exemplo n.º 23
0
        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());
        }
Exemplo n.º 24
0
        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.");
        }
Exemplo n.º 25
0
        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"));
        }
Exemplo n.º 26
0
        public void MultilineEvaluation()
        {
            AtTemplate template = new AtTemplate(
                "    @= \"line1\\r\\nline2\"");
            template.Parse();

            Assert.AreEqual("    line1\r\n    line2\r\n", template.Render());
        }
Exemplo n.º 27
0
        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());
        }
Exemplo n.º 28
0
        public void SimpleSectionReference(string code)
        {
            AtTemplate template = new AtTemplate(code);
            template.Parse();

            Assert.That(template.Render(), Is.EqualTo("Hello DCG\r\n"));
        }
Exemplo n.º 29
0
        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"));
        }
Exemplo n.º 30
0
        public void EmptyLine()
        {
            AtTemplate template = new AtTemplate("\r\n");
            template.Parse();

            Assert.AreEqual("\r\n", template.Render());
        }