Ejemplo n.º 1
0
        public void FormatTestListNested()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "# Fuel could be:\n" +
                           "## Coal\n" +
                           "## Gasoline\n" +
                           "## Electricity\n" +
                           "# Humans need only:\n" +
                           "## Water\n" +
                           "## Protein";

            target.Format(input);
            string expected = "<ol>\n" +
                              "<li>Fuel could be:" +
                              "<ol>\n" +
                              "<li>Coal</li>\n" +
                              "<li>Gasoline</li>\n" +
                              "<li>Electricity</li>\n" +
                              "</ol>\n" +
                              "</li>\n" +
                              "<li>Humans need only:" +
                              "<ol>\n" +
                              "<li>Water</li>\n" +
                              "<li>Protein</li>\n" +
                              "</ol>\n" +
                              "</li>\n" +
                              "</ol>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void TestStuff(string input, string expected)
        {
            var outputter = new StringBuilderOutputter();
            var formatter = new TextileFormatter(outputter);

            formatter.Format(input);
            var actual = outputter.GetFormattedText();

            Bitmap diff;

            if (!actual.RendersEqual(expected, out diff))
            {
                var path = Path.Combine(Path.GetTempPath(), "Textile.Test");

                if (Directory.Exists(path))
                {
                }

                Directory.CreateDirectory(path);
                var filename = Path.Combine(path, $"{TestContext.CurrentContext.Test.Name}.png");

                diff.Save(filename);

                Assert.Fail($"HTML does not match.\r\nExpected:\r\n{expected}\r\n\r\nActual:\r\n{actual}\r\n\r\nDiff image: {filename}");
            }
        }
        public override string MarkUpToHTML(string source)
        {
            var output = new EscapeOutputter();

            TextileFormatter.FormatString(source, output);
            return(output.Result);
        }
 public string ScriptToHtml(string script)
 {
     if (script == null)
     {
         throw new ArgumentNullException("script");
     }
     return(TextileFormatter.FormatString(script));
 }
        public override string RenderHtml(string innerRepresentation)
        {
            var outputter = new StringBuilderTextileFormatter();
            var renderer  = new TextileFormatter(outputter);

            renderer.Format(innerRepresentation);
            return(outputter.GetFormattedText());
        }
Ejemplo n.º 6
0
        public void PhraseModifierFormatTestAllMixed()
        {
            string input    = "I seriously *{color:red}blushed* when I _(big)sprouted_ that corn stalk from my %[es]cabeza%.";
            string expected = "<p>I seriously <strong style=\"color:red;\">blushed</strong> when I <em class=\"big\">sprouted</em> that corn stalk from my <span lang=\"es\">cabeza</span>.</p>\n";
            string actual   = TextileFormatter.FormatString(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void Hyperlink()
        {
            const string input    = @"""get lost"":http://google.ca";
            const string expected = "<p><a href=\"http://google.ca\">get lost</a></p>\r\n";
            var          actual   = TextileFormatter.FormatString(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void ApplyFormating(NoticeMessage message)
        {
            var output    = new StringBuilderTextileFormatter();
            var formatter = new TextileFormatter(output);

            message.Subject = VelocityArguments.Replace(message.Subject, argMatchReplace);
            formatter.Format(message.Body);
            message.Body = Master.Replace("%CONTENT%", output.GetFormattedText());
        }
Ejemplo n.º 9
0
        public void ApplyFormating(NoticeMessage message)
        {
            var output    = new StringBuilderTextileFormatter();
            var formatter = new TextileFormatter(output);

            if (!string.IsNullOrEmpty(message.Subject))
            {
                message.Subject = VelocityArguments.Replace(message.Subject, m => m.Result("${arg}"));
            }

            if (!string.IsNullOrEmpty(message.Body))
            {
                formatter.Format(message.Body);

                var logoMail = ConfigurationManager.AppSettings["web.logo.mail"];
                var logo     = string.IsNullOrEmpty(logoMail) ? "http://cdn.teamlab.com/media/newsletters/images/header_04.jpg" : logoMail;
                message.Body = Resources.TemplateResource.HtmlMaster.Replace("%CONTENT%", output.GetFormattedText()).Replace("%LOGO%", logo);

                var footer  = message.GetArgument("WithPhoto");
                var partner = message.GetArgument("Partner");
                var res     = String.Empty;

                if (partner != null)
                {
                    res = partner.Value.ToString();
                }
                if (String.IsNullOrEmpty(res) && footer != null)
                {
                    switch ((string)footer.Value)
                    {
                    case "photo":
                        res = Resources.TemplateResource.FooterWithPhoto;
                        break;

                    case "links":
                        res = Resources.TemplateResource.FooterWithLinks;
                        break;

                    default:
                        res = String.Empty;
                        break;
                    }
                }
                message.Body = message.Body.Replace("%FOOTER%", res);

                var mail   = message.Recipient.Addresses.FirstOrDefault(r => r.Contains("@"));
                var domain = ConfigurationManager.AppSettings["web.teamlab-site"];
                var site   = string.IsNullOrEmpty(domain) ? "http://www.teamlab.com" : domain;
                var link   = site + string.Format("/Unsubscribe.aspx?id={0}", HttpServerUtility.UrlTokenEncode(Security.Cryptography.InstanceCrypto.Encrypt(Encoding.UTF8.GetBytes(mail.ToLowerInvariant()))));
                var text   = string.Format(Resources.TemplateResource.TextForFooter, link, DateTime.UtcNow.Year);

                message.Body = message.Body.Replace("%TEXTFOOTER%", text);
            }
        }
Ejemplo n.º 10
0
        public void FormatTestFootNote()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "fn1. Down here, in fact.";

            target.Format(input);
            string expected = "<p id=\"fn1\"><sup>1</sup> Down here, in fact.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void FormatTestRandomSentences()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "\"Textile\":http://textism.com/tools/textile/ is a \"Humane Web Text Generator\", as they say.";

            target.Format(input);
            string expected = "<p><a href=\"http://textism.com/tools/textile/\">Textile</a> is a &#8220;Humane Web Text Generator&#8221;, as they say.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void FormatTestSytledParagraph()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "p{color:blue;margin:30px}. Spacey blue.";

            target.Format(input);
            string expected = "<p style=\"color:blue;margin:30px;\">Spacey blue.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void FormatTestParagraphWithClassAndID()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "p(example1#big-red2). Red here.";

            target.Format(input);
            string expected = "<p class=\"example1\" id=\"big-red2\">Red here.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void FormatTestParagraphWithID()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "p(#big-red). Red here!";

            target.Format(input);
            string expected = "<p id=\"big-red\">Red here!</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void FormatTestParagraphWithClass()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "p(example1). An example.";

            target.Format(input);
            string expected = "<p class=\"example1\">An example.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void FormatTestOneParagraph()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "A single paragraph.";

            target.Format(input);

            string expected = "<p>A single paragraph.</p>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void FormatTestOneParagraphWithLineBreak()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "A single paragraph.\n" +
                           "Followed by the rest.";

            target.Format(input);

            string expected = "<p>A single paragraph.<br />\n" +
                              "Followed by the rest.</p>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 18
0
        public void BulletList()
        {
            const string input    = @"* me
* is
* the
* hello";
            const string expected = @"<ul>
<li>me</li>
<li>is</li>
<li>the</li>
<li>hello</li>
</ul>
";
            var          actual   = TextileFormatter.FormatString(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        public void FormatTestBlockQuote()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "An old text\n\n" +
                           "bq. A block quotation.\n\n" +
                           "Any old text";

            target.Format(input);
            string expected = "<p>An old text</p>\n" +
                              "<blockquote><p>A block quotation.</p></blockquote>\n" +
                              "<p>Any old text</p>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public void FormatTestTwoParagraphs()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "A single paragraph.\n" +
                           "\n" +
                           "Followed by another.";

            target.Format(input);

            string expected = "<p>A single paragraph.</p>\n" +
                              "<p>Followed by another.</p>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        public void FormatTestListSimple()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "# A first item\n" +
                           "# A second item\n" +
                           "# A third";

            target.Format(input);
            string expected = "<ol>\n" +
                              "<li>A first item</li>\n" +
                              "<li>A second item</li>\n" +
                              "<li>A third</li>\n" +
                              "</ol>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 22
0
        public void FormatTestTableWithCellAttributes()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "|_. attribute list |\n" +
                           "|<. align left |\n" +
                           "|>. align right|\n" +
                           "|=. center |\n" +
                           "|<>. justify |\n" +
                           "|^. valign top |\n" +
                           "|~. bottom |\n";

            target.Format(input);
            string expected = "<table>\n" +
                              "<tr>\n" +
                              "<th>attribute list </th>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"text-align:left;\">align left </td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"text-align:right;\">align right</td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"text-align:center;\">center </td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"text-align:justify;\">justify </td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"vertical-align:top;\">valign top </td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td style=\"vertical-align:bottom;\">bottom </td>\n" +
                              "</tr>\n" +
                              "</table>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 23
0
        public void FormatTestTableWithHeaders()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "|_. name |_.age |_. sex|\n" +
                           "| joan | 24 | f |\n";

            target.Format(input);
            string expected = "<table>\n" +
                              "<tr>\n" +
                              "<th>name </th><th>age </th><th>sex</th>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td> joan </td><td> 24 </td><td> f </td>\n" +
                              "</tr>\n" +
                              "</table>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 24
0
        public void FormatTestTableSimple()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "|name|age|sex|\n" +
                           "| joan arc| 24 | f |";

            target.Format(input);
            string expected = "<table>\n" +
                              "<tr>\n" +
                              "<td>name</td><td>age</td><td>sex</td>\n" +
                              "</tr>\n" +
                              "<tr>\n" +
                              "<td> joan arc</td><td> 24 </td><td> f </td>\n" +
                              "</tr>\n" +
                              "</table>\n";
            string actual = output.GetOutput();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public void ApplyFormating(NoticeMessage message)
        {
            var output    = new StringBuilderTextileFormatter();
            var formatter = new TextileFormatter(output);

            if (!string.IsNullOrEmpty(message.Subject))
            {
                message.Subject = VelocityArguments.Replace(message.Subject, m => m.Result("${arg}"));
            }

            if (string.IsNullOrEmpty(message.Body))
            {
                return;
            }

            formatter.Format(message.Body);

            var template        = GetTemplate(message);
            var analytics       = GetAnalytics(message);
            var imagePath       = GetImagePath(message);
            var logoImg         = GetLogoImg(message, imagePath);
            var logoText        = GetLogoText(message);
            var mailSettings    = GetMailSettings(message);
            var unsubscribeText = GetUnsubscribeText(message, mailSettings);

            string footerContent;
            string footerSocialContent;

            InitFooter(message, mailSettings, out footerContent, out footerSocialContent);

            message.Body = template.Replace("%ANALYTICS%", analytics)
                           .Replace("%CONTENT%", output.GetFormattedText())
                           .Replace("%LOGO%", logoImg)
                           .Replace("%LOGOTEXT%", logoText)
                           .Replace("%SITEURL%", mailSettings == null ? MailWhiteLabelSettings.DefaultMailSiteUrl : mailSettings.SiteUrl)
                           .Replace("%FOOTER%", footerContent)
                           .Replace("%FOOTERSOCIAL%", footerSocialContent)
                           .Replace("%TEXTFOOTER%", unsubscribeText)
                           .Replace("%IMAGEPATH%", imagePath);
        }
Ejemplo n.º 26
0
        public void FormatTestHeaders()
        {
            TestOutputter    output = new TestOutputter();
            TextileFormatter target = new TextileFormatter(output);

            string input = "h1. A simple header";

            target.Format(input);
            string expected = "<h1>A simple header</h1>\n";
            string actual   = output.GetOutput();

            Assert.AreEqual(expected, actual);

            input = "h1. A simple header\n" +
                    "h2. A sub header\n" +
                    "h3. A sub sub header";
            target.Format(input);
            expected = "<h1>A simple header</h1>\n" +
                       "<h2>A sub header</h2>\n" +
                       "<h3>A sub sub header</h3>\n";
            actual = output.GetOutput();
            Assert.AreEqual(expected, actual);
        }
 public PreCodeFormatterState(TextileFormatter formatter)
     : base(formatter)
 {
 }
 public OrderedListFormatterState(TextileFormatter formatter)
     : base(formatter)
 {
 }
 protected SimpleBlockFormatterState(TextileFormatter formatter)
     : base(formatter)
 {
 }
 public TableRowFormatterState(TextileFormatter f)
     : base(f)
 {
 }
Ejemplo n.º 31
0
        public string Process(string input)
        {
            var output = TextileFormatter.FormatString(input);

            return(output);
        }
 public PassthroughFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public HeaderFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public FootNoteFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public FootNoteFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public ParagraphFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public BlockQuoteFormatterState(TextileFormatter f)
     : base(f)
 {
 }
Ejemplo n.º 38
0
 public TableRowFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public NoTextileFormatterState(TextileFormatter f)
     : base(f)
 {
 }
 public HeaderFormatterState(TextileFormatter f)
     : base(f)
 {
 }
Ejemplo n.º 41
0
 public PaddingFormatterState(TextileFormatter formatter)
     : base(formatter)
 {
 }