This project is read-only.

Using the Spark View Engine

Dec 9, 2009 at 9:25 PM

I'd like to use the C# WebServer project together with the Spark View Engine.

Looking through the documentation and code here and over on the Spark site, I can see it'll take some work.

If you're interested in helping out, post a message.

Dec 14, 2009 at 8:52 PM

A few folks on the Spark View Engine project were interested in this, so I created a Google Code project with my integration glue classes.

I've done an initial upload of my code so far.

There's really only a handful of interesting files, all of them in the root of the project. I think my SparkDataDictionary and SparkView classes may be overkill. (I just borrowed the code from Spark.Web.Mvc.)

Dec 15, 2009 at 7:20 AM

I'm interested too. I've looked at the spark engine and it looks really nice.

I got way to much at work right now, that's why I'm so quiet in this forum.

I'm still using this HTTP server though, so the project wont die. But nothing more than bugfixes will happen the next 6 months, at least not from me.

Dec 17, 2009 at 10:23 PM

The Spark Engine is a great template engine. It lets the Html really shine through. I'm glad I decided to use it. 

It was easier to wire up the changes than I thought. I'm still not sure that I've got some of the supporting Spark classes fully working yet, but it does what I need.

I'd be more than happy to donate the code back to the C# WebServer project when we're through. But I thought it might be useful to get some input from the Spark community as well.


Dec 18, 2009 at 10:38 AM
Any opinions on the pros and cons of using Spark vs. haml? I think I
spied that webserver has haml out of the box, and while Spark does
look the first ever reasonable HTML-based view/templating system, haml
looks incredibly succinct.

Has anyone used both? Anyone not use both, but have an opinion anyway? :-)

Dec 18, 2009 at 2:57 PM

I haven't worked with Haml, but its "code haiku" approach didn't appeal to me. Saving a few extra keystrokes seems a poor trade for increased obfuscation. Since I'm an Html expert, the best thing a template engine can do for me is to show me the Html.

Spark does exactly that, but it adds a few capabilities missing from the other built-in template method in the C# WebServer project, Tiny template.

My current task is to convert a bunch of Xslt templates into Spark templates. Since both Xslt and Spark render out the Html untouched it was a much easier conversion process than using Haml or Tiny. (I know, I know, why were we using something crazy like Xslt in the first place? Lesson learned.)


Jan 5, 2010 at 1:07 PM

I've successfully rendered a view with spark today. Now I just gotto figure out how to control the layouts that views get rendered into. I want to complete this before I do the first 2.0 check in.

Program.cs in the spark sample project:



	 // Log everything to console.
	LogFactory.Assign(new ConsoleLogFactory(null));

	Assembly thisAssembly = typeof (Program).Assembly;

	// create a MVC web server.
	MvcServer server = new MvcServer();

	// add spark view engine.
	server.ViewEngines.Add(new SparkEngine());

	// map embedded resources.
	EmbeddedResources embedded = new EmbeddedResources("/user/", thisAssembly, "Spark.User.Views");
	embedded.Add("/shared/", thisAssembly, "Spark.Shared");

	// Load all controllers found in this assembly.

	// We need a HTTP listener too :)
	server.Add(HttpListener.Create(IPAddress.Any, 8080));

	// redirect root to user.
	server.Add(new SimpleRouter("/", "/user/"));

	// And run the server.

	// run until you press enter.



    public class UserController : Controller
        /// <summary>
        /// Default controller method.
        /// </summary>
        /// <returns></returns>
        public IViewData Index()
            ViewData["whom"] = "World";
            return Render();

        /// <summary>
        /// Creates a new controller that is a clone of the current one.
        /// </summary>
        /// <returns>A new controller.</returns>
        public override object Clone()
            return this;

And the small view:


<p>Hello ${whom}</p>

I do a small tweak compared to spark running in Asp.Net MVC. All views are strongly typed. I import all view data variables and there is no need to use the <viewdata ... /> tag in the spark templates.




Jan 27, 2010 at 7:39 AM

Yay, got master layouts working today.

Just minor pieces left with spark.

Jan 27, 2010 at 3:00 PM

Awesome! I'm looking forward to playing with the new version.