Skip to content

Commit cbe5113

Browse files
committed
Minor updates before releasing 1.0
1 parent cfe4fb0 commit cbe5113

10 files changed

Lines changed: 60 additions & 26 deletions

File tree

Blade/Blade/Tags/LineBreaks.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ namespace Connect.Razor.Blade
44
{
55
public static partial class Tags
66
{
7-
public static Regex Replacer(string names, bool open = true, bool close = true)
8-
{
9-
if (names.IndexOf(',') > -1)
10-
names = "[" + names.Replace(',', '|') + "]";
11-
const string closeOptional = "[/]?";
12-
const string closeRequired = "/";
13-
var closer = open ? (close ? closeOptional : "") : (close ? closeRequired : "");
14-
return new Regex("<" + closer + names + "[^>]*>", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
15-
}
167

178
/// <summary>
189
/// Convert \n into line-breaks
@@ -23,22 +14,22 @@ public static string Nl2Br(string value)
2314
=> Text.Nl2X(value, "<br>");
2415

2516

26-
private static readonly Regex Br = Replacer("br");
17+
private static readonly Regex RelpacerBr = TagReplacer.Replacer("br");
2718

2819
/// <summary>
2920
/// Convert <br> and <br/> into line-breaks
3021
/// </summary>
3122
/// <param name="value"></param>
3223
/// <returns></returns>
3324
public static string Br2Nl(string value)
34-
=> Br.Replace(value, "\n");
25+
=> RelpacerBr.Replace(value, "\n");
3526

3627
/// <summary>
3728
/// Convert <br> and <br/> into line-breaks
3829
/// </summary>
3930
/// <param name="value"></param>
4031
/// <returns></returns>
4132
public static string Br2Space(string value)
42-
=> Br.Replace(value, " ");
33+
=> RelpacerBr.Replace(value, " ");
4334
}
4435
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ public static string Strip(string original)
1919

2020
return sanitizedText.Trim();
2121
}
22-
23-
2422
}
2523
}

Blade/Blade/Tags/TagReplacer.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Connect.Razor.Blade
4+
{
5+
internal static class TagReplacer
6+
{
7+
internal static Regex Replacer(string names, bool open = true, bool close = true)
8+
{
9+
if (names.IndexOf(',') > -1)
10+
names = "[" + names.Replace(',', '|') + "]";
11+
const string closeOptional = "[/]?";
12+
const string closeRequired = "/";
13+
var closer = open ? (close ? closeOptional : "") : (close ? closeRequired : "");
14+
return new Regex("<" + closer + names + "[^>]*>", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
15+
}
16+
17+
}
18+
}

Blade/Blade/Tags/Wrap.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Connect.Razor.Blade
2+
{
3+
public partial class Tags
4+
{
5+
/// <summary>
6+
/// internal test wrap-tag, not ready for use, so still marked internal
7+
/// </summary>
8+
/// <param name="tag"></param>
9+
/// <param name="content"></param>
10+
/// <param name="id"></param>
11+
/// <param name="cls"></param>
12+
/// <param name="attr"></param>
13+
/// <returns></returns>
14+
internal static string Wrap(string tag, string content, string id = null, string cls = null, string attr = null)
15+
{
16+
if (attr == null) attr = "";
17+
18+
if (cls != null)
19+
attr = $"class=\"{cls}\" " + attr;
20+
if (id != null)
21+
attr = $"id=\"{id}\" " + attr;
22+
23+
if (!string.IsNullOrWhiteSpace(attr)) attr = " " + attr;
24+
return $"<{tag}{attr}>{content}</{tag}>";
25+
}
26+
}
27+
}

Blade/Blade/Text/HasText.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Text.RegularExpressions;
3-
using Connect.Razor.Internals;
1+
using Connect.Razor.Internals;
42

53
namespace Connect.Razor.Blade
64
{

Blade/Blade/Text/Zip.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Text.RegularExpressions;
2-
using Connect.Razor.Internals;
32

43
namespace Connect.Razor.Blade
54
{

Blade/Razor - Blade.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737
</ItemGroup>
3838
<ItemGroup>
3939
<Compile Include="Blade\Tags\LineBreaks.cs" />
40+
<Compile Include="Blade\Tags\TagReplacer.cs" />
41+
<Compile Include="Blade\Tags\Wrap.cs" />
4042
<Compile Include="Blade\Text\Zip.cs" />
4143
<Compile Include="Blade\Text\Crop.cs" />
4244
<Compile Include="Internals\Defaults.cs" />
4345
<Compile Include="Blade\Dic\SafeGet.cs" />
4446
<Compile Include="Blade\Dic\Dynamic.cs" />
45-
<Compile Include="Blade\Tags\Remove.cs" />
47+
<Compile Include="Blade\Tags\Strip.cs" />
4648
<Compile Include="Blade\Text\HasText.cs" />
4749
<Compile Include="Blade\Text\FirstText.cs" />
4850
<Compile Include="Blade\Text\Ellipsis.cs" />

Razor Blades Tests/Test_Blades_Zip.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Connect.Razor.Internals;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using Connect.Razor.Blade;
43

54

Razor Blades Tests/Text_Crop.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
43
using Connect.Razor.Internals;
54
using Microsoft.VisualStudio.TestTools.UnitTesting;

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ This is a short summary of the most used variations of the helpers. Further deta
7878

7979
## Ideas to discuss
8080

81+
1. `Tags.Strip(htmlText, tagName)`
8182
1. `Tags.Strip(htmlText, csvListOfTagsToStrip)`
83+
1. `Tags.Wrap(tagName, content, id, cls, attr)` - something which puts a tag (like a div, span, p) around some content
8284
1. `Tags.Replace(htmlText, listOfTags, replacementTag)`
8385
1. (place other wishes into issues for discussion)
84-
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.
86+
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.
87+
1. `Mail.Generate(pathToRazor, objValues)` - uses a razor template to generate a mail.
8588

86-
## Contributions
89+
## Your Contributions
8790

8891
1. Any tests and bugfixes are always welcome and will be processed quickly by iJungleboy.
8992
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.
9093

91-
Please also read the [conventions](docs/conventions.md) so we can work on this together.
94+
Please also read the [conventions](docs/conventions.md) so we can work on this together.

0 commit comments

Comments
 (0)