Exemple #1
0
        /// <summary>
        /// Creates a template with specified text that
        /// runs on another application domain.
        /// </summary>
        /// <param name="text">Template text.</param>
        /// <param name="compilerVersion">Indicates the compiler version to use.
        /// Such as "v3.5" or "v2.0".</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="text"/> is null or empty.
        /// </exception>
        public AtTemplateProxy(string text, string compilerVersion)
        {
            if (text == null)
            {
                throw new ArgumentNullException("templateText");
            }

            if (compilerVersion == null)
            {
                compilerVersion = String.Empty;
            }

            CreateDomain();

            this.template =
                (AtTemplate)this.domain.CreateInstanceFromAndUnwrap(
                    Assembly.GetExecutingAssembly().CodeBase,
                    typeof(AtTemplate).FullName,
                    false,
                    BindingFlags.Public | BindingFlags.Instance,
                    null,
                    new object[] { text, compilerVersion },
                    null,
                    null,
                    null);
        }
Exemple #2
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();
        }
Exemple #3
0
        internal static void Main(string[] args)
        {
            AtTemplate template = new AtTemplate("numbers.al", (Encoding) null);
            template.Parse();

            Console.WriteLine(template.Render());
            Console.ReadLine();
        }
Exemple #4
0
        public void GenerateAssembly()
        {
            ITemplate template =
                new AtTemplate(TemplateFile, Encoding.Default);

            template.Parse();

            Assert.IsNotNull(template.GeneratedAssemblyPath);
        }
Exemple #5
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();
        }
Exemple #6
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();
        }
Exemple #7
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();
        }
Exemple #8
0
        public void GenerateAssemblyWithDebug()
        {
            ITemplate template =
                new AtTemplate(TemplateFile, Encoding.Default);
            template.Debug = true;

            template.Parse();

            Assert.IsNotNull(template.GeneratedAssemblyPath);
            Assert.IsTrue(
                File.Exists(
                    template.GeneratedAssemblyPath.Substring(
                        0, template.GeneratedAssemblyPath.Length-4) + ".pdb"));
        }
Exemple #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());
        }
Exemple #10
0
        public void BetweenBlock()
        {
            AtTemplate template = new AtTemplate(
                @"{@{
            if (true)
            {
            @text
            1@
            @end_text
            }
            @}}");
            template.Parse();

            Assert.AreEqual("{1}\r\n", template.Render());
        }
Exemple #11
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();
        }
Exemple #12
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());
        }
Exemple #13
0
 public void WrongTextEndDirective()
 {
     AtTemplate template = new AtTemplate("@end_text");
     template.Parse();
 }
Exemple #14
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"));
        }
Exemple #15
0
            public AtTemplateInstance(AtTemplate template)
            {
                Assertion.Assert(template != null, "template cannot be null.");

                this.template = template;
            }
Exemple #16
0
        public void TextDirective()
        {
            AtTemplate template = new AtTemplate(
                @"@code
            @text
            @code
            @text
            line 1

            @end_text
            @end_code
            @end_text
            @end_code");
            template.Parse();
        }
Exemple #17
0
        public void StaticEscaping()
        {
            AtTemplate template = new AtTemplate(
                "@@reference System.dll\r\n");

            template.Parse();

            Assert.AreEqual("@reference System.dll\r\n", template.Render());
        }
Exemple #18
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());
        }
Exemple #19
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());
        }
Exemple #20
0
        public void SimpleSectionReference(string code)
        {
            AtTemplate template = new AtTemplate(code);
            template.Parse();

            Assert.That(template.Render(), Is.EqualTo("Hello DCG\r\n"));
        }
Exemple #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"));
        }
Exemple #22
0
            public AtTemplateInstance(AtTemplate template)
            {
                Assertion.Assert(template != null, "template cannot be null.");

                this.template = template;
            }
Exemple #23
0
        /// <summary>
        /// Creates a template with specified text that
        /// runs on another application domain.
        /// </summary>
        /// <param name="text">Template text.</param>
        /// <param name="compilerVersion">Indicates the compiler version to use.
        /// Such as "v3.5" or "v2.0".</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="text"/> is null or empty.
        /// </exception>
        public AtTemplateProxy(string text, string compilerVersion)
        {
            if (text == null)
            {
                throw new ArgumentNullException("templateText");
            }

            if (compilerVersion == null)
            {
                compilerVersion = String.Empty;
            }

            CreateDomain();

            this.template =
                (AtTemplate) this.domain.CreateInstanceFromAndUnwrap(
                    Assembly.GetExecutingAssembly().CodeBase,
                    typeof(AtTemplate).FullName,
                    false,
                    BindingFlags.Public | BindingFlags.Instance,
                    null,
                    new object[] { text, compilerVersion },
                    null,
                    null,
                    null);
        }
Exemple #24
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());
        }
Exemple #25
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"));
        }
Exemple #26
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);
            }
        }
Exemple #27
0
        static DefaultStyles()
        {
            string text;

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.CSharp_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            CSharpHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.CSharp_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            CSharpHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Css_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            CssHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Css_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            CssHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.JavaScript_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            JavaScriptHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.JavaScript_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            JavaScriptHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Xml_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            XmlHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Xml_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            XmlHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Html_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            HtmlHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Html_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            HtmlHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.At_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            AtHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.At_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            AtHtmlLine = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Python_Html.template")))
            {
                text = reader.ReadToEnd();
            }
            PythonHtml = new AtTemplate(text, "v2.0");

            using (StreamReader reader = new StreamReader(
                typeof(DefaultStyles).Assembly.GetManifestResourceStream(
                    "Cavingdeep.CodeStyler.StyleTemplates.Python_Html_Line.template")))
            {
                text = reader.ReadToEnd();
            }
            PythonHtmlLine = new AtTemplate(text, "v2.0");
        }
Exemple #28
0
 public void WrongParamDirective()
 {
     AtTemplate template = new AtTemplate("@param s: ");
     template.Parse();
 }
Exemple #29
0
 public void WrongGlobalDirective(string text)
 {
     AtTemplate template = new AtTemplate(text);
     template.Parse();
 }
Exemple #30
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"));
        }
Exemple #31
0
        public void WhiteSpace()
        {
            AtTemplate template = new AtTemplate(
                @"line1@
            ,line1 too
            ");
            template.Parse();

            Assert.AreEqual("line1,line1 too\r\n", template.Render());
        }
Exemple #32
0
 public void NothingToParse()
 {
     using (IAtTemplate template = new AtTemplate(""))
     {
         template.Parse();
         Assert.IsEmpty(template.Render());
     }
 }