Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created February 15, 2011 09:25
Show Gist options
  • Save thecodejunkie/827307 to your computer and use it in GitHub Desktop.
Save thecodejunkie/827307 to your computer and use it in GitHub Desktop.
Experimenting with new Nancy view engine signature
public Action<Stream> RenderView<TModel>(ViewLocationResult viewLocationResult, TModel model)
{
return stream =>
{
var templateManagerProvider =
new TemplateManagerProvider()
.WithLoader(new TemplateLoader(viewLocationResult.Contents));
var templateManager =
templateManagerProvider.GetNewManager();
var template =
templateManager.GetTemplate(string.Empty);
var context = new Dictionary<string, object> { { "Model", model } };
var reader = template.Walk(templateManager, context);
using (var writer = new StreamWriter(stream))
{
writer.Write(reader.ReadToEnd());
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment