LogicNP are Dodgy
Spread the word: If you buy controls from LogicNP and use them to make cool things then they will rip off your idea.
Case in point. Mindscape created the awesome, free .
Lo and behold, what appears on the LogicNP site sometime later: The not free, and much less awesome ““!
Boycott LogicNP!
As usual, the opinions expressed are mine and not that of my employer or of Mindscape.
Getting Started with NHaml
has put up a great on how to get started with NHaml.
Thanks Brian!
In-process ASP.NET MVC Web Form View Rendering
Sometimes it’s useful to be able to render a view in-process, for example, from within a unit test if you would like to validate the rendered XHTML. View engines like make this easy because they aren’t tightly coupled to the System.Web.* ASP.NET runtime. Web Forms, however, is another story. You cannot simply new up a WebFormViewEngine, nestle it in some moqs and start rendering away merrily. You will quickly run into various exceptions because the ASP.NET runtime has not been properly initialized.
All is not lost however. Here’s how you can easily render Web Forms views using the ASP.NET Hosting API:
First, create an Application Host class. Inherit MarshalByRefObject because this will run ASP.NET in a separate App Domain. Add a method, ProcessRequest, that will request a view through the runtime.
public sealed class TestApplicationHost : MarshalByRefObject { public void ProcessRequest(string page, string query, TextWriter output) { var simpleWorkerRequest = new SimpleWorkerRequest(page, query, output); HttpRuntime.ProcessRequest(simpleWorkerRequest); } }
Second, create your host which points to an ASP.NET app and render a view.
public sealed class Program { private static void Main() { var applicationHost = (TestApplicationHost) ApplicationHost.CreateApplicationHost( typeof(TestApplicationHost), "/", @"C:\Dev\MyMvcApplication"); using (var output = new StringWriter()) { applicationHost.ProcessRequest("Account/Login", null, output); Console.WriteLine(output); } Console.ReadKey(); } }
Surprisingly easy actually.
By Popular Demand
The version of NHaml now lets you use tabs or a variable indent size for indentation.
Now, no more arguing! You may go about your business.
P.S. 2 spaces is the best
NHaml 2.0 Beta
rightly pointed out that requiring NHaml users to pull the source from SVN was just downright lazy. So I finally got around to putting together an actual release: .
With 2.0 we’ve made some substantial changes and improvements and also greatly simplified the API. Here’s a sneak peak of what’s coming:
- The biggest change by far has been the introduction of pluggable back-end compilers. NHaml templates can now be authored in one of four languages: C# 2, C# 3, Boo and IronRuby.
- We have greatly simplified our ASP.NET MVC View Engine which now inherits from the framework provided VirtualPathProviderViewEngine.
- NHaml 2.0 implements the for convenient handling of HTML encoding.
- We made some major API usability improvements for stand-alone template rendering.
We still have a bunch of stuff on our backlog, some of which we’ll try and squeeze into 2.0 RTM - Hopefully sometime within the next month.
Enjoy and death to angle brackets!