Esempio 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();
        }
Esempio 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();
        }
Esempio n. 3
0
        public void GenerateAssembly()
        {
            ITemplate template =
                new AtTemplate(TemplateFile, Encoding.Default);

            template.Parse();

            Assert.IsNotNull(template.GeneratedAssemblyPath);
        }
Esempio n. 4
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();
        }
Esempio 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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public void BetweenBlock()
        {
            AtTemplate template = new AtTemplate(
                @"{@{
            if (true)
            {
            @text
            1@
            @end_text
            }
            @}}");
            template.Parse();

            Assert.AreEqual("{1}\r\n", template.Render());
        }
Esempio n. 8
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();
        }
Esempio n. 9
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());
        }
Esempio n. 10
0
 public void WrongParamDirective()
 {
     AtTemplate template = new AtTemplate("@param s: ");
     template.Parse();
 }
Esempio n. 11
0
 public void WrongTextEndDirective()
 {
     AtTemplate template = new AtTemplate("@end_text");
     template.Parse();
 }
Esempio n. 12
0
        public void WhiteSpace()
        {
            AtTemplate template = new AtTemplate(
                @"line1@
            ,line1 too
            ");
            template.Parse();

            Assert.AreEqual("line1,line1 too\r\n", template.Render());
        }
Esempio n. 13
0
 public void WrongGlobalDirective(string text)
 {
     AtTemplate template = new AtTemplate(text);
     template.Parse();
 }
Esempio n. 14
0
        public void TextDirective()
        {
            AtTemplate template = new AtTemplate(
                @"@code
            @text
            @code
            @text
            line 1

            @end_text
            @end_code
            @end_text
            @end_code");
            template.Parse();
        }
Esempio n. 15
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());
        }
Esempio n. 16
0
        public void ParameterLineLocation()
        {
            AtTemplate template = new AtTemplate(
                @"@# line 1
            @param a:A
            ");
            template.Debug = true;

            try
            {
                template.Parse();
                Assert.Fail();
            }
            catch (TemplateCompilationException ex)
            {
                Assert.AreEqual(2, ex.Errors[1].Line);
            }
        }
Esempio n. 17
0
 public void NothingToParse()
 {
     using (IAtTemplate template = new AtTemplate(""))
     {
         template.Parse();
         Assert.IsEmpty(template.Render());
     }
 }
Esempio n. 18
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());
        }
Esempio n. 19
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());
        }
Esempio n. 20
0
        public void SimpleSectionReference(string code)
        {
            AtTemplate template = new AtTemplate(code);
            template.Parse();

            Assert.That(template.Render(), Is.EqualTo("Hello DCG\r\n"));
        }
Esempio n. 21
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"));
        }
Esempio n. 22
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"));
        }
Esempio n. 23
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"));
        }
Esempio n. 24
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"));
        }
Esempio n. 25
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());
        }
Esempio n. 26
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());
        }
Esempio n. 27
0
        public void StaticEscaping()
        {
            AtTemplate template = new AtTemplate(
                "@@reference System.dll\r\n");

            template.Parse();

            Assert.AreEqual("@reference System.dll\r\n", template.Render());
        }
Esempio n. 28
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());
        }
Esempio n. 29
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());
        }
Esempio n. 30
0
        public void MultilineEvaluation()
        {
            AtTemplate template = new AtTemplate(
                "    @= \"line1\\r\\nline2\"");
            template.Parse();

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