I should have gone to bed early last night (after all, I did wake up at 4:30AM yesterday morning). Unfortunately, a spark of inspiration quite literally kept me up later than normal sleep cycles dictate… but what a spark it was.
To understand the spark, you have to understand my history of server-side web programming.
In the beginning
My first experience with server-side web programming was with Allaire ColdFusion some ten years ago. What was great about ColdFusion is its use of a tag-based scripting language, CFML, as illustrated below.
<cfset value = "Hello" /> <cfoutput> #value# Bob! </cfoutput>
After ColdFusion, I came across what is now known as “Classic ASP” – and my web code looked less and less like HTML.
<% value = "Hello" %> <%= value %> Bob!
Classic ASP felt more like programming, less like web programming. Quite accurately, it was web programming via scripting. I missed the tag-based syntax of ColdFusion.
Then there was ASP.Net, which at first glance looked like it was a return to tag-based web programming! Well, almost… along came this weird codebehind model, and the entire stateless request/response nature of the web was bastardized.
<asp:label runat="server" id="greeting" /> Bob! // and in the codebehind greeting.Text = "Hello";
And so there I was until I found Castle Monorail, which returned web programming to its core, thanks to a fantastic MVC architecture. With MonoRail, you injected text into your web pages using a template engine. For me (and most other newcomers to MonoRail), that meant NVelocity.
${value} Bob! // and in the controller PropertyBag["value"] = "Hello";
Now assignments happened somewhere detached from the view (i.e. the controller), and my web page was looking rather clean. I still yearned for the tag-style days of ColdFusion.
Enter Spark, a tag-based view engine for MVC platforms (i.e. MonoRail!). Spark gives you almost all the power of C# and the .Net Framework within your view, but does it using a syntax that is entirely tag-based, as shown in the following example from the Spark web site.
<var names="new [] {'alpha', 'beta', 'gamma'}"/> <for each="var name in names"> <test if="name == 'beta'"> <p>beta is my favorite.</p> <else/> <p>${name} is okay too I suppose. </test> </for>
With this, the presentation logic in your view looks like HTML. It makes the resulting view file much more semantic otherwise.
The Spark view engine is an impressive effort by Louis DeJardin, who deserves kudos for his efforts. Not only does the code work great, he’s got plenty of documentation on how to get it working with Castle MonoRail – even plenty of references to Windsor integration.
I’m switching a major project from NVelocity to Spark, and plan to blog more about this in the future. In the meantime, check out Spark – there’s lots to read and learn, and the examples available in the Subversion repository are fantastic.
josh says:
please do blog about migrating from nvelocity to sparks. I’m running nv right now, and will be checking out sparks.
brian says:
This is something I definitely plan to do. Expect frequent posts (nightly?) as I discover more and more things about the Spark view engine. For example, tonight I should be posting about how to incorporate strongly-typed Flash and PropertyBag elements (something I figured out last night).
harborpirate says:
Very interesting! I’ll be curious to see where this leads.
brian says:
Post #2 about Spark is up. I’ll try to keep the snippets coming.