public void CreateComponentDsl()
        {
            // not so much a test, as an example of how you could construct a
            // "DSL" like syntax to represent a monorail view component with 
            // section overrides.

            var people = new List<Person>
                             {
                                 new Person {FirstName = "Alex", LastName = "Henderson"},
                                 new Person {FirstName = "Joe", LastName = "Bloggs"}
                             };

            var compDsl = new ComponentDsl();

            compDsl.Add
                (
                GridComponent => compDsl.Component
                                     (
                                     compDsl.Parameters
                                         (
                                         source => people
                                         ),
                                     header => compDsl.Section
                                                   (
                                                   tr => compDsl.As
                                                             (
                                                             th => compDsl.As
                                                                       (
                                                                       compDsl.Text("Names")
                                                                       )
                                                             )
                                                   ),
                                     item => compDsl.Section
                                                 (
                                                 tr => compDsl.As
                                                           (
                                                           td => compDsl.As
                                                                     (
                                                                     compDsl.Item<Person>(p => p.FirstName + " " + p.LastName)
                                                                     )
                                                           )
                                                 )
                                     )
                );

            var dsl = new StandardDsl();

            dsl.Add
                (
                html => dsl.As
                            (
                            body => compDsl
                            )
                );

            Console.WriteLine(DslToXml.ToXml(dsl));
        }
Exemple #2
0
        public static string ToXml(StandardDsl dsl)
        {
            var nodeWriter = new NodeWriter();

            using (var scope = new DslEvaluationScope(nodeWriter))
            {
                dsl.Execute();
            }

            return(ToXml(nodeWriter));
        }
        public static string ToXml(StandardDsl dsl)
        {
            var nodeWriter = new NodeWriter();

            using (var scope = new DslEvaluationScope(nodeWriter))
            {
                dsl.Execute();
            }

            return ToXml(nodeWriter);
        }
        public void CreateSimpleDsl()
        {
            var dsl = new StandardDsl();

            dsl.Add
                (
                table => dsl.As
                             (
                             tr => dsl.As
                                       (
                                       td => dsl.Text("header1"),
                                       td => dsl.Text("header2")
                                       )
                             )
                );

            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?><table><tr><td>header1</td><td>header2</td></tr></table>";

            Assert.AreEqual(expected, DslToXml.ToXml(dsl));
        }
        public void CreateDslWithForEach()
        {
            var headers = new List<string> {"header1", "header2", "header3"};

            var innerDsl = new StandardDsl();
            innerDsl.Add(
                headers.ForEach(text =>
                                td => innerDsl.Text(text)
                    )
                );

            var dsl = new StandardDsl();

            dsl.Add(
                table => dsl.As(
                             tr => dsl.As(innerDsl)));


            Console.WriteLine(DslToXml.ToXml(dsl));
        }