A library of helpers for Razor, to lighten Razor templates and make work easier.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Blade
Razor Blades Tests
assets
.gitattributes
.gitignore
LICENSE
README.md
Razor Blades.sln
concept.md

README.md

Razor Blade

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:

Write this:

  @Fallback(firstName, "nothing found");

Instead of this:

  @if(String.IsNullOrWhiteSpace(firstName as string)) {
    @"nothing found"
  } else {
    @firstName
  }

Here are the commands so far:

  1. HasText(someObjectOrString) - true if it has real text, basically a reversed shorthand for IsNullOrWhiteSpace with type-check for non-strings
  2. ShowText(intendedValue, fallbackIfEmpty)
  3. ShowText(intendedValue, next-value, next-value, ..., fallbackIfEmpty)
  4. Ellipsis(valToShow, maxLength) - will show value, and if it's longer than max-length, will go add an "..."-character instead
  5. Ellipsis(valToShow, maxLength, customEllipsis) - same as the simple one, but you can specify what should be added
  6. StripHtml(html) - strips the html from an string
  7. ToDynamic(dictionary) - converts a Dictionary to an expando object, so you can write obj.Property instead of obj["Property"]

WIP

  1. @If(condition, value) - nicer shorthand for @(condition ? value : "")
  2. @If(condition, value, otherwise) - nicer shorthand for @(condition ? value : otherwise)
  3. `@Switch...