Skip to content

Commit

Permalink
Minor updates before releasing 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Feb 17, 2019
1 parent cfe4fb0 commit cbe5113
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 26 deletions.
15 changes: 3 additions & 12 deletions Blade/Blade/Tags/LineBreaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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


private static readonly Regex Br = Replacer("br");
private static readonly Regex RelpacerBr = TagReplacer.Replacer("br");

/// <summary>
/// Convert <br> and <br/> into line-breaks
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string Br2Nl(string value)
=> Br.Replace(value, "\n");
=> RelpacerBr.Replace(value, "\n");

/// <summary>
/// Convert <br> and <br/> into line-breaks
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string Br2Space(string value)
=> Br.Replace(value, " ");
=> RelpacerBr.Replace(value, " ");
}
}
2 changes: 0 additions & 2 deletions Blade/Blade/Tags/Remove.cs → Blade/Blade/Tags/Strip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ public static string Strip(string original)

return sanitizedText.Trim();
}


}
}
18 changes: 18 additions & 0 deletions Blade/Blade/Tags/TagReplacer.cs
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
27 changes: 27 additions & 0 deletions Blade/Blade/Tags/Wrap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Connect.Razor.Blade
{
public partial class Tags
{
/// <summary>
/// internal test wrap-tag, not ready for use, so still marked internal
/// </summary>
/// <param name="tag"></param>
/// <param name="content"></param>
/// <param name="id"></param>
/// <param name="cls"></param>
/// <param name="attr"></param>
/// <returns></returns>
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}</{tag}>";
}
}
}
4 changes: 1 addition & 3 deletions Blade/Blade/Text/HasText.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Text.RegularExpressions;
using Connect.Razor.Internals;
using Connect.Razor.Internals;

namespace Connect.Razor.Blade
{
Expand Down
1 change: 0 additions & 1 deletion Blade/Blade/Text/Zip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.RegularExpressions;
using Connect.Razor.Internals;

namespace Connect.Razor.Blade
{
Expand Down
4 changes: 3 additions & 1 deletion Blade/Razor - Blade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Blade\Tags\LineBreaks.cs" />
<Compile Include="Blade\Tags\TagReplacer.cs" />
<Compile Include="Blade\Tags\Wrap.cs" />
<Compile Include="Blade\Text\Zip.cs" />
<Compile Include="Blade\Text\Crop.cs" />
<Compile Include="Internals\Defaults.cs" />
<Compile Include="Blade\Dic\SafeGet.cs" />
<Compile Include="Blade\Dic\Dynamic.cs" />
<Compile Include="Blade\Tags\Remove.cs" />
<Compile Include="Blade\Tags\Strip.cs" />
<Compile Include="Blade\Text\HasText.cs" />
<Compile Include="Blade\Text\FirstText.cs" />
<Compile Include="Blade\Text\Ellipsis.cs" />
Expand Down
3 changes: 1 addition & 2 deletions Razor Blades Tests/Test_Blades_Zip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Connect.Razor.Internals;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Connect.Razor.Blade;


Expand Down
3 changes: 1 addition & 2 deletions Razor Blades Tests/Text_Crop.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Please also read the [conventions](docs/conventions.md) so we can work on this together.

0 comments on commit cbe5113

Please sign in to comment.