Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Last active December 15, 2015 22:39
Show Gist options
  • Save thecodejunkie/5334869 to your computer and use it in GitHub Desktop.
Save thecodejunkie/5334869 to your computer and use it in GitHub Desktop.
public interface ISuperSimpleViewEngineExtension
{
string Invoke(string content, dynamic model, IViewEngineHost host);
}
public class GistSuperSimpleViewEngineExtension : ISuperSimpleViewEngineExtension
{
private readonly Regex regex = new Regex(@"(?:@gist\[(?<id>[a-z01-9]*)\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private const string GistTemplate = "<script src='https://gist.github.com/{0}.js'></script>";
public string Invoke(string content, dynamic model, IViewEngineHost host)
{
return regex.Replace(content, match => (match.Groups["id"].Success) ? string.Format(GistTemplate, match.Groups["id"].Value) : string.Empty);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment