public void ShouldReadHtmlFile_and_FormatData_Week() { ContactDTO dto = new ContactDTO(); dto.Id = "1235"; dto.RegistrationDate = "06-11-2015"; dto.Name = "Kannan"; dto.Email = "*****@*****.**"; var registrationDate = dto.ConvertRegistrationToDate() .AddMonths(12) .AddDays(-7); Reminder reminder = new Reminder(); reminder.RegistrationDate = dto.ConvertRegistrationToDate(); TemplateFormatter formatter = new TemplateFormatter(); var str = formatter.GenerateHtml(dto, reminder); Assert.IsTrue(str.Length > 0); Assert.IsTrue(str.Contains("Kannan")); Assert.IsTrue(str.Contains(dto.Id)); Assert.IsTrue(str.Contains("week")); }
/// <summary> /// /// </summary> /// <param name="content"></param> /// <param name="message"></param> /// <returns></returns> public virtual string Fromat(Content content, Message message) { Dictionary <string, TemplateFormatter> templateValues = content.CreateVariableMaping(message); var mapping = new Dictionary <string, string>(); foreach (string s in NamedFormatters) { //if couldn't find the Valibel in mapping, it will try to //get value by reflact. if (!templateValues.ContainsKey(s)) { PropertyInfo propertyInfo = content.Value.GetType().GetProperty(s); if (propertyInfo != null) { templateValues[s] = new TemplateFormatter { Value = propertyInfo.GetValue(content.Value, null) }; } } mapping.Add(s, templateValues[s].ToString()); } return(NamedFormatterHelper.Replace(TemplateContent, mapping)); }
private static string Format(string source, string append) { var sb = new StringBuilder(); TemplateFormatter.Format(sb, new(source), append); return(sb.ToString()); }
internal MailSmartFormatter() : base() { // Register all default extensions here: // Add all extensions: // Note, the order is important; the extensions // will be executed in this order: var listFormatter = new ListFormatter(this); AddExtensions( (ISource)listFormatter, // ListFormatter MUST be first new DictionarySource(this), new ValueTupleSource(this), new SmartObjectsSource(this), new JsonSource(this), //new XmlSource(this), new ReflectionSource(this), // The DefaultSource reproduces the string.Format behavior: new DefaultSource(this) ); AddExtensions( (IFormatter)listFormatter, new PluralLocalizationFormatter("en"), new ConditionalFormatter(), new TimeFormatter("en"), //new XElementFormatter(), new ChooseFormatter(), new DefaultFormatter() ); Templates = new TemplateFormatter(this); AddExtensions(Templates); }
public void Templates_can_be_nested(bool useFormalSalutation, string expected) { var smart = Smart.CreateDefaultSmartFormat(); var templates = new TemplateFormatter(); smart.AddExtensions(templates); // ConditionalFormatter with arg1 // controls the kind of salutation templates.Register("salutation", "{1:cond:{:t:sal_formal}|{:t:sal_informal}}"); // Register the formal nested template templates.Register("sal_formal", "Dear Mr {LastName}"); // Register the informal nested template templates.Register("sal_informal", "Hi {Nickname}"); var person = new { FirstName = "Joseph", Nickname = "Joe", LastName = "Doe" }; // Use the "master" template with different args var result = smart.Format("{0:t(salutation)}:", person, useFormalSalutation); Assert.That(result, Is.EqualTo(expected)); }
private static SmartFormatter GetFormatterWithRegisteredTemplates(CaseSensitivityType caseSensitivity) { var templates = new TemplateFormatter { CanAutoDetect = false }; var smart = Smart.CreateDefaultSmartFormat(new SmartSettings { CaseSensitivity = caseSensitivity }); smart.AddExtensions(templates); templates.Register("firstLast", "{First} {Last}"); templates.Register("lastFirst", "{Last}, {First}"); templates.Register("FIRST", "{First.ToUpper}"); templates.Register("last", "{Last.ToLower}"); if (smart.Settings.CaseSensitivity == CaseSensitivityType.CaseSensitive) { templates.Register("LAST", "{Last.ToUpper}"); } templates.Register("NESTED", "{:t:FIRST} {:t:last}"); return(smart); }
public void Given_test_cases_render_as_expected(string template, string val1, string val2, string expectation) { var formatter = TemplateFormatter.Create(template, ValueMappingProvider); var result = formatter((val1, val2)); Assert.AreEqual(expectation, result); }
public NotificationController() { _reminder = new Reminder(); _emailService = new GmailSMTPService(); _reader = new CSVReader(); _formatter = new TemplateFormatter(); _repo = new EmailHistoryRepository(); }
public void Formatter_can_be_reused_with_different_inputs() { var formatter = TemplateFormatter.Create("Example {val1} Template {val2}", ValueMappingProvider); var result1 = formatter(("x", "y")); var result2 = formatter(("a", "b")); Assert.AreEqual("Example x Template y", result1); Assert.AreEqual("Example a Template b", result2); }
private void CreateWindowGenerate() { // Crée fenêtre de génération du code // D'abord, créer object qui gère le content complet du template courant Helpers.TemplateContent tc = new Helpers.TemplateContent(currentTemplate()); // Ensuite créer l'object qui formatte le code sur la base du content TemplateFormatter tf = new TemplateFormatter(tc); // Ensuite créer la fenêtre avec code généré WindowGeneratedCode gc = new WindowGeneratedCode(); gc.Code.Text = tf.generate(); gc.Show(); }
private void RegisterTemplates(SmartFormatter smart) { var templates = new TemplateFormatter(smart); smart.AddExtensions(templates); templates.Register("firstLast", "{First} {Last}"); templates.Register("lastFirst", "{Last}, {First}"); templates.Register("FIRST", "{First.ToUpper}"); templates.Register("last", "{Last.ToLower}"); if (smart.Settings.CaseSensitivity == CaseSensitivityType.CaseSensitive) { templates.Register("LAST", "{Last.ToUpper}"); } templates.Register("NESTED", "{:template:FIRST} {:template:last}"); }
public void ShouldReadHtmlFile_and_FormatData_Today() { ContactDTO dto = new ContactDTO(); dto.Id = "1235"; dto.RegistrationDate = "30-10-2015"; dto.Name = "Kannan"; dto.Email = "*****@*****.**"; Reminder reminder = new Reminder(); reminder.RegistrationDate = dto.ConvertRegistrationToDate(); TemplateFormatter formatter = new TemplateFormatter(); var str = formatter.GenerateHtml(dto, reminder); Assert.IsNotNull(str); Assert.IsTrue(str.Contains("Kannan")); Assert.IsTrue(str.Contains(dto.Id)); Assert.IsTrue(str.Contains("today")); }
private static void DoDecompile(DecompileOptions decompileOptions) { IList <Template> templates; var stream = File.OpenRead(decompileOptions.InputFile); using (var streamReader = new StreamReader(stream)) { var deserialiser = SettingsSerialisation.DeserialiseFromXaml(streamReader); templates = deserialiser.DeserialiseTemplates(); } foreach (var template in templates) { var name = template.Shortcut ?? template.Description.Replace(' ', '_'); var filename = InvalidFileCharsRegex.Replace(name + ".md", string.Empty); var file = File.Open(Path.Combine(decompileOptions.OutDir, filename), FileMode.Create, FileAccess.Write); using (var writer = new StreamWriter(file)) { var formatter = new TemplateFormatter(writer); formatter.FormatTemplate(template); } } }
/// <summary> /// /// </summary> /// <param name="content"></param> /// <param name="message"></param> /// <returns></returns> public virtual string Fromat(Content content, Message message) { Dictionary<string, TemplateFormatter> templateValues = content.CreateVariableMaping(message); var mapping = new Dictionary<string, string>(); foreach (string s in NamedFormatters) { //if couldn't find the Valibel in mapping, it will try to //get value by reflact. if (!templateValues.ContainsKey(s)) { PropertyInfo propertyInfo = content.Value.GetType().GetProperty(s); if (propertyInfo != null) { templateValues[s] = new TemplateFormatter { Value = propertyInfo.GetValue(content.Value, null) }; } } mapping.Add(s, templateValues[s].ToString()); } return NamedFormatterHelper.Replace(TemplateContent, mapping); }