public override string RenderHtml(string innerRepresentation)
        {
            var outputter = new StringBuilderTextileFormatter();
            var renderer  = new TextileFormatter(outputter);

            renderer.Format(innerRepresentation);
            return(outputter.GetFormattedText());
        }
Beispiel #2
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());
        }
        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);
            }
        }
        public void OnContextAcquired()
        {
            // arrange
            var output = new StringBuilderTextileFormatter();
            output.Begin();
            var fnfs = new FootNoteFormatterState(new TextileFormatter(output));
            fnfs.m_tag = "fn42";

            // act
            fnfs.OnContextAcquired();

            // assert
            Assert.AreEqual(42, fnfs.m_noteID);
        }
        public void Enter()
        {
            // arrange
            var output = new StringBuilderTextileFormatter();
            output.Begin();
            var fnfs = new FootNoteFormatterState(new TextileFormatter(output));
            fnfs.m_noteID = 1;
            fnfs.m_alignNfo = String.Empty;
            fnfs.m_attNfo = "{color:red}";

            // act
            fnfs.Enter();

            // assert
            Assert.AreEqual("<p id=\"fn1\" style=\"color:red;\"><sup>1</sup> ", output.GetFormattedText());
        }
        public void OnContextAcquired()
        {
            // arrange
            var output = new StringBuilderTextileFormatter();

            output.Begin();
            var fnfs = new FootNoteFormatterState(new TextileFormatter(output));

            fnfs.m_tag = "fn42";

            // act
            fnfs.OnContextAcquired();

            // assert
            Assert.AreEqual(42, fnfs.m_noteID);
        }
        public void OnContextAcquired()
        {
            // arrange
            var output = new StringBuilderTextileFormatter ();
            output.Begin();
            var fnfs = new FootNoteFormatterState(new TextileFormatter(output));
            var expression = SimpleBlockFormatterState.PatternBegin + @"fn[0-9]+" + SimpleBlockFormatterState.PatternEnd;
            var input = "fn1{color:red}. This is the footnote";
            Match m = Regex.Match(input, expression);
            fnfs.Consume (input, m);

            // act
            // do nothing, since Consume() already caused OnContextAcquired() to be called

            // assert
            Assert.AreEqual(1, fnfs.m_noteID);
        }
        public void Enter()
        {
            // arrange
            var output = new StringBuilderTextileFormatter();

            output.Begin();
            var fnfs = new FootNoteFormatterState(new TextileFormatter(output));

            fnfs.m_noteID   = 1;
            fnfs.m_alignNfo = String.Empty;
            fnfs.m_attNfo   = "{color:red}";

            // act
            fnfs.Enter();

            // assert
            Assert.AreEqual("<p id=\"fn1\" style=\"color:red;\"><sup>1</sup> ", output.GetFormattedText());
        }
        public void EnterAndOnContextAcquired()
        {
            // arrange
            var output = new StringBuilderTextileFormatter();

            output.Begin();
            var   fnfs       = new FootNoteFormatterState(new TextileFormatter(output));
            var   expression = SimpleBlockFormatterState.PatternBegin + @"fn[0-9]+" + SimpleBlockFormatterState.PatternEnd;
            var   input      = "fn1{color:red}. This is the footnote";
            Match m          = Regex.Match(input, expression);

            fnfs.Consume(input, m);

            // act
            // do nothing, since Consume() already caused OnContextAcquired() and Enter() to be called

            // assert
            Assert.AreEqual("<p id=\"fn1\" style=\"color:red;\"><sup>1</sup> ", output.GetFormattedText());
        }
Beispiel #10
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);
        }
Beispiel #11
0
 public WikiRenderer()
 {
     output    = new StringBuilderTextileFormatter();
     formatter = new TextileFormatter(output);
 }
        public void ApplyFormating(NoticeMessage message)
        {
            var template       = NotifyTemplateResource.HtmlMaster;
            var isPersonalTmpl = false;

            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 isPersonal = message.GetArgument("IsPersonal");

            if (isPersonal != null && (string)isPersonal.Value == "true")
            {
                isPersonalTmpl = true;
            }

            var templateTag = message.GetArgument("MasterTemplate");

            if (templateTag != null)
            {
                var templateTagValue = templateTag.Value as string;
                if (!string.IsNullOrEmpty(templateTagValue))
                {
                    var templateValue = NotifyTemplateResource.ResourceManager.GetString(templateTagValue);
                    if (!string.IsNullOrEmpty(templateValue))
                    {
                        template = templateValue;
                    }
                }
            }

            string logoImg;

            if (isPersonalTmpl)
            {
                logoImg = "http://cdn.teamlab.com/media/newsletters/images/mail_logo.png";
            }
            else
            {
                logoImg = ConfigurationManager.AppSettings["web.logo.mail"];
                if (String.IsNullOrEmpty(logoImg))
                {
                    var logo = message.GetArgument("LetterLogo");
                    if (logo != null && (string)logo.Value != "")
                    {
                        logoImg = (string)logo.Value;
                    }
                    else
                    {
                        logoImg = "http://cdn.teamlab.com/media/newsletters/images/mail_logo.png";
                    }
                }
            }

            var logoText = ConfigurationManager.AppSettings["web.logotext.mail"];

            if (String.IsNullOrEmpty(logoText))
            {
                var llt = message.GetArgument("LetterLogoText");
                if (llt != null && (string)llt.Value != "")
                {
                    logoText = (string)llt.Value;
                }
                else
                {
                    logoText = TenantWhiteLabelSettings.DefaultLogoText;
                }
            }

            var mailWhiteLabelTag      = message.GetArgument("MailWhiteLabelSettings");
            var mailWhiteLabelSettings = mailWhiteLabelTag == null ? null : mailWhiteLabelTag.Value as MailWhiteLabelSettings;

            message.Body = template.Replace("%CONTENT%", output.GetFormattedText())
                           .Replace("%LOGO%", logoImg)
                           .Replace("%LOGOTEXT%", logoText)
                           .Replace("%SITEURL%", mailWhiteLabelSettings == null ? MailWhiteLabelSettings.DefaultMailSiteUrl : mailWhiteLabelSettings.SiteUrl);

            var footer  = message.GetArgument("Footer");
            var partner = message.GetArgument("Partner");

            var footerContent       = string.Empty;
            var footerSocialContent = string.Empty;

            if (partner != null)
            {
                footerContent = partner.Value.ToString();
            }

            if (String.IsNullOrEmpty(footerContent) && footer != null)
            {
                switch ((string)footer.Value)
                {
                case "common":
                    InitCommonFooter(mailWhiteLabelSettings, out footerContent, out footerSocialContent);
                    break;

                case "personal":
                    footerSocialContent = NotifyTemplateResource.FooterSocial;
                    break;

                case "freecloud":
                    footerContent       = NotifyTemplateResource.FooterFreeCloud;
                    footerSocialContent = NotifyTemplateResource.FooterSocial;
                    break;

                case "opensource":
                    footerContent       = NotifyTemplateResource.FooterOpensource;
                    footerSocialContent = NotifyTemplateResource.FooterSocial;
                    break;
                }
            }

            message.Body = message.Body
                           .Replace("%FOOTER%", footerContent)
                           .Replace("%FOOTERSOCIAL%", footerSocialContent);

            var text = "";

            if (ConfigurationManager.AppSettings["core.base-domain"] != "localhost")
            {
                var noUnsubscribeLink = message.GetArgument("noUnsubscribeLink");
                if (noUnsubscribeLink == null || (string)noUnsubscribeLink.Value == "false")
                {
                    var isHosted = ConfigurationManager.AppSettings["core.payment-partners-hosted"];
                    if (String.IsNullOrEmpty(isHosted) || isHosted == "false")
                    {
                        var mail   = message.Recipient.Addresses.FirstOrDefault(r => r.Contains("@"));
                        var domain = ConfigurationManager.AppSettings["web.teamlab-site"];
                        var site   = string.IsNullOrEmpty(domain) ? "http://www.onlyoffice.com" : domain;
                        var link   = site +
                                     string.Format("/Unsubscribe.aspx?id={0}",
                                                   HttpServerUtility.UrlTokenEncode(
                                                       Security.Cryptography.InstanceCrypto.Encrypt(
                                                           Encoding.UTF8.GetBytes(mail.ToLowerInvariant()))));

                        text = string.Format(NotifyTemplateResource.TextForFooterWithUnsubscribe, link);
                    }
                }

                text += string.Format(NotifyTemplateResource.TextForFooter, DateTime.UtcNow.Year, string.Empty);
            }

            message.Body = message.Body.Replace("%TEXTFOOTER%", text);
        }
Beispiel #13
0
        public void ApplyFormating(NoticeMessage message)
        {
            bool isPromoTmpl = false;
            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 isPromo = message.GetArgument("isPromoLetter");
                if (isPromo != null && (string)isPromo.Value == "true")
                {
                    isPromoTmpl = true;
                }

                var logoImg = "";
                if (isPromoTmpl)
                {
                    logoImg = "http://cdn.teamlab.com/media/newsletters/images/logo.png";
                }
                else
                {
                    logoImg = ConfigurationManager.AppSettings["web.logo.mail"];
                    if (String.IsNullOrEmpty(logoImg))
                    {
                        var logo = message.GetArgument("LetterLogo");
                        if (logo != null && (string)logo.Value != "")
                        {
                            logoImg = (string)logo.Value;
                        }
                        else
                        {
                            logoImg = "http://cdn.teamlab.com/media/newsletters/images/header_08.png";
                        }
                    }
                }


                var template = isPromoTmpl ? Resources.TemplateResource.HtmlMasterPromo : Resources.TemplateResource.HtmlMaster;
                message.Body = template.Replace("%CONTENT%", output.GetFormattedText()).Replace("%LOGO%", logoImg);

                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;

                    case "personal":
                        res = Resources.TemplateResource.FooterPersonal;
                        break;

                    case "freecloud":
                        res = Resources.TemplateResource.FooterFreeCloud;
                        break;

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


                var text = "";

                var noUnsubscribeLink = message.GetArgument("noUnsubscribeLink");
                if (noUnsubscribeLink == null || (string)noUnsubscribeLink.Value == "false")
                {
                    var isHosted = ConfigurationManager.AppSettings["core.payment-partners-hosted"];
                    if (String.IsNullOrEmpty(isHosted) || isHosted == "false")
                    {
                        var mail   = message.Recipient.Addresses.FirstOrDefault(r => r.Contains("@"));
                        var domain = ConfigurationManager.AppSettings["web.teamlab-site"];
                        var site   = string.IsNullOrEmpty(domain) ? "http://www.onlyoffice.com" : domain;
                        var link   = site + string.Format("/Unsubscribe.aspx?id={0}", HttpServerUtility.UrlTokenEncode(Security.Cryptography.InstanceCrypto.Encrypt(Encoding.UTF8.GetBytes(mail.ToLowerInvariant()))));

                        text = string.Format(Resources.TemplateResource.TextForFooterWithUnsubscribe, link);
                    }
                }

                text        += string.Format(Resources.TemplateResource.TextForFooter, DateTime.UtcNow.Year, string.Empty);
                message.Body = message.Body.Replace("%TEXTFOOTER%", text);
            }
        }