コード例 #1
0
        public void MustacheRenderer_RenderConditionalTagOnFileName()
        {
            var files = new List <TemplateFile> {
                new TemplateFile
                {
                    Name    = "file{{cond1}}",
                    Content = ""
                },
                new TemplateFile
                {
                    Name    = "file{{cond1}}/subfile",
                    Content = ""
                }
            };

            var tags = new Dictionary <string, object>
            {
                { "cond1", true }
            };

            var sut    = new MustacheRenderer();
            var result = sut.Render(files, tags);

            Assert.IsTrue(result.Any(x => x.Name == "file"));
            Assert.IsTrue(result.Any(x => x.Name == "file/subfile"));
        }
コード例 #2
0
        public void MustacheRenderer_RenderConditionalTag()
        {
            var files = new List <TemplateFile> {
                new TemplateFile
                {
                    Name    = "file1",
                    Content = "You chose {{#cond1}}One{{/cond1}}{{#cond2}}Two{{/cond2}}"
                },
                new TemplateFile
                {
                    Name    = "file2",
                    Content = "You did not choose {{^cond1}}One{{/cond1}}{{^cond2}}Two{{/cond2}}"
                }
            };

            var tags = new Dictionary <string, object>
            {
                { "cond1", true },
                { "cond2", false }
            };

            var sut    = new MustacheRenderer();
            var result = sut.Render(files, tags);

            Assert.AreEqual("You chose One", result.FirstOrDefault(x => x.Name == "file1").Content);
            Assert.AreEqual("You did not choose Two", result.FirstOrDefault(x => x.Name == "file2").Content);
        }
コード例 #3
0
        public void MustacheRenderer_RenderTag()
        {
            var files = new List <TemplateFile> {
                new TemplateFile
                {
                    Name    = "file1",
                    Content = "Greetings {{firstName}} {{lastName}}!"
                },
                new TemplateFile
                {
                    Name    = "file2",
                    Content = "How can I help, {{firstName}}?"
                },
                new TemplateFile
                {
                    Name    = "{{file3__upper}}",
                    Content = "{{firstName__lower}} {{lastName__upper}}"
                }
            };

            var tags = new Dictionary <string, object>
            {
                { "firstName", "John" },
                { "lastName", "Doe" },
                { "file3", "filename3" }
            };

            var sut    = new MustacheRenderer();
            var result = sut.Render(files, tags);

            Assert.AreEqual("Greetings John Doe!", result.FirstOrDefault(x => x.Name == "file1").Content);
            Assert.AreEqual("How can I help, John?", result.FirstOrDefault(x => x.Name == "file2").Content);
            Assert.AreEqual("john DOE", result.FirstOrDefault(x => x.Name == "FILENAME3").Content);
        }
コード例 #4
0
        /// <summary>
        /// Runs example
        /// </summary>
        /// <param name="unused">Unused command line arguments</param>
        static void Main(string[] unused)
        {
            Console.WriteLine("Beginning code generation...");
            Console.WriteLine();
            Console.WriteLine();


            // Create template renderer
            var mustache = new MustacheRenderer();


            // Select all types with NameAttribute
            AppDomain.CurrentDomain
            .GetAssemblies()
            .SelectMany(a => a.GetTypes())
            .Where(t => t.HasAttribute <NameAttribute>(false))
            .ToList()

            // For each type with NameAttribute
            // 1. prepare template data, and
            // 2. render it
            .ForEach(t =>
            {
                var template = NamedTemplate;
                var data     = new NamedData
                {
                    Namespace = t.Namespace,
                    ClassName = t.Name,
                    Name      = t.GetAttribute <NameAttribute>(false).Name
                };

                var code = mustache.Render(template, data, null);

                // Show generated code in console
                Console.WriteLine(string.Format("'INamed' implementation for '{0}':", t.Name));
                Console.WriteLine();
                Console.WriteLine(code);
                Console.WriteLine();
            });


            Console.WriteLine();
            Console.WriteLine("Code generation ran to completion...");
            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
コード例 #5
0
        public void MustacheRenderer_RenderTagOnFileName()
        {
            var files = new List <TemplateFile> {
                new TemplateFile
                {
                    Name    = "{{projectName}}",
                    Content = "content"
                }
            };

            var tags = new Dictionary <string, object>
            {
                { "projectName", "StarterApp" }
            };

            var sut    = new MustacheRenderer();
            var result = sut.Render(files, tags);

            Assert.IsTrue(result.Any(x => x.Name == "StarterApp"));
        }