Exemple #1
0
        public void Comments()
        {
            string template = @"<h1>Today{{! ignore me }}.</h1>";
            var    output   = Mustache.render(template, null);

            Assert.AreEqual("<h1>Today.</h1>", output);
        }
        private static void AddBeard(Mobile m, int itemID, int hue)
        {
            if (m.Female)
            {
                return;
            }

            Item item;

            switch (itemID & 0x3FFF)
            {
            case 0x203E: item = new LongBeard(hue); break;

            case 0x203F: item = new ShortBeard(hue); break;

            case 0x2040: item = new Goatee(hue); break;

            case 0x2041: item = new Mustache(hue); break;

            case 0x204B: item = new MediumShortBeard(hue); break;

            case 0x204C: item = new MediumLongBeard(hue); break;

            case 0x204D: item = new Vandyke(hue); break;

            default: return;
            }

            m.AddItem(item);
        }
Exemple #3
0
        public void Numbers()
        {
            var view   = new MyView();
            var output = Mustache.render("{{aNumber}} believes", view);

            Assert.AreEqual("13 believes", output);
        }
Exemple #4
0
        public void NonEmptyLists()
        {
            var view = new MyView()
            {
                stooges = new List <string> {
                    "Moe", "Larry", "Curly"
                },
            };
            var output = Mustache.render("Shown{{#stooges}} {{.}}{{/stooges}}", view);

            Assert.AreEqual("Shown Moe Larry Curly", output);

            var context = new MyView()
            {
                subberList = new List <SubObj> {
                    new SubObj {
                        whatever = "abc"
                    }, new SubObj {
                        whatever = "xyz"
                    }
                }
            };

            output = Mustache.render("={{#subberList}}-{{whatever}}{{/subberList}}", context);
            Assert.AreEqual("=-abc-xyz", output);

            output = Mustache.render("={{#subberList}}-{{uppers}}{{/subberList}}", context);
            Assert.AreEqual("=-ABC-XYZ", output);
        }
Exemple #5
0
        public void DynamicJson()
        {
            dynamic data   = Newtonsoft.Json.JsonConvert.DeserializeObject("{'person?': { 'name': 'Jon' }}");
            var     output = Mustache.render("{{#person?}}Hi {{name}}!{{/person?}}", data);

            Assert.AreEqual("Hi Jon!", output);
        }
Exemple #6
0
        public void InvertedSection()
        {
            string  template = @"{{#repo}}<b>{{name}}</b>{{/repo}}{{^repo}}No repos :({{/repo}}";
            dynamic data     = Newtonsoft.Json.JsonConvert.DeserializeObject("{ 'repo': []}");
            var     output   = Mustache.render(template, data);

            Assert.AreEqual("No repos :(", output);
        }
Exemple #7
0
        public void DotNotation()
        {
            var view = new MyView()
            {
                title = "Joe",
            };
            var output = Mustache.render("{{title}} believes {{subber.whatever}}", view);

            Assert.AreEqual("Joe believes life is 42", output);
        }
Exemple #8
0
        public void Position()
        {
            var view = new WithDecimal()
            {
                Number = 12345.0123M
            };

            var output = Mustache.render("{{Number,10:F}}", view);

            Assert.AreEqual("  12345.01", output);
        }
Exemple #9
0
        public void Tutorial()
        {
            var view = new MyView()
            {
                title = "Joe",
            };

            var output = Mustache.render("{{title}} spends {{calc}}", view);

            Assert.AreEqual("Joe spends 6", output);
        }
Exemple #10
0
        public void Lambdas()
        {
            var template = @"{{#wrapped}} {{title}} is awesome. {{/wrapped}}";
            var view     = new MyView()
            {
                title = "Willy"
            };
            var output = Mustache.render(template, view);

            Assert.AreEqual("<b> Willy is awesome. </b>", output);
        }
Exemple #11
0
        public void EmptyString()
        {
            var view = new MyView
            {
                title = ""
            };

            var output = Mustache.render("{{#title}}Something{{/title}}Nothing", view);

            Assert.AreEqual("Nothing", output);
        }
Exemple #12
0
        public void Zero()
        {
            var view = new WithDecimal
            {
                Number = 0
            };

            var output = Mustache.render("{{#Number}}Something{{/Number}}Nothing", view);

            Assert.AreEqual("Nothing", output);
        }
Exemple #13
0
        public void SetDelimiter()
        {
            string contrivedExampleTemplate = @"* {{default_tags}}
{{=<% %>=}}
* <% erb_style_tags %>
<%={{ }}=%>
* {{ default_tags_again }}";

            string  expected = @"* han
* shot
* first";
            dynamic data     = Newtonsoft.Json.JsonConvert.DeserializeObject("{ 'default_tags': 'han', 'erb_style_tags': 'shot', default_tags_again: 'first'}");
            var     output   = Mustache.render(contrivedExampleTemplate, data);

            Assert.AreEqual(output, expected);
        }
Exemple #14
0
        public void Sections()
        {
            var view = new MyView()
            {
                title = "Joe",
            };
            var output = Mustache.render("Shown.{{#person}}Never shown!{{/person}}", view);

            Assert.AreEqual("Shown.", output);

            output = Mustache.render("Shown.{{#stooges}}Never shown!{{/stooges}}", view);
            Assert.AreEqual("Shown.", output);

            output = Mustache.render("Shown.{{#stoogesArray}}Never shown!{{/stoogesArray}}", view);
            Assert.AreEqual("Shown.", output);
        }
Exemple #15
0
        public void Partials()
        {
            string baseTemplate = @"<h2>Names</h2>{{#names}}  {{> user}}{{/names}}";
            var    partials     = new Dictionary <string, string>()
            {
                { "user", "<strong>{{name}}</strong>" }
            };

            string fullTemplate = "<h2>Names</h2>{{#names}}  <strong>{{name}}</strong>{{/names}}";

            dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject("{ 'names': [{name: 'Moe'}, {name:'Homer'}]}");

            var output             = Mustache.render(fullTemplate, data);
            var outputWithPartials = Mustache.render(baseTemplate, data, partials);

            Assert.AreEqual(outputWithPartials, output);
            Assert.AreEqual(output, "<h2>Names</h2>  <strong>Moe</strong>  <strong>Homer</strong>");
        }
Exemple #16
0
        private void ParseBtn_OnClick(object sender, RoutedEventArgs e)
        {
            Mustache mustache = new Mustache();

            try
            {
                ResultsTb.Text = mustache.Parse(
                    new TextRange(TemplateRtb.Document.ContentStart,
                                  TemplateRtb.Document.ContentEnd).Text,
                    new TextRange(KeyValueRtb.Document.ContentStart,
                                  KeyValueRtb.Document.ContentEnd).Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Произошла ошибка распознавания",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #17
0
        public virtual Item AddRandomFacialHair(int hairHue)
        {
            Item hair = null;

            switch (Utility.Random(5))
            {
            case 0: AddItem(hair = new LongBeard(hairHue)); break;

            case 1: AddItem(hair = new MediumLongBeard(hairHue)); break;

            case 2: AddItem(hair = new Vandyke(hairHue)); break;

            case 3: AddItem(hair = new Mustache(hairHue)); break;

            case 4: AddItem(hair = new Goatee(hairHue)); break;
            }
            return(hair);
        }
Exemple #18
0
        public void Unescape()
        {
            var expected = @"* Chris
* 
* &lt;b&gt;GitHub&lt;/b&gt;
* <b>GitHub</b>
* <b>GitHub</b>";
            var template = @"* {{name}}
* {{age}}
* {{company}}
* {{{company}}}
* {{&company}}";
            var view     = new Dictionary <string, string> {
                { "name", "Chris" },
                { "company", "<b>GitHub</b>" }
            };

            var output = Mustache.render(template, view);

            Assert.AreEqual(expected, output);
        }
Exemple #19
0
 static void Main(string[] args)
 {
     Console.WriteLine(Mustache.render("asdf{{!ignoredcomment...}} me", null));
 }