diff --git a/Blade/Blade/Tags/LineBreaks.cs b/Blade/Blade/Tags/LineBreaks.cs index adfc070..349e50b 100644 --- a/Blade/Blade/Tags/LineBreaks.cs +++ b/Blade/Blade/Tags/LineBreaks.cs @@ -4,15 +4,6 @@ namespace Connect.Razor.Blade { public static partial class Tags { - public static Regex Replacer(string names, bool open = true, bool close = true) - { - if (names.IndexOf(',') > -1) - names = "[" + names.Replace(',', '|') + "]"; - const string closeOptional = "[/]?"; - const string closeRequired = "/"; - var closer = open ? (close ? closeOptional : "") : (close ? closeRequired : ""); - return new Regex("<" + closer + names + "[^>]*>", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); - } /// /// Convert \n into line-breaks @@ -23,7 +14,7 @@ public static string Nl2Br(string value) => Text.Nl2X(value, "
"); - private static readonly Regex Br = Replacer("br"); + private static readonly Regex RelpacerBr = TagReplacer.Replacer("br"); /// /// Convert
and
into line-breaks @@ -31,7 +22,7 @@ public static string Nl2Br(string value) /// /// public static string Br2Nl(string value) - => Br.Replace(value, "\n"); + => RelpacerBr.Replace(value, "\n"); /// /// Convert
and
into line-breaks @@ -39,6 +30,6 @@ public static string Br2Nl(string value) /// /// public static string Br2Space(string value) - => Br.Replace(value, " "); + => RelpacerBr.Replace(value, " "); } } diff --git a/Blade/Blade/Tags/Remove.cs b/Blade/Blade/Tags/Strip.cs similarity index 99% rename from Blade/Blade/Tags/Remove.cs rename to Blade/Blade/Tags/Strip.cs index 08b9db5..84edadd 100644 --- a/Blade/Blade/Tags/Remove.cs +++ b/Blade/Blade/Tags/Strip.cs @@ -19,7 +19,5 @@ public static string Strip(string original) return sanitizedText.Trim(); } - - } } diff --git a/Blade/Blade/Tags/TagReplacer.cs b/Blade/Blade/Tags/TagReplacer.cs new file mode 100644 index 0000000..f13ee63 --- /dev/null +++ b/Blade/Blade/Tags/TagReplacer.cs @@ -0,0 +1,18 @@ +using System.Text.RegularExpressions; + +namespace Connect.Razor.Blade +{ + internal static class TagReplacer + { + internal static Regex Replacer(string names, bool open = true, bool close = true) + { + if (names.IndexOf(',') > -1) + names = "[" + names.Replace(',', '|') + "]"; + const string closeOptional = "[/]?"; + const string closeRequired = "/"; + var closer = open ? (close ? closeOptional : "") : (close ? closeRequired : ""); + return new Regex("<" + closer + names + "[^>]*>", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); + } + + } +} diff --git a/Blade/Blade/Tags/Wrap.cs b/Blade/Blade/Tags/Wrap.cs new file mode 100644 index 0000000..5d67a58 --- /dev/null +++ b/Blade/Blade/Tags/Wrap.cs @@ -0,0 +1,27 @@ +namespace Connect.Razor.Blade +{ + public partial class Tags + { + /// + /// internal test wrap-tag, not ready for use, so still marked internal + /// + /// + /// + /// + /// + /// + /// + internal static string Wrap(string tag, string content, string id = null, string cls = null, string attr = null) + { + if (attr == null) attr = ""; + + if (cls != null) + attr = $"class=\"{cls}\" " + attr; + if (id != null) + attr = $"id=\"{id}\" " + attr; + + if (!string.IsNullOrWhiteSpace(attr)) attr = " " + attr; + return $"<{tag}{attr}>{content}"; + } + } +} diff --git a/Blade/Blade/Text/HasText.cs b/Blade/Blade/Text/HasText.cs index 9530538..30ac2a5 100644 --- a/Blade/Blade/Text/HasText.cs +++ b/Blade/Blade/Text/HasText.cs @@ -1,6 +1,4 @@ -using System; -using System.Text.RegularExpressions; -using Connect.Razor.Internals; +using Connect.Razor.Internals; namespace Connect.Razor.Blade { diff --git a/Blade/Blade/Text/Zip.cs b/Blade/Blade/Text/Zip.cs index 34a09e5..4cff089 100644 --- a/Blade/Blade/Text/Zip.cs +++ b/Blade/Blade/Text/Zip.cs @@ -1,5 +1,4 @@ using System.Text.RegularExpressions; -using Connect.Razor.Internals; namespace Connect.Razor.Blade { diff --git a/Blade/Razor - Blade.csproj b/Blade/Razor - Blade.csproj index 84d9381..b01862e 100644 --- a/Blade/Razor - Blade.csproj +++ b/Blade/Razor - Blade.csproj @@ -37,12 +37,14 @@ + + - + diff --git a/Razor Blades Tests/Test_Blades_Zip.cs b/Razor Blades Tests/Test_Blades_Zip.cs index b2f234a..47eafa6 100644 --- a/Razor Blades Tests/Test_Blades_Zip.cs +++ b/Razor Blades Tests/Test_Blades_Zip.cs @@ -1,5 +1,4 @@ -using Connect.Razor.Internals; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Connect.Razor.Blade; diff --git a/Razor Blades Tests/Text_Crop.cs b/Razor Blades Tests/Text_Crop.cs index becfd0b..af61105 100644 --- a/Razor Blades Tests/Text_Crop.cs +++ b/Razor Blades Tests/Text_Crop.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Connect.Razor.Internals; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/readme.md b/readme.md index 84c68aa..3b6d38f 100644 --- a/readme.md +++ b/readme.md @@ -78,14 +78,17 @@ This is a short summary of the most used variations of the helpers. Further deta ## Ideas to discuss +1. `Tags.Strip(htmlText, tagName)` 1. `Tags.Strip(htmlText, csvListOfTagsToStrip)` +1. `Tags.Wrap(tagName, content, id, cls, attr)` - something which puts a tag (like a div, span, p) around some content 1. `Tags.Replace(htmlText, listOfTags, replacementTag)` 1. (place other wishes into issues for discussion) -1. `Dic.ToDynamic(dictionary)` - converts a Dictionary to an expando object, so you can write obj.Property instead of obj["Property"]; would return null if a property would not be found. +1. `Dic.ToDynamic(dictionary)` - converts a Dictionary to an expando object, so you can write `obj.Property` instead of `obj["Property"]`; would return null if a property would not be found. +1. `Mail.Generate(pathToRazor, objValues)` - uses a razor template to generate a mail. -## Contributions +## Your Contributions 1. Any tests and bugfixes are always welcome and will be processed quickly by iJungleboy. 1. New commands / overloads / features should be discussed in issues before adding to this library, to ensure that it's inline with the overal purpose of this library. -Please also read the [conventions](docs/conventions.md) so we can work on this together. \ No newline at end of file +Please also read the [conventions](docs/conventions.md) so we can work on this together. \ No newline at end of file