diff --git a/Blade/ConditionalOutput.cs b/Blade/ConditionalOutput.cs deleted file mode 100644 index 64206e4..0000000 --- a/Blade/ConditionalOutput.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Connect.Razor -{ - public static partial class Temporary - { - - public static string If(bool condition, string result, string otherwise = null) - { - return condition ? result : otherwise; - } - - } -} diff --git a/Blade/RazorBlade.csproj b/Blade/RazorBlade.csproj index 8824c64..474c1aa 100644 --- a/Blade/RazorBlade.csproj +++ b/Blade/RazorBlade.csproj @@ -38,7 +38,6 @@ - @@ -46,7 +45,6 @@ - diff --git a/Blade/Strings.cs b/Blade/Strings.cs deleted file mode 100644 index 2d4a64a..0000000 --- a/Blade/Strings.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Text.RegularExpressions; - -namespace Connect.Razor -{ - public static partial class Temporary - { - - - #region Replace helpers - public static string Replace(this string input, string search, string replacement, bool caseSensitive) - { - input = input ?? ""; - search = search ?? ""; - replacement = replacement ?? ""; - - if (caseSensitive) - return input.Replace(search, replacement); - - string result = Regex.Replace( - input, - Regex.Escape(search ), - (replacement).Replace("$", "$$"), - RegexOptions.IgnoreCase - ); - return result; - } - #endregion - } -} diff --git a/Connect.Razor.Dnn/Connect.Razor.Dnn.csproj b/Connect.Razor.Dnn/Connect.Razor.Dnn.csproj index 35927ea..4681623 100644 --- a/Connect.Razor.Dnn/Connect.Razor.Dnn.csproj +++ b/Connect.Razor.Dnn/Connect.Razor.Dnn.csproj @@ -43,30 +43,7 @@ 4 - - - ..\packages\Newtonsoft.Json.4.5.6\lib\net40\Newtonsoft.Json.dll - False - False - - - - - - - - - Assemblies\System.Web.Helpers.dll - False - - - - - - - - diff --git a/README.md b/README.md index e1f9749..918390a 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,15 @@ A library of common functions for Razor, to lighten Razor templates and make work easier. -The goal is to provide helpers for very common code snippets or functions, which would lighten the load. Here's an example: +The goal is to provide helpers for very common code snippets or functions, which would lighten the load. Here some common examples... -Instead of writing this: +_Sometimes you need the first 100 characters followed by an ellipsis (if truncated), but umlauts like `ü` will mess up your count or might even be cut off. This is automatically handled by:_ + +```razor + @Text.Crop(someText, 100) +``` + +_Or sometimes you need a value, but if it's empty, you need another one. So instead of writing:_ ```razor @if(String.IsNullOrWhiteSpace(firstName as string)) { @@ -17,19 +23,15 @@ Instead of writing this: } ``` -You can write this: +_You can write this, or below it the example with even more values:_ ```razor - @Text.First(firstName, "nothing found"); -``` - -Or here an example with more values: + @Text.First(firstName, "John"); -```razor @Text.First(nameFromDb, nameFromProfile, defaultNameForThisCountry, "unknown") ``` -Note that HTML whitespace like ` ` will also be treated as empty, unless you add `false` as a last parameter. But RazorBlade does more than just skip empty texts, here some more examples: +_Note that HTML whitespace like ` ` will also be treated as empty, unless you add `false` as a last parameter. But RazorBlade does more than just skip empty texts, here some more examples:_ ```razor @* remove html from a wysiwyg-string *@ @@ -48,6 +50,8 @@ Note that HTML whitespace like ` ` will also be treated as empty, unless yo ## Using Razor Blade +First, install the DNN-module from the [releases on Github](https://github.com/DNN-Connect/razor-blade/releases). + In your c# code, add the following line to then have access to all the commands: ```razor @@ -94,8 +98,11 @@ This is a short summary of the most used variations of the helpers. Further deta ## Commands in v0.1 to Convert Html to Text or Back 1. `Tags.Remove(htmlText)` - strips the html from an string, ensuring that all tags will cause 1 spaces between words, but only one (multiple spaces are shortened to 1 again) + 1. `Tags.Br2Nl(text)` - replaces all kinds of `
` tags with new-line `\n` + 1. `Tags.Br2Space(text)` - replaces all kinds of `
` with spaces + 1. `Tags.Nl2Br(text)` - replaces all kinds of new-line (`\n`, `\r`) with `
` ## Ideas to discuss @@ -103,10 +110,7 @@ This is a short summary of the most used variations of the helpers. Further deta 1. `Tags.Remove(htmlText, csvListOfTagsToRemove)` 1. `Tags.Replace(htmlText, listOfTags, replacementTag)` 1. (place other wishes into issues for discussion) - -### WIP - -1. `ToDynamic(dictionary)` - converts a Dictionary to an expando object, so you can write obj.Property instead of obj["Property"] +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. ## Namespace Conventions diff --git a/Razor Blades.sln b/Razor Blade.sln similarity index 100% rename from Razor Blades.sln rename to Razor Blade.sln